summaryrefslogtreecommitdiff
path: root/ai_rand.cpp
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-02-16 20:30:21 +0100
committertomsmeding <tom.smeding@gmail.com>2019-02-16 20:30:21 +0100
commit1a996c6e016b28e09895aa17201720b63d70bd71 (patch)
treed5dd88fd79dc108b81618af4d00bbfcb6f43f67a /ai_rand.cpp
parent39b942ad50b1ebe942afd350d8038929a26d7ac6 (diff)
Optimise board edge handling
This new organisation assumes that you'll do very few modifications before calling forEachMoves again.
Diffstat (limited to 'ai_rand.cpp')
-rw-r--r--ai_rand.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/ai_rand.cpp b/ai_rand.cpp
index 7479d01..c4df24e 100644
--- a/ai_rand.cpp
+++ b/ai_rand.cpp
@@ -11,9 +11,8 @@ int RAND::calcMove(Board &bd, uint8_t myclr) {
(void)myclr;
assert(bd.bag.totalLeft() > 0);
- int moves[BSZ * BSZ], nmoves = 0;
- bd.forEachMove([&moves, &nmoves](int idx) { moves[nmoves++] = idx; });
+ const vector<int> &moves = bd.getEdgeCells();
- assert(nmoves > 0);
- return moves[random() % nmoves];
+ assert(moves.size() > 0);
+ return moves[random() % moves.size()];
}