Esempio n. 1
0
 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]))
Esempio n. 2
0
 def test_incomplete_game(self):
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardTestPresets.simple_tie_test_board))
     test_game.board.set_up_pieces([], [(5, 5)])
     test_game.switch_team_turn()
     self.assertEqual(test_game.end_game().value, 'incomplete game')
Esempio n. 3
0
 def test_move_piece_with_occupied_target(self):
     test_board = CheckerBoardFactory.build_board_from_preset(
         CheckerBoardPresets.standard_8_by_8)
     source = (1, 0)
     target = (3, 0)
     self.assertRaises(BoardTileOccupiedException, test_board.move_piece,
                       source, target)
Esempio n. 4
0
 def test_move_piece_with_bad_source(self):
     test_board = CheckerBoardFactory.build_board_from_preset(
         CheckerBoardPresets.standard_8_by_8)
     source = (1, 1)
     target = (1, 0)
     self.assertRaises(MissingGamePieceException, test_board.move_piece,
                       source, target)
Esempio n. 5
0
 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])))
Esempio n. 6
0
 def test_move_piece_to_outside_the_board(self):
     test_board = CheckerBoardFactory.build_board_from_preset(
         CheckerBoardPresets.standard_8_by_8)
     source = (1, 0)
     for target in [(8, 0), (-1, 0), (0, 8), (0, -1), (0, 11)]:
         self.assertRaises(OutOfBoardException, test_board.move_piece,
                           source, target)
Esempio n. 7
0
 def test_black_wins_game(self):
     move_iterator = create_move_iterator_from_move_file('games/black.txt')
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardPresets.standard_8_by_8))
     for ind, move in enumerate(move_iterator):
         test_game.make_move(move)
     self.assertEqual(test_game.end_game().value, 'second')
Esempio n. 8
0
 def test_white_wins_game(self):
     move_iterator = create_move_iterator_from_move_file('games/white.txt')
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardPresets.standard_8_by_8))
     for move in move_iterator:
         test_game.make_move(move)
     self.assertEqual(test_game.end_game().value, 'first')
Esempio n. 9
0
 def test_valid_move(self):
     test_board = CheckerBoardFactory.build_board_from_preset(
         CheckerBoardPresets.standard_8_by_8)
     test_game = CheckersGame(test_board)
     test_game.make_move(CheckersMove([1, 2, 2, 3]))
     self.assertIsInstance(test_game.board[2, 3], CheckersGamePiece)
     self.assertEqual(test_game.board[2, 3].team, TeamEnum.white)
     self.assertIsNone(test_game.board[1, 2])
Esempio n. 10
0
def main():
    parser = argparse.ArgumentParser(description='Please enter file path for game')
    parser.add_argument('path', type=str)
    args = parser.parse_args()
    move_iterator = create_move_iterator_from_move_file(args.path)
    game = CheckersGame(CheckerBoardFactory.build_board_from_preset(CheckerBoardPresets.standard_8_by_8))
    game_result = game.run_game(move_iterator)
    print(f'{os.path.basename(args.path)} - {game_result}')
Esempio n. 11
0
 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])
Esempio n. 12
0
 def test_verify_move_is_diagonal(self):
     test_board = CheckerBoardFactory.build_board_from_preset(CheckerBoardPresets.standard_8_by_8)
     test_game = CheckersGame(test_board)
     self.assertTrue(test_game.verify_move_is_diagonal(CheckersMove([0, 0, 1, 1])))
     self.assertTrue(test_game.verify_move_is_diagonal(CheckersMove([0, 0, 2, 2])))
     self.assertFalse(test_game.verify_move_is_diagonal(CheckersMove([0, 0, 4, 2])))
     self.assertTrue(test_game.verify_move_is_diagonal(CheckersMove([1, 1, 0, 0])))
     self.assertTrue(test_game.verify_move_is_diagonal(CheckersMove([2, 2, 0, 0])))
     self.assertFalse(test_game.verify_move_is_diagonal(CheckersMove([4, 2, 0, 0])))
Esempio n. 13
0
 def test_verify_source_is_correct_color(self):
     test_board = CheckerBoardFactory.build_board_from_preset(CheckerBoardPresets.standard_8_by_8)
     test_game = CheckersGame(test_board, skip_scan_for_pieces_that_can_capture=True)
     self.assertTrue(test_game.verify_source_is_correct_color(CheckersMove([7, 6, 1, 1]), TeamEnum.black))
     self.assertTrue(test_game.verify_source_is_correct_color(CheckersMove([1, 2, 1, 1]), TeamEnum.white))
     self.assertFalse(test_game.verify_source_is_correct_color(CheckersMove([1, 2, 1, 1]), TeamEnum.black))
     self.assertFalse(test_game.verify_source_is_correct_color(CheckersMove([7, 6, 1, 1]), TeamEnum.white))
     self.assertFalse(test_game.verify_source_is_correct_color(CheckersMove([0, 0, 1, 1]), TeamEnum.white))
     self.assertFalse(test_game.verify_source_is_correct_color(CheckersMove([-1, 0, 1, 1]), TeamEnum.black))
Esempio n. 14
0
 def test_possible_captures(self):
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardTestPresets.test_capture_board))
     test_game.make_move(CheckersMove([3, 2, 5, 4]))
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardTestPresets.test_capture_board))
     test_game.make_move(CheckersMove([3, 2, 1, 4]))
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardTestPresets.test_capture_board))
     test_game.make_move(CheckersMove([7, 0, 5, 2]))
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardTestPresets.test_capture_board))
     self.assertRaises(IllegalMoveException, test_game.make_move,
                       CheckersMove([0, 1, 1, 2]))
Esempio n. 15
0
 def test_no_piece_to_capture(self):
     test_board = CheckerBoardFactory.build_board_from_preset(
         CheckerBoardPresets.standard_8_by_8)
     source = (1, 0)
     target = (1, 1)
     captured_piece = (0, 4)
     self.assertIsInstance(test_board[source], CheckersGamePiece)
     self.assertEqual(test_board[source].team, TeamEnum.white)
     self.assertIsNone(test_board[target], CheckersGamePiece)
     self.assertRaises(MissingGamePieceException, test_board.capture_piece,
                       source, target, captured_piece)
Esempio n. 16
0
 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)
Esempio n. 17
0
 def test_move_piece(self):
     test_board = CheckerBoardFactory.build_board_from_preset(
         CheckerBoardPresets.standard_8_by_8)
     source = (1, 0)
     target = (1, 1)
     self.assertIsInstance(test_board[source], CheckersGamePiece)
     self.assertEqual(test_board[source].team, TeamEnum.white)
     self.assertIsNone(test_board[target], CheckersGamePiece)
     test_board.move_piece(source, target)
     self.assertIsInstance(test_board[target], CheckersGamePiece)
     self.assertEqual(test_board[target].team, TeamEnum.white)
     self.assertIsNone(test_board[source], CheckersGamePiece)
Esempio n. 18
0
 def test_verify_move_is_valid(self):
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardPresets.standard_8_by_8))
     self.assertRaises(IllegalMoveException, test_game.verify_move_is_valid,
                       CheckersMove([1, 0, 0, 1]), TeamEnum.white)
     self.assertRaises(IllegalMoveException, test_game.verify_move_is_valid,
                       CheckersMove([0, 1, 2, 3]), TeamEnum.white)
     self.assertRaises(IllegalMoveException, test_game.verify_move_is_valid,
                       CheckersMove([0, 1, 2, 3]), TeamEnum.white)
     self.assertRaises(IllegalMoveException, test_game.verify_move_is_valid,
                       CheckersMove([0, 1, 2, 3]), TeamEnum.black)
     self.assertRaises(IllegalMoveException, test_game.verify_move_is_valid,
                       CheckersMove([1, 2, 0, 3]), TeamEnum.black)
     self.assertRaises(IllegalMoveException, test_game.verify_move_is_valid,
                       CheckersMove([1, 2, -1, 4]), TeamEnum.white)
     test_game.board.remove_piece((4, 5))
     self.assertRaises(IllegalMoveException, test_game.verify_move_is_valid,
                       CheckersMove([1, 2, 4, 5]), TeamEnum.white)
     self.assertRaises(IllegalMoveException, test_game.verify_move_is_valid,
                       CheckersMove([7, 2, 5, 3]), TeamEnum.white)
     test_game.verify_move_is_valid(CheckersMove([1, 2, 0, 3]),
                                    TeamEnum.white)
     test_game.verify_move_is_valid(CheckersMove([3, 2, 2, 3]),
                                    TeamEnum.white)
     test_game.verify_move_is_valid(CheckersMove([3, 2, 4, 3]),
                                    TeamEnum.white)
     test_game2 = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardTestPresets.multi_capture_test_board_8_by_8))
     test_game2.verify_move_is_valid(CheckersMove([0, 0, 2, 2]),
                                     TeamEnum.white)
     test_game2.board.set_up_pieces([(5, 6)], [(4, 5)])
     self.assertRaises(IllegalMoveException,
                       test_game2.verify_move_is_valid,
                       CheckersMove([5, 6, 6, 5]), TeamEnum.white)
     self.assertRaises(IllegalMoveException,
                       test_game2.verify_move_is_valid,
                       CheckersMove([5, 6, 3, 4]), TeamEnum.white)
Esempio n. 19
0
 def test_ignore_capture_move_raises_exception(self):
     list_of_setup_moves = [
         [1, 2, 2, 3],
         [0, 5, 1, 4],
     ]
     illegal_move = [2, 3, 3, 4]
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardPresets.standard_8_by_8))
     for move in create_move_iterator_from_list_of_lists(
             list_of_setup_moves):
         test_game.make_move(move)
     self.assertRaises(IllegalMoveException, test_game.make_move,
                       CheckersMove(illegal_move))
Esempio n. 20
0
 def test_multi_capture(self):
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardTestPresets.multi_capture_test_board_8_by_8))
     move_list = [[0, 0, 2, 2], [2, 2, 4, 4]]
     move_iterator = create_move_iterator_from_list_of_lists(move_list)
     test_game.make_move(next(move_iterator))
     self.assertEqual(test_game.current_team, TeamEnum.white)
     test_game.make_move(next(move_iterator))
     self.assertIsNone(test_game.board[0, 0])
     self.assertIsNone(test_game.board[1, 1])
     self.assertIsNone(test_game.board[3, 3])
     self.assertIsInstance(test_game.board[4, 4], CheckersGamePiece)
     self.assertEqual(test_game.current_team, TeamEnum.black)
Esempio n. 21
0
 def test_black_cant_move_backwards(self):
     test_board = CheckerBoardFactory.build_board_from_preset(
         CheckerBoardPresets.standard_8_by_8)
     test_game = CheckersGame(test_board)
     move_list = [[1, 2, 2, 3], [2, 5, 3, 4], [2, 3, 1, 4]]
     team_iterator = self.team_iterator()
     for move in create_move_iterator_from_list_of_lists(move_list):
         test_game.make_move(move)
         self.assertIsInstance(test_game.board[move.target],
                               CheckersGamePiece)
         self.assertEqual(test_game.board[move.target].team,
                          next(team_iterator))
         self.assertIsNone(test_game.board[move.source])
     self.assertRaises(IllegalMoveException, test_game.make_move,
                       CheckersMove([3, 4, 2, 5]))
Esempio n. 22
0
 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])))
Esempio n. 23
0
 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])
Esempio n. 24
0
 def test_check_if_there_is_a_piece_to_capture(self):
     test_board = CheckerBoardFactory.build_board_from_preset(
         CheckerBoardTestPresets.multi_capture_test_board_8_by_8)
     test_game = CheckersGame(test_board)
     self.assertTrue(
         test_game.check_if_there_is_a_piece_to_capture(
             CheckersMove([0, 0, 2, 2]), team=TeamEnum.white))
     self.assertFalse(
         test_game.check_if_there_is_a_piece_to_capture(
             CheckersMove([0, 0, 2, 2]), team=TeamEnum.black))
     test_game.board.set_up_pieces([(1, 2), (3, 4)], [(2, 3)])
     self.assertTrue(
         test_game.check_if_there_is_a_piece_to_capture(
             CheckersMove([1, 2, 3, 4]), team=TeamEnum.white))
     self.assertFalse(
         test_game.check_if_there_is_a_piece_to_capture(
             CheckersMove([3, 3, 5, 5]), TeamEnum.black))
     self.assertFalse(
         test_game.check_if_there_is_a_piece_to_capture(
             CheckersMove([3, 3, 2, 2]), TeamEnum.black))
     test_game.check_if_there_is_a_piece_to_capture(CheckersMove(
         [0, 0, 2, 2]),
                                                    team=TeamEnum.white)
Esempio n. 25
0
 def test_cant_move_to_occupied_space_by_same_team(self):
     test_board = CheckerBoardFactory.build_board_from_preset(
         CheckerBoardPresets.standard_8_by_8)
     test_game = CheckersGame(test_board)
     self.assertRaises(IllegalMoveException, test_game.make_move,
                       CheckersMove([1, 0, 0, 1]))
Esempio n. 26
0
 def test_verify_target_is_empty(self):
     test_board = CheckerBoardFactory.build_board_from_preset(CheckerBoardPresets.standard_8_by_8)
     test_game = CheckersGame(test_board, skip_scan_for_pieces_that_can_capture=True)
     self.assertTrue(test_game.verify_target_is_empty(CheckersMove([2, 1, 1, 1])))
     self.assertFalse(test_game.verify_target_is_empty(CheckersMove([1, 1, 2, 1])))
Esempio n. 27
0
 def test_find_move_type(self):
     test_board = CheckerBoardFactory.build_board_from_preset(CheckerBoardPresets.standard_8_by_8)
     test_game = CheckersGame(test_board)
     self.assertEqual(test_game.find_move_type(CheckersMove([0, 0, 1, 1])), MoveTypeEnum.regular_move)
     self.assertEqual(test_game.find_move_type(CheckersMove([0, 0, 2, 2])), MoveTypeEnum.capture)
     self.assertEqual(test_game.find_move_type(CheckersMove([0, 0, 4, 2])), MoveTypeEnum.illegal_move)
Esempio n. 28
0
 def test_tie(self):
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardTestPresets.simple_tie_test_board))
     self.assertEqual(test_game.end_game().value, 'tie game')
Esempio n. 29
0
 def test_black_wins(self):
     test_game = CheckersGame(
         CheckerBoardFactory.build_board_from_preset(
             CheckerBoardTestPresets.simple_tie_test_board))
     test_game.board.set_up_pieces([], [(7, 7)])
     self.assertEqual(test_game.end_game().value, 'second')
Esempio n. 30
0
 def test_empty_iterator(self):
     test_board = CheckerBoardFactory.build_board_from_preset(
         CheckerBoardPresets.standard_8_by_8)
     test_game = CheckersGame(test_board)
     move_iterator = create_move_iterator_from_list_of_lists([])
     print(test_game.run_game(move_iterator))