diff options
author | tomsmeding <tom.smeding@gmail.com> | 2018-03-12 00:20:50 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2018-03-12 00:20:50 +0100 |
commit | b26b8840e2cebec9ea8294d24ceb6663942005d4 (patch) | |
tree | 295d74c04bc9b6496e5a06a76234d87e876b3fe9 /main.cpp |
Initial
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..1419b08 --- /dev/null +++ b/main.cpp @@ -0,0 +1,85 @@ +#include <iostream> +#include <string> +#include <stdexcept> +#include <time.h> +#include "board.h" +#include "minimax.h" + + +const int AB_MAXDEPTH = 6; + +int main() { + Board B; + cout << B << endl; + + // clock_t start = clock(); + // for (int i = 0; i < 1000000; i++) { + // B.subsequents(); + // } + // clock_t diff = clock() - start; + // cout << (double)diff / CLOCKS_PER_SEC << endl; + + // for (const Board &B2 : B.subsequents()) { + // cout << B2 << endl; + // } + + while (true) { + string line; + getline(cin, line); + if (!cin) break; + if (line == "s") { + cout << "----------------------" << endl; + for (const Board &B2 : B.subsequents()) { + cout << B2 << endl; + } + cout << "----------------------" << endl << B << endl; + continue; + } + if (line == "q") break; + if (line == "r") { + vector<Board> subs = B.subsequents(); + if (subs.size() == 0) { + cout << "No possible moves" << endl; + } else { + B = subs[rand() % subs.size()]; + cout << B << endl; + } + continue; + } + if (line == "a") { + vector<Board> subs = B.subsequents(); + if (subs.size() == 0) { + cout << "No possible moves" << endl; + } else { + int maxval = INT_MIN, maxat = -1; + const int multfactor = B.onTurn == WHITE ? 1 : -1; + cout << "["; + for (size_t i = 0; i < subs.size(); i++) { + int v = alphabeta<evaluate_pieceScore>(subs[i], AB_MAXDEPTH); + if (i != 0) cout << ", "; + cout << v << endl; + v *= multfactor; + if (v > maxval) { + maxval = v; + maxat = i; + } + } + cout << "]" << endl; + B = subs[maxat]; + cout << B << endl; + } + continue; + } + try { + Move mv(line.data()); + if (B.isValid(mv)) { + B.apply(mv); + cout << B << endl; + } else { + cout << "Invalid move." << endl; + } + } catch (const runtime_error &e) { + cout << "Unrecognised input, expected move." << endl; + } + } +} |