Ejemplo 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
Ejemplo n.º 2
0
    def test_capture_piece_king_bad(self):
        factor = 1
        black_queen = pieces.Queen(False, 8, 8)
        white_king = pieces.King(True, 12, 8)

        self.assertEqual(100,
                         score.capture_piece(black_queen, white_king, factor))
Ejemplo n.º 3
0
    def test_scan_King(self):
        new_score = score.Score()
        king = pieces.King(True, 2, 14)
        moves = [{'from_row': 2, 'from_col': 14, 'to_row': 1, 'to_col': 14, 'score': 43.0},
                {'from_row': 2, 'from_col': 14, 'to_row': 1, 'to_col': 15, 'score': 5},
                {'from_row': 2, 'from_col': 14, 'to_row': 2, 'to_col': 15, 'score': 5},
                {'from_row': 2, 'from_col': 14, 'to_row': 3, 'to_col': 15, 'score': 5},
                {'from_row': 2, 'from_col': 14, 'to_row': 3, 'to_col': 14, 'score': 5},
                {'from_row': 2, 'from_col': 14, 'to_row': 3, 'to_col': 13, 'score': 5},
                {'from_row': 2, 'from_col': 14, 'to_row': 1, 'to_col': 13, 'score': 5}]
        
        up          = scans.scan_up(self.actual_board, king)
        up_right    = scans.scan_up_right(self.actual_board, king)
        right       = scans.scan_right(self.actual_board, king)
        down_right  = scans.scan_down_right(self.actual_board, king)
        down        = scans.scan_down(self.actual_board, king)
        down_left   = scans.scan_down_left(self.actual_board, king)
        left        = scans.scan_left(self.actual_board, king)
        up_left     = scans.scan_up_left(self.actual_board, king)
        L           = scans.scan_L(self.actual_board, king)

        player.scan(new_score, up, king, True)
        player.scan(new_score, up_right, king, True)
        player.scan(new_score, right, king, True)
        player.scan(new_score, down_right, king, True)
        player.scan(new_score, down, king, True)
        player.scan(new_score, down_left, king, True)
        player.scan(new_score, left, king, True)
        player.scan(new_score, up_left, king, True)
        player.scan(new_score, L, king, True)

        self.assertEqual(moves, new_score.play_moves)
Ejemplo n.º 4
0
    def test_set_score(self):
        score_new = score.Score()
        color = True
        white_queen = pieces.Queen(True, 8, 8)
        black_king = pieces.King(False, 0, 8)
        move = [{
            'from_row': 8,
            'from_col': 8,
            'to_row': 0,
            'to_col': 8,
            'score': 100.0
        }]

        score_new.set_score(white_queen, black_king, color)

        self.assertEqual(move, score_new.play_moves)
Ejemplo n.º 5
0
    def test_whitekking_valid_move_jump(self):
        king = pieces.King(True, 8, 8)

        empty_square1 = pieces.EmptySquare(7, 8)     # up
        empty_square2 = pieces.EmptySquare(7, 9)     # up_right
        empty_square3 = pieces.EmptySquare(8, 9)     # right
        empty_square4 = pieces.EmptySquare(9, 9)     # down_right
        empty_square5 = pieces.EmptySquare(9, 8)    # down
        empty_square6 = pieces.EmptySquare(9, 7)    # down_left
        empty_square7 = pieces.EmptySquare(8, 7)     # left
        empty_square8 = pieces.EmptySquare(7, 7)     # up_left

        self.assertTrue(king.valid_move(empty_square1))
        self.assertTrue(king.valid_move(empty_square2))
        self.assertTrue(king.valid_move(empty_square3))
        self.assertTrue(king.valid_move(empty_square4))
        self.assertTrue(king.valid_move(empty_square5))
        self.assertTrue(king.valid_move(empty_square6))
        self.assertTrue(king.valid_move(empty_square7))
        self.assertTrue(king.valid_move(empty_square8))
Ejemplo n.º 6
0
    def test_whitekking_invalid_move_capture(self):
        king = pieces.King(True, 8, 8)

        rival1 = pieces.Pawn(False, 5, 8)     # up
        rival2 = pieces.Pawn(False, 6, 10)     # up_right
        rival3 = pieces.Pawn(False, 8, 10)     # right
        rival4 = pieces.Pawn(False, 11, 11)     # down_right
        rival5 = pieces.Pawn(False, 12, 8)    # down
        rival6 = pieces.Pawn(False, 11, 5)    # down_left
        rival7 = pieces.Pawn(False, 8, 5)     # left
        rival8 = pieces.Pawn(False, 6, 6)     # up_left

        self.assertFalse(king.valid_move(rival1))
        self.assertFalse(king.valid_move(rival2))
        self.assertFalse(king.valid_move(rival3))
        self.assertFalse(king.valid_move(rival4))
        self.assertFalse(king.valid_move(rival5))
        self.assertFalse(king.valid_move(rival6))
        self.assertFalse(king.valid_move(rival7))
        self.assertFalse(king.valid_move(rival8))
Ejemplo n.º 7
0
    def test_whitekking_valid_move_capture(self):
        king = pieces.King(True, 8, 8)

        rival1 = pieces.Pawn(False, 7, 8)     # up
        rival2 = pieces.Pawn(False, 7, 9)     # up_right
        rival3 = pieces.Pawn(False, 8, 9)     # right
        rival4 = pieces.Pawn(False, 9, 9)     # down_right
        rival5 = pieces.Pawn(False, 9, 8)    # down
        rival6 = pieces.Pawn(False, 9, 7)    # down_left
        rival7 = pieces.Pawn(False, 8, 7)     # left
        rival8 = pieces.Pawn(False, 7, 7)     # up_left

        self.assertTrue(king.valid_move(rival1))
        self.assertTrue(king.valid_move(rival2))
        self.assertTrue(king.valid_move(rival3))
        self.assertTrue(king.valid_move(rival4))
        self.assertTrue(king.valid_move(rival5))
        self.assertTrue(king.valid_move(rival6))
        self.assertTrue(king.valid_move(rival7))
        self.assertTrue(king.valid_move(rival8))
Ejemplo n.º 8
0
    def test_blackking_invalid_move_jump(self):
        king = pieces.King(False, 8, 8)

        empty_square1 = pieces.EmptySquare(5, 8)     # up
        empty_square2 = pieces.EmptySquare(6, 10)    # up_right
        empty_square3 = pieces.EmptySquare(8, 10)    # right
        empty_square4 = pieces.EmptySquare(11, 11)   # down_right
        empty_square5 = pieces.EmptySquare(12, 8)    # down
        empty_square6 = pieces.EmptySquare(11, 5)    # down_left
        empty_square7 = pieces.EmptySquare(8, 5)     # left
        empty_square8 = pieces.EmptySquare(6, 6)     # up_left

        self.assertFalse(king.valid_move(empty_square1))
        self.assertFalse(king.valid_move(empty_square2))
        self.assertFalse(king.valid_move(empty_square3))
        self.assertFalse(king.valid_move(empty_square4))
        self.assertFalse(king.valid_move(empty_square5))
        self.assertFalse(king.valid_move(empty_square6))
        self.assertFalse(king.valid_move(empty_square7))
        self.assertFalse(king.valid_move(empty_square8))
Ejemplo n.º 9
0
    def test_whiteking_invalid_move_jump(self):
        king = pieces.King(True, 8, 8)

        empty_square1 = pieces.EmptySquare(5, 8)     # up
        empty_square2 = pieces.EmptySquare(6, 10)    # up_right
        empty_square3 = pieces.EmptySquare(8, 10)    # right
        empty_square4 = pieces.EmptySquare(11, 11)   # down_right
        empty_square5 = pieces.EmptySquare(12, 8)    # down
        empty_square6 = pieces.EmptySquare(11, 5)    # down_left
        empty_square7 = pieces.EmptySquare(8, 5)     # left
        empty_square8 = pieces.EmptySquare(6, 6)     # up_left

        self.assertFalse(king.valid_move(empty_square1))
        self.assertFalse(king.valid_move(empty_square2))
        self.assertFalse(king.valid_move(empty_square3))
        self.assertFalse(king.valid_move(empty_square4))
        self.assertFalse(king.valid_move(empty_square5))
        self.assertFalse(king.valid_move(empty_square6))
        self.assertFalse(king.valid_move(empty_square7))
        self.assertFalse(king.valid_move(empty_square8))

# if __name__ == 'main':
#     unittest.main()
Ejemplo n.º 10
0
    def test_jump_rival_king(self):
        factor = -1
        king = pieces.King(True, 8, 8)

        self.assertEqual(-5, score.jump_piece(king, factor))