summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp85
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;
+ }
+ }
+}