diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2019-02-13 21:08:37 +0100 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2019-02-13 21:08:37 +0100 |
commit | 6175cb1c53772cc92d91a39a254c38bdf8f64905 (patch) | |
tree | 3a7dd5f8810d0c859faaf5ab985afc51841899a8 /main.cpp |
Initial: working monte carlo AI
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..80d0fb8 --- /dev/null +++ b/main.cpp @@ -0,0 +1,39 @@ +#include <iostream> +#include <cstdlib> +#include <sys/time.h> +#include "board.h" +#include "mc.h" +#include "util.h" + +using namespace std; + + +int main() { + struct timeval tv; + gettimeofday(&tv, nullptr); + srandom(tv.tv_sec * 1000000U + tv.tv_usec); + + Board bd = Board::makeEmpty(); + cerr << "Initial stone at " << Idx(BSZ * BMID + BMID) << endl; + bd.put(BSZ * BMID + BMID, 1); + + cout << bd << endl; + + uint8_t onturn = 2; + while (bd.bag.totalLeft() > 0) { + cout << "--- NEXT TURN: " << Stone(onturn) << " ---" << endl; + + int idx = MC::calcMove(bd, onturn); + uint8_t clr = bd.bag.drawRandom(); + uint8_t win = bd.putCW(idx, clr); + + cout << bd << endl; + + if (win != 0) { + cout << "Winner: " << Stone(clr) << endl; + break; + } + + onturn = NEXTTURN(onturn); + } +} |