summaryrefslogtreecommitdiff
path: root/ai_rand.cpp
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2018-06-30 00:30:14 +0200
committerTom Smeding <tom.smeding@gmail.com>2018-06-30 00:30:14 +0200
commit44421af15c2f361764b8741bb93f9fddda3f8a8b (patch)
tree15e541b25d145595279de6067cb839ebbb16b982 /ai_rand.cpp
Initial
Diffstat (limited to 'ai_rand.cpp')
-rw-r--r--ai_rand.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/ai_rand.cpp b/ai_rand.cpp
new file mode 100644
index 0000000..9bd3eed
--- /dev/null
+++ b/ai_rand.cpp
@@ -0,0 +1,14 @@
+#include "ai_rand.h"
+
+
+Move AI::Rand::findMove(const Board &bd, int player) {
+ Move poss[N * N * N];
+ int nposs = 0;
+
+ bd.forEachMove(player, [&bd, &poss, &nposs](Move mv) {
+ poss[nposs++] = mv;
+ });
+
+ if (nposs == 0) return Move(-1, -1);
+ return poss[rand() % nposs];
+}