PredicateMover implements Mover { @Override public short selectAndPlayOneMove(MersenneTwisterFast random, boolean fast) { candidates.clear(); candidates.addAll(board.getVacantPoints()); while (candidates.size() > 0) { final short p = candidates.removeRandom(random); if (board.getColorAt(p) == VACANT && filter.at(p)) { Legality legality = fast ? board.playFast(p) : board.play(p); if (legality == OK) { return p; } } } board.pass(); return PASS; } PredicateMover(Board board, Predicate filter); @Override short selectAndPlayOneMove(MersenneTwisterFast random, boolean fast);  }
@Test public void testSelectAndPlayOneMove() { String[] diagram = { ".###.", "#####", "#O.O#", "OOOOO", "O...O", }; int[] counts = new int[coords.getFirstPointBeyondBoard()]; MersenneTwisterFast random = new MersenneTwisterFast(); int trials = 1000; for (int i = 0; i < trials; i++) { board.setUpProblem(diagram, BLACK); counts[mover.selectAndPlayOneMove(random, true)]++; } assertEquals(trials/4.0, counts[at("b1")], trials/20.0); assertEquals(trials/4.0, counts[at("c1")], trials/20.0); assertEquals(trials/4.0, counts[at("c3")], trials/20.0); assertEquals(trials/4.0, counts[at("d1")], trials/20.0); }