#include #include #include #include #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 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 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(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; } } }