diff options
Diffstat (limited to 'ai_rand.cpp')
-rw-r--r-- | ai_rand.cpp | 14 |
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]; +} |