def test_standard_ko(self): # . B . . # B X B . # W B W . # . W . . gs = GameState(size=9) gs.do_move((1, 0)) # B gs.do_move((2, 0)) # W gs.do_move((2, 1)) # B gs.do_move((3, 1)) # W gs.do_move((1, 2)) # B gs.do_move((2, 2)) # W gs.do_move((0, 1)) # B gs.do_move((1, 1)) # W trigger capture and ko self.assertEqual(gs.num_black_prisoners, 1) self.assertEqual(gs.num_white_prisoners, 0) self.assertFalse(gs.is_legal((2, 1))) gs.do_move((5, 5)) gs.do_move((5, 6)) self.assertTrue(gs.is_legal((2, 1)))
def test_snapback_is_not_ko(self): gs = GameState(size=5) # B X W B . # W W B . . # . . . . . # . . . . . # . . . . . # imagine black plays at 'X' capturing the white stone at (2, 0). # White may play again at (2, 0) to capture the black stones # at (0, 0), (1, 0). this is a 'snapback' not 'ko' # since it doesn't return the game to a previous position B = [(0, 0), (2, 1), (3, 0)] W = [(0, 1), (1, 1), (2, 0)] for (b, w) in zip(B, W): gs.do_move(b) gs.do_move(w) # do the capture of the single white stone gs.do_move((1, 0)) # there should be no ko self.assertIsNone(gs.ko) self.assertTrue(gs.is_legal((2, 0))) # now play the snapback gs.do_move((2, 0)) # check that the numbers worked out self.assertEqual(gs.num_black_prisoners, 2) self.assertEqual(gs.num_white_prisoners, 1)