StoneCountObserver implements BoardObserver { public StoneColor mercyWinner() { final int difference = counts[BLACK.index()] - counts[WHITE.index()]; if (difference >= blackMercyThreshold) { return BLACK; } else if (difference <= whiteMercyThreshold) { return WHITE; } return null; } StoneCountObserver(Board board, Scorer scorer); @Override void clear(); @Override void copyDataFrom(BoardObserver that); int getCount(StoneColor color); StoneColor mercyWinner(); @Override void update(StoneColor color, short location,
			ShortList capturedStones);  }
@Test public void testMercy(){ assertNull(counter.mercyWinner()); String[] diagram = { "#####", "#####", "#####", "#####", "#.#..", }; board.setUpProblem(diagram, BLACK); assertNull(counter.mercyWinner()); board.play(board.getCoordinateSystem().at("e1")); assertEquals(BLACK, counter.mercyWinner()); diagram = new String[] { "###..", ".....", ".....", "OOOOO", "OOOOO", }; board.setUpProblem(diagram, WHITE); assertNull(counter.mercyWinner()); board.play(board.getCoordinateSystem().at("a3")); assertEquals(WHITE, counter.mercyWinner()); }
@Test public void testMercyOnLargerBoard(){ board = new Board(19); counter = new StoneCountObserver(board, new ChineseFinalScorer(board, 7.5)); assertNull(counter.mercyWinner()); String[] diagram = { "###################", "###################", "###################", "##########.........", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", }; board.setUpProblem(diagram, BLACK); assertNull(counter.mercyWinner()); board.play(board.getCoordinateSystem().at("a1")); assertEquals(BLACK, counter.mercyWinner()); diagram = new String[] { "#..................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "...................", "OOOOOOOOOOOOOOO....", "OOOOOOOOOOOOOOOOOOO", "OOOOOOOOOOOOOOOOOOO", }; board.setUpProblem(diagram, WHITE); assertNull(counter.mercyWinner()); board.play(board.getCoordinateSystem().at("e5")); assertEquals(WHITE, counter.mercyWinner()); }