SuggesterMover implements Mover { @Override public short selectAndPlayOneMove(MersenneTwisterFast random, boolean fast) { candidates.clear(); candidates.addAll(suggester.getMoves()); while (candidates.size() > 0) { final short p = candidates.removeRandom(random); assert board.getColorAt(p) == VACANT; Legality legality = fast ? board.playFast(p) : board.play(p); if (legality == OK) { return p; } } return fallbackMover.selectAndPlayOneMove(random, fast); } SuggesterMover(Board board, Suggester suggester, Mover fallbackMover); @Override short selectAndPlayOneMove(MersenneTwisterFast random, boolean fast);  }
@Test public void testSuggestions() { String[] diagram = { ".##..", "#OO#O", "..#OO", ".#O##", ".....", }; MersenneTwisterFast random = new MersenneTwisterFast(); int[] counts = new int[coords.getFirstPointBeyondBoard()]; for(int i = 0; i < 1000; i++){ board.setUpProblem(diagram, BLACK); short p = mover.selectAndPlayOneMove(random, true); counts[p]++; } assertTrue(counts[at("b3")] > 250); assertTrue(counts[at("c1")] > 250); assertTrue(counts[at("e5")] > 250); }
@Test public void testFallback() { String[] diagram = { ".#...", "#....", ".....", ".....", ".....", }; MersenneTwisterFast random = new MersenneTwisterFast(); int[] counts = new int[coords.getFirstPointBeyondBoard()]; for(int i = 0; i < 1000; i++){ board.setUpProblem(diagram, BLACK); short p = mover.selectAndPlayOneMove(random, true); counts[p]++; } final ShortSet invalidPoints = new ShortSet(coords.getFirstPointBeyondBoard()); for (String s : new String[] {"a4", "a5", "b5", "c1", "d1", "d2", "e1", "e2", "e3"}) { invalidPoints.add(at(s)); } for(short p : coords.getAllPointsOnBoard()){ if(!invalidPoints.contains(p)){ assertTrue(counts[p] > 20); } } assertEquals(0, counts[at("a5")]); assertEquals(0, counts[at("a4")]); assertEquals(0, counts[at("b5")]); }