def test_ko_move(self): start_board = utils_test.load_board(''' .OX...... OX....... ''' + EMPTY_ROW * 7) start_position = Position( utils_test.BOARD_SIZE, board=start_board, n=0, komi=6.5, caps=(1, 2), ko=None, recent=tuple(), to_play=BLACK, ) expected_board = utils_test.load_board(''' X.X...... OX....... ''' + EMPTY_ROW * 7) expected_position = Position( utils_test.BOARD_SIZE, board=expected_board, n=1, komi=6.5, caps=(2, 2), ko=coords.from_kgs(utils_test.BOARD_SIZE, 'B9'), recent=(PlayerMove(BLACK, coords.from_kgs(utils_test.BOARD_SIZE, 'A9')), ), to_play=WHITE, ) actual_position = start_position.play_move( coords.from_kgs(utils_test.BOARD_SIZE, 'A9')) self.assertEqualPositions(actual_position, expected_position) # Check that retaking ko is illegal until two intervening moves with self.assertRaises(go.IllegalMove): actual_position.play_move( coords.from_kgs(utils_test.BOARD_SIZE, 'B9')) pass_twice = actual_position.pass_move().pass_move() ko_delayed_retake = pass_twice.play_move( coords.from_kgs(utils_test.BOARD_SIZE, 'B9')) expected_position = Position( utils_test.BOARD_SIZE, board=start_board, n=4, komi=6.5, caps=(2, 3), ko=coords.from_kgs(utils_test.BOARD_SIZE, 'A9'), recent=( PlayerMove(BLACK, coords.from_kgs(utils_test.BOARD_SIZE, 'A9')), PlayerMove(WHITE, None), PlayerMove(BLACK, None), PlayerMove(WHITE, coords.from_kgs(utils_test.BOARD_SIZE, 'B9')), ), to_play=BLACK) self.assertEqualPositions(ko_delayed_retake, expected_position)
def test_move(self): start_position = Position( utils_test.BOARD_SIZE, board=TEST_BOARD, n=0, komi=6.5, caps=(1, 2), ko=None, recent=tuple(), to_play=BLACK, ) expected_board = utils_test.load_board(''' .XX....OO X........ ''' + EMPTY_ROW * 7) expected_position = Position( utils_test.BOARD_SIZE, board=expected_board, n=1, komi=6.5, caps=(1, 2), ko=None, recent=(PlayerMove(BLACK, coords.from_kgs(utils_test.BOARD_SIZE, 'C9')), ), to_play=WHITE, ) actual_position = start_position.play_move( coords.from_kgs(utils_test.BOARD_SIZE, 'C9')) self.assertEqualPositions(actual_position, expected_position) expected_board2 = utils_test.load_board(''' .XX....OO X.......O ''' + EMPTY_ROW * 7) expected_position2 = Position( utils_test.BOARD_SIZE, board=expected_board2, n=2, komi=6.5, caps=(1, 2), ko=None, recent=( PlayerMove(BLACK, coords.from_kgs(utils_test.BOARD_SIZE, 'C9')), PlayerMove(WHITE, coords.from_kgs(utils_test.BOARD_SIZE, 'J8')), ), to_play=BLACK, ) actual_position2 = actual_position.play_move( coords.from_kgs(utils_test.BOARD_SIZE, 'J8')) self.assertEqualPositions(actual_position2, expected_position2)
def test_ko_move_mutable_board(self): start_board = load_board(''' .OX...... OX....... ''' + EMPTY_ROW * 7) start_position = Position( board=start_board, n=0, komi=6.5, caps=(1, 2), ko=None, recent=tuple(), to_play=BLACK, ) expected_board = load_board(''' X.X...... OX....... ''' + EMPTY_ROW * 7) expected_position = Position( board=expected_board, n=1, komi=6.5, caps=(2, 2), ko=pc('B9'), recent=(PlayerMove(BLACK, pc('A9')), ), to_play=WHITE, ) actual_position = start_position.play_move(pc('A9'), mutate=True) self.assertEqualPositions(actual_position, expected_position) # Check that retaking ko is illegal until two intervening moves with self.assertRaises(go.IllegalMove): actual_position.play_move(pc('B9'), mutate=True) pass_twice = actual_position.pass_move(mutate=True).pass_move( mutate=True) ko_delayed_retake = pass_twice.play_move(pc('B9'), mutate=True) expected_position = Position( board=start_board, n=4, komi=6.5, caps=(2, 3), ko=pc('A9'), recent=(PlayerMove(BLACK, pc('A9')), PlayerMove(WHITE, None), PlayerMove(BLACK, None), PlayerMove(WHITE, pc('B9'))), to_play=BLACK, ) self.assertEqualPositions(ko_delayed_retake, expected_position)
def test_move_with_capture(self): start_board = load_board(EMPTY_ROW * 5 + ''' XXXX..... XOOX..... O.OX..... OOXX..... ''') start_position = Position( board=start_board, n=0, komi=6.5, caps=(1, 2), ko=None, recent=tuple(), to_play=BLACK, ) expected_board = load_board(EMPTY_ROW * 5 + ''' XXXX..... X..X..... .X.X..... ..XX..... ''') expected_position = Position( board=expected_board, n=1, komi=6.5, caps=(7, 2), ko=None, recent=(PlayerMove(BLACK, pc('B2')), ), to_play=WHITE, ) actual_position = start_position.play_move(pc('B2')) self.assertEqualPositions(actual_position, expected_position)
def test_passing(self): start_position = Position( board=TEST_BOARD, n=0, komi=6.5, caps=(1, 2), ko=pc('A1'), recent=tuple(), to_play=BLACK, ) expected_position = Position( board=TEST_BOARD, n=1, komi=6.5, caps=(1, 2), ko=None, recent=(PlayerMove(BLACK, None), ), to_play=WHITE, ) pass_position = start_position.pass_move() self.assertEqualPositions(pass_position, expected_position)