EscapeSuggester implements Suggester { @Override public ShortSet getMoves() { movesToEscape.clear(); final StoneColor colorToPlay = board.getColorToPlay(); final ShortSet chainsInAtari = atariObserver.getChainsInAtari(colorToPlay); for (int i = 0; i < chainsInAtari.size(); i++) { final short chain = chainsInAtari.get(i); final short p = board.getLiberties(chain).get(0); if (board.getNeighborsOfColor(p, VACANT) >= 2) { movesToEscape.add(p); } else if (board.getNeighborsOfColor(p, colorToPlay) > 0) { escapeByMerging(p); } escapeByCapturing(chain); } return movesToEscape; } EscapeSuggester(Board board, AtariObserver atariObserver);  EscapeSuggester(Board board, AtariObserver atariObserver, int bias); @Override int getBias(); @Override ShortSet getMoves();  }
@Test public void testEscape(){ String[] diagram = { "O#...", "....#", "...#O", ".....", ".....", }; board.setUpProblem(diagram, WHITE); assertTrue(movesToEscape.getMoves().contains(at("e2"))); assertTrue(movesToEscape.getMoves().contains(at("a4"))); }
@Test public void testCaptureEscape(){ String[] diagram = { "O#...", "...O#", "...#O", ".....", ".....", }; board.setUpProblem(diagram, WHITE); assertTrue(movesToEscape.getMoves().contains(at("e2"))); assertTrue(movesToEscape.getMoves().contains(at("a4"))); assertTrue(movesToEscape.getMoves().contains(at("e5"))); assertEquals(3, movesToEscape.getMoves().size()); }
@Test public void testConnectEscape(){ String[] diagram = { "O###.", "...O#", "...#O", "...#.", "..O.O", }; board.setUpProblem(diagram, WHITE); assertFalse(movesToEscape.getMoves().contains(at("e2"))); board.play("d1"); assertTrue(movesToEscape.getMoves().contains(at("e5"))); board.play("a3"); assertTrue(movesToEscape.getMoves().contains(at("e2"))); }
@Test public void testMultipleMerge() { String[] diagram = { "OO.OO", ".#O#.", ".#O#.", "..#..", ".....", }; board.setUpProblem(diagram, WHITE); assertTrue(movesToEscape.getMoves().contains(at("c5"))); assertEquals(1, movesToEscape.getMoves().size()); }