def test_multi_capture_possible_with_original_piece_only(self): test_board = CheckerBoardFactory.build_board_from_preset( BoardPresetDataclass(8, 8, [(2, 2), (6, 4)], [(3, 3), (5, 5)])) test_game = CheckersGame(test_board) test_game.make_move(CheckersMove([2, 2, 4, 4])) self.assertEqual(test_game.current_team, TeamEnum.white) self.assertRaises(IllegalMoveException, test_game.make_move, CheckersMove([6, 4, 4, 6])) test_board2 = CheckerBoardFactory.build_board_from_preset( BoardPresetDataclass(8, 8, [(2, 2), (6, 4)], [(3, 3), (5, 5)])) test_game2 = CheckersGame(test_board2) test_game2.make_move(CheckersMove([2, 2, 4, 4])) self.assertEqual(test_game2.current_team, TeamEnum.white) test_game2.make_move(CheckersMove([4, 4, 6, 6]))
def test_multi_capture_not_activated_on_regular_move(self): test_board = CheckerBoardFactory.build_board_from_preset( BoardPresetDataclass(8, 8, [(1, 1)], [(3, 3), (5, 5)])) test_game = CheckersGame(test_board) test_game.make_move(CheckersMove([1, 1, 2, 2])) self.assertEqual(test_game.current_team, TeamEnum.black) test_game.make_move((CheckersMove([3, 3, 1, 1])))
def test_potential_capture_added_when_blocking_piece_is_removed(self): test_board = CheckerBoardFactory.build_board_from_preset( BoardPresetDataclass(8, 8, [(1, 0), (3, 2)], [(2, 1), (2, 3)])) test_game = CheckersGame(test_board) test_game.switch_team_turn() test_game.make_move(CheckersMove([2, 3, 4, 1])) self.assertEqual(test_game.current_team, TeamEnum.white) self.assertIn(CheckersMove([1, 0, 3, 2]), test_game.possible_capture_moves[TeamEnum.white])
def test_board_dimensions(self): test_board = CheckerBoardFactory.build_board_from_preset( BoardPresetDataclass(8, 100, [(0, 0)], [])) test_board.move_piece( CheckersMove([0, 0, 2, 2]).source, CheckersMove([0, 0, 2, 2]).target) test_board.move_piece( CheckersMove([2, 2, 4, 11]).source, CheckersMove([2, 2, 4, 11]).target) self.assertRaises(OutOfBoardException, test_board.move_piece, CheckersMove([4, 11, 11, 11]).source, CheckersMove([4, 11, 11, 11]).target)
def test_verify_is_on_board(self): test_board = CheckerBoardFactory.build_board_from_preset(BoardPresetDataclass(8, 100, [(0, 0)], [])) test_game = CheckersGame(test_board) self.assertTrue(test_game.is_move_inside_board(CheckersMove([0, 0, 2, 2]))) self.assertTrue(test_game.is_move_inside_board(CheckersMove([2, 2, 4, 11]))) self.assertTrue(test_game.is_move_inside_board(CheckersMove([2, 2, 7, 99]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([4, 11, 11, 11]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([8, 100, 11, 11]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([7, 100, 11, 11]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([8, 99, 11, 11]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([-1, 99, 11, 11]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([5, -2, 11, 11]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([5, 5, 8, 100]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([5, 5, 7, 100]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([5, 5, 8, 99]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([5, 5, 5, -1]))) self.assertFalse(test_game.is_move_inside_board(CheckersMove([5, 5, -5, 55])))
def test_extensive_possible_captures(self): test_board = CheckerBoardFactory.build_board_from_preset( BoardPresetDataclass(8, 8, [(7, 2), (6, 3), (4, 3), (3, 2), (2, 3)], [(5, 4), (4, 5), (5, 6), (6, 5)])) test_game = CheckersGame(test_board) test_game.switch_team_turn() test_game.make_move(CheckersMove([4, 5, 3, 4])) self.assertEqual(test_game.current_team, TeamEnum.white) white_potential_captures = [[6, 3, 4, 5], [4, 3, 2, 5], [2, 3, 4, 5]] black_potential_captures = [[3, 4, 1, 2], [3, 4, 5, 2]] for move in create_move_iterator_from_list_of_lists( white_potential_captures): self.assertIn(move, test_game.possible_capture_moves[TeamEnum.white]) for move in create_move_iterator_from_list_of_lists( black_potential_captures): self.assertIn(move, test_game.possible_capture_moves[TeamEnum.black])
class CheckerBoardTestPresets: multi_capture_test_board_8_by_8 = BoardPresetDataclass(8, 8, [(0, 0)], [(1, 1), (3, 3)]) simple_tie_test_board = BoardPresetDataclass(8, 8, [(0, 7)], [(1, 0)]) test_capture_board = BoardPresetDataclass(8, 8, [(3, 2), (0, 1), (7, 0)], [(4, 3), (2, 3), (6, 1)])