Ejemplo n.º 1
0
    def test_pawn_capture_promotion(self):
        """
        Perform piece capture with a pawn that will place the pawn on the last row.
        Expected result is the pawn can be promoted.
        :return:
        """
        self.p1.color = Color.WHITE
        self.p2.color = Color.BLACK

        fen = '2b1k2r/5pP1/2n1p3/1P5p/3B1P2/2P3N1/7P/3RK3 w - -'
        game = ChessGame(fen=fen, white_player=self.p1, black_player=self.p2)

        # Capture the black pawn
        result = game.move_piece('g7', 'h8')

        expected_move_result = MoveResult()
        expected_move_result.pawn_promote_info = {
            'player': self.p1,
            'promote_types': game.get_pawn_promote_types()
        }
        self.assertEqual(expected_move_result, result)

        # Promote the piece and confirm move result
        result = game.promote_pawn('g7', 'h8', Type.QUEEN)
        expected_promote_result = MoveResult()
        expected_promote_result.update_positions = {'g7': None, 'h8': Queen(Color.WHITE)}
        expected_promote_result.king_in_check = self.p2
        self.assertEqual(expected_promote_result, result)
Ejemplo n.º 2
0
    def test_move_result_pawn_promotion(self):
        self.p1.color = Color.WHITE
        self.p2.color = Color.BLACK

        fen = '8/P2n4/4b3/2q1k3/K7/8/3RB1p1/8 b - -'
        game = ChessGame(fen=fen, white_player=self.p1, black_player=self.p2)

        # Move black pawn
        result = game.move_piece('g2', 'g1')
        expected_move_result = MoveResult()
        expected_move_result.pawn_promote_info = {
            'player': self.p2,
            'promote_types': game.get_pawn_promote_types()
        }

        self.assertEqual(expected_move_result, result)

        result = game.promote_pawn('g2', 'g1', Type.QUEEN)
        expected_move_result = MoveResult()
        expected_move_result.update_positions = {'g2': None, 'g1': Queen(Color.BLACK)}
        self.assertEqual(expected_move_result, result)

        # Move white pawn
        result = game.move_piece('a7', 'a8')
        expected_move_result = MoveResult()
        expected_move_result.pawn_promote_info = {
            'player': self.p1,
            'promote_types': game.get_pawn_promote_types()
        }

        self.assertEqual(expected_move_result, result)

        result = game.promote_pawn('a7', 'a8', Type.KNIGHT)
        expected_promote_result = MoveResult()
        expected_promote_result.update_positions = {'a7': None, 'a8': Knight(Color.WHITE)}
        self.assertEqual(expected_promote_result, result)