class ComputerMoveServiceTest(unittest.TestCase): def setUp(self): self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=2) def test_get_minimax(self): assert self.game.current_player.is_white is True self.game._move_service.get_computer_move_applied() assert self.game.current_player.is_white is False self.game._move_service.get_computer_move_applied() assert self.game.current_player.is_white is True del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=2, board_type="Check") assert self.game.current_player.is_white is True self.game._move_service.get_computer_move_applied() assert self.game.current_player.is_white is False self.game._move_service.get_computer_move_applied() assert self.game.current_player.is_white is True self.game._move_service.get_computer_move_applied() assert self.game.current_player.is_white is False self.game._move_service.get_computer_move_applied() assert self.game.current_player.is_white is True del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=3, board_type="Check in One for White") assert self.game.current_player.is_white is True self.game._move_service.get_computer_move_applied() assert self.game.current_player.is_white is False del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=3, board_type="Check in One for White") self.game.get_next_player_turn() assert self.game.current_player.is_white is False self.game._move_service.get_computer_move_applied() assert self.game.current_player.is_white is True del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=3, board_type="Check in One for Black") assert self.game.current_player.is_white is True self.game._move_service.get_computer_move_applied() assert self.game.current_player.is_white is False del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=3, board_type="Check in One for Black") self.game.get_next_player_turn() assert self.game.current_player.is_white is False self.game._move_service.get_computer_move_applied() assert self.game.current_player.is_white is True def tearDown(self): del self.game
class MoveServiceTest(unittest.TestCase): def setUp(self): self.game = Game(white_player=Human(is_white=True), black_player=Computer(is_white=False), depth=2) def test_get_move_tested(self): player = self.game.current_player initial_square = self.game.board.get_square(1, 1) target_square = self.game.board.get_square(1, 2) move = Move(player, initial_square, target_square) self.game.get_next_player_turn() assert self.game._move_service.get_move_tested(move, player) is False self.game.get_next_player_turn() initial_square = self.game.board.get_square(3, 3) target_square = self.game.board.get_square(1, 1) move = Move(player, initial_square, target_square) assert self.game._move_service.get_move_tested(move, player) is False initial_square = self.game.board.get_square(7, 2) target_square = self.game.board.get_square(7, 4) move = Move(player, initial_square, target_square) assert self.game._move_service.get_move_tested(move, player) is False initial_square = self.game.board.get_square(1, 2) target_square = self.game.board.get_square(3, 2) move = Move(player, initial_square, target_square) assert self.game._move_service.get_move_tested(move, player) is False del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=1, board_type="Castling") self.game.get_human_move(self.game.current_player, 1, 1, 1, 2) self.game.get_undo_performed() def test_get_wrong_move_tested(self): assert self.game.get_human_move(self.game.current_player, 1, 3, 3, 1) is False self.game.get_next_player_turn() assert self.game.get_human_move(self.game.current_player, 8, 3, 5, 1) is False assert self.game.get_human_move(self.game.current_player, 8, 8, 1, 8) is False assert self.game.get_human_move(self.game.current_player, 8, 8, 8, 8) is False del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=1, board_type="Castling") assert self.game.get_human_move(self.game.current_player, 1, 1, 2, 3) is False assert self.game.get_human_move(self.game.current_player, 1, 5, 8, 8) is False assert self.game.get_human_move(self.game.current_player, 2, 5, 1, 8) is False del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=1, board_type="Fail Castling") assert self.game.get_human_move(self.game.current_player, 1, 5, 1, 8) is False assert self.game.get_human_move(self.game.current_player, 6, 7, 8, 7) is False def test_get_castling_move_tested(self): del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=1, board_type="Castling") self.game.get_human_move(self.game.current_player, 1, 1, 1, 2) self.game.get_human_move(self.game.current_player, 8, 8, 5, 5) initial_square = self.game.board.get_square(1, 5) target_square = self.game.board.get_square(1, 7) move = Move(self.game.current_player, initial_square, target_square) assert self.game._move_service.get_move_tested( move, self.game.current_player) is False def test_get_long_castling_tested(self): del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=1, board_type="Castling") assert self.game.get_human_move(self.game.current_player, 1, 5, 1, 3) is True del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=1, board_type="Fail Castling") self.game.get_next_player_turn() assert self.game.get_human_move(self.game.current_player, 8, 1, 8, 4) is True assert self.game.get_human_move(self.game.current_player, 1, 5, 1, 3) is False self.game.get_undo_performed() self.game.get_undo_performed() assert self.game.get_human_move(self.game.current_player, 8, 1, 3, 1) is True assert self.game.get_human_move(self.game.current_player, 1, 5, 1, 3) is False def test_get_short_castling_tested(self): del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=1, board_type="Castling") assert self.game.get_human_move(self.game.current_player, 1, 5, 1, 7) is True self.game.get_undo_performed() assert self.game.get_human_move(self.game.current_player, 2, 2, 4, 2) is True assert self.game.get_human_move(self.game.current_player, 8, 8, 6, 6) is True assert self.game.get_human_move(self.game.current_player, 1, 5, 1, 7) is False def test_get_captured_piece_for_pawn_captures(self): del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=1, board_type="Castling") self.game.get_next_player_turn() assert self.game.get_human_move(self.game.current_player, 7, 3, 6, 3) is True assert self.game.get_human_move(self.game.current_player, 5, 4, 6, 3) is True assert self.game.get_human_move(self.game.current_player, 6, 8, 6, 7) is True self.game.get_undo_performed() def test_get_pawn_promotion_move_tested(self): del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=1, board_type="Castling") self.game.get_next_player_turn() assert self.game.get_human_move(self.game.current_player, 7, 3, 5, 3) is True assert self.game.get_human_move(self.game.current_player, 5, 4, 6, 3) is True self.game.get_undo_performed() self.game.get_undo_performed() assert self.game.get_human_move(self.game.current_player, 7, 3, 5, 3) is True assert self.game.get_human_move(self.game.current_player, 5, 4, 6, 3) is True self.game.get_human_move(self.game.current_player, 8, 8, 7, 7) assert self.game.get_human_move(self.game.current_player, 2, 1, 4, 1) is True self.game.get_human_move(self.game.current_player, 7, 7, 8, 8) assert self.game.get_human_move(self.game.current_player, 4, 1, 5, 1) is True self.game.get_human_move(self.game.current_player, 8, 8, 7, 7) assert self.game.get_human_move(self.game.current_player, 5, 1, 6, 1) is True self.game.get_human_move(self.game.current_player, 7, 7, 8, 8) assert self.game.get_human_move(self.game.current_player, 6, 1, 7, 1) is True self.game.get_human_move(self.game.current_player, 8, 8, 7, 7) assert self.game.get_human_move(self.game.current_player, 7, 1, 8, 1) is True def test_get_en_passant_move(self): del self.game self.game = Game(white_player=Human(is_white=True), black_player=Human(is_white=False), depth=1, board_type="Castling") assert self.game.get_human_move(self.game.current_player, 2, 2, 4, 2) is True assert self.game.get_human_move(self.game.current_player, 4, 3, 3, 2) is True self.game.get_undo_performed() def test_get_moves_played(self): assert len(self.game._move_service.get_moves_played()) == 0 assert self.game.get_human_move(self.game.current_player, 2, 2, 4, 2) is True assert len(self.game._move_service.get_moves_played()) == 1 def test_attributes(self): assert self.game._move_service.white_king == (1, 5) assert self.game._move_service.black_king == (8, 5) self.game._move_service.black_king = (5, 5) assert self.game._move_service.black_king == (5, 5) def tearDown(self): del self.game