Exemplo n.º 1
0
    def complete_matrix_pieces(self):

        for row, pieces_row in enumerate(self.matrix):
            for col, piece in enumerate(pieces_row):
                # Creates a list with black pieces
                if piece == '♟':
                    black_pawn = pieces.Pawn(False, row, col)
                    self.matrix_pieces[row][col] = black_pawn
                elif piece == '♞':
                    black_horse = pieces.Horse(False, row, col)
                    self.matrix_pieces[row][col] = black_horse
                elif piece == '♝':
                    black_bishop = pieces.Bishop(False, row, col)
                    self.matrix_pieces[row][col] = black_bishop
                elif piece == '♜':
                    black_rook = pieces.Rook(False, row, col)
                    self.matrix_pieces[row][col] = black_rook
                elif piece == '♛':
                    black_queen = pieces.Queen(False, row, col)
                    self.matrix_pieces[row][col] = black_queen
                elif piece == '♚':
                    black_king = pieces.King(False, row, col)
                    self.matrix_pieces[row][col] = black_king

                # Creates a list with white pieces
                elif piece == '♙':
                    white_pawn = pieces.Pawn(True, row, col)
                    self.matrix_pieces[row][col] = white_pawn
                elif piece == '♘':
                    white_horse = pieces.Horse(True, row, col)
                    self.matrix_pieces[row][col] = white_horse
                elif piece == '♗':
                    white_bishop = pieces.Bishop(True, row, col)
                    self.matrix_pieces[row][col] = white_bishop
                elif piece == '♖':
                    white_rook = pieces.Rook(True, row, col)
                    self.matrix_pieces[row][col] = white_rook
                elif piece == '♕':
                    white_queen = pieces.Queen(True, row, col)
                    self.matrix_pieces[row][col] = white_queen
                elif piece == '♔':
                    white_king = pieces.King(True, row, col)
                    self.matrix_pieces[row][col] = white_king

                # Creates a list with empty squares
                else:
                    empty_square = pieces.EmptySquare(row, col)
                    self.matrix_pieces[row][col] = empty_square
Exemplo n.º 2
0
    def test_capture_piece_rook_bad(self):
        factor = 1
        black_queen = pieces.Queen(False, 8, 8)
        white_rook = pieces.Rook(True, 12, 8)

        self.assertEqual(61,
                         score.capture_piece(black_queen, white_rook, factor))
Exemplo n.º 3
0
    def test_whiterook_invalid_move_jump(self):
        rook = pieces.Rook(True, 7, 7)

        empty_square1 = pieces.EmptySquare(5, 5)     # up_rigth
        empty_square2 = pieces.EmptySquare(9, 9)     # down_right
        empty_square3 = pieces.EmptySquare(9, 5)     # down_left
        empty_square4 = pieces.EmptySquare(3, 3)     # up_left

        self.assertFalse(rook.valid_move(empty_square1))
        self.assertFalse(rook.valid_move(empty_square2))
        self.assertFalse(rook.valid_move(empty_square3))
        self.assertFalse(rook.valid_move(empty_square4))
Exemplo n.º 4
0
    def test_whiterook_valid_move_jump(self):
        rook = pieces.Rook(True, 7, 7)

        empty_square1 = pieces.EmptySquare(0, 7)     # up
        empty_square2 = pieces.EmptySquare(7, 5)     # right
        empty_square3 = pieces.EmptySquare(12, 7)    # down
        empty_square4 = pieces.EmptySquare(7, 1)     # left

        self.assertTrue(rook.valid_move(empty_square1))
        self.assertTrue(rook.valid_move(empty_square2))
        self.assertTrue(rook.valid_move(empty_square3))
        self.assertTrue(rook.valid_move(empty_square4))
Exemplo n.º 5
0
    def test_whiterook_invalid_move_capture(self):
        rook = pieces.Rook(True, 7, 7)

        rival1 = pieces.Pawn(False, 5, 5)     # up_rigth
        rival2 = pieces.Pawn(False, 9, 9)     # down_right
        rival3 = pieces.Pawn(False, 9, 5)     # down_left
        rival4 = pieces.Pawn(False, 3, 3)     # up_left

        self.assertFalse(rook.valid_move(rival1))
        self.assertFalse(rook.valid_move(rival2))
        self.assertFalse(rook.valid_move(rival3))
        self.assertFalse(rook.valid_move(rival4))
Exemplo n.º 6
0
    def test_whiterook_valid_move_capture(self):
        rook = pieces.Rook(True, 7, 7)

        rival1 = pieces.Pawn(False, 0, 7)     # up
        rival2 = pieces.Pawn(False, 7, 5)     # right
        rival3 = pieces.Pawn(False, 12, 7)     # down
        rival4 = pieces.Pawn(False, 7, 1)     # left

        self.assertTrue(rook.valid_move(rival1))
        self.assertTrue(rook.valid_move(rival2))
        self.assertTrue(rook.valid_move(rival3))
        self.assertTrue(rook.valid_move(rival4))
Exemplo n.º 7
0
    def test_jump_rival_rook(self):
        factor = -1
        rook = pieces.Rook(True, 8, 8)

        self.assertEqual(-9, score.jump_piece(rook, factor))