Пример #1
0
    def move_piece(self, the_piece, pos_x, pos_y, gui_board):
        
        gui_board.move_a_piece(the_piece, pos_x, pos_y , self.board_array)

        brd = self.board_array
        #gui_board.move_a_piece(the_piece, pos_x, pos_y)
        temp = piece("", "", the_piece.x, the_piece.y)

        self.board_array[the_piece.x][the_piece.y] = temp
        
        the_piece.x = pos_x
        the_piece.y = pos_y

        #White Castle Queen Side
        if(the_piece == "king" and the_piece.moves == 0 and pos_x == 2 and pos_y == 0):
            rook1 = brd[0][0]
            gui_board.move_a_piece(rook1, 3, 0, self.board_array)
            temp2 = piece("", "", 0, 0)
            rook1.moves = rook1.moves+1
            rook1.x = 3
            rook1.y = 0
            self.board_array[3][0] = rook1
            self.board_array[0][0] = temp2

        #White castle king side
        elif(the_piece == "king" and the_piece.moves == 0 and pos_x == 6 and pos_y == 0):
            temp2 = piece("", "", 0, 0)
            rook1 = brd[7][0]
            gui_board.move_a_piece(rook1, 5, 0, self.board_array)
            rook1.moves = rook1.moves+1
            rook1.x = 5
            rook1.y = 0
            self.board_array[5][0] = rook1
            self.board_array[7][0] = temp2

        #Black castle queen side
        elif(the_piece == "king" and the_piece.moves == 0 and pos_x == 2 and pos_y == 7):
            temp2 = piece("", "", 0, 0)
            rook1 = brd[0][7]
            gui_board.move_a_piece(rook1, 3, 7, self.board_array)
            rook1.moves = rook1.moves+1
            rook1.x = 3
            rook1.y = 7
            self.board_array[3][7] = rook1
            self.board_array[0][7] = temp2

        #Black castle king side
        elif(the_piece == "king" and the_piece.moves == 0 and pos_x == 6 and pos_y == 7):
            temp2 = piece("", "", 0, 0)
            rook1 = brd[7][7]
            gui_board.move_a_piece(rook1, 5, 7, self.board_array)
            rook1.moves = rook1.moves+1
            rook1.x = 5
            rook1.y = 7
            self.board_array[5][7] = rook1
            self.board_array[7][7] = temp2


        the_piece.moves = the_piece.moves+1
        self.board_array[pos_x][pos_y] = the_piece
Пример #2
0
def is_move_legal(old_array, the_piece, pos_x, pos_y):
            
    colour_move = the_piece.colour

    temp = piece("", "", the_piece.x, the_piece.y)

    temp_array = old_array

    old_x = the_piece.x
    old_y = the_piece.y


    a_temp_piece = temp_array[pos_x][pos_y]

    temp_array[pos_x][pos_y] = the_piece
    temp_array[the_piece.x][the_piece.y] = temp


    if (colour_move == "white"):
        is_check = is_white_in_check(temp_array)
    else:
        is_check = is_black_in_check(temp_array)

    if(is_check == True):
        is_legal = False
    else:
        is_legal = True


    temp_array[pos_x][pos_y] = a_temp_piece
    temp_array[old_x][old_y] = the_piece


    return is_legal
    
Пример #3
0
    def total_black_potentials(self):
        brd_array = self.board_array

        pieces_that_can_move = []

        for x in range(0,8):
            for y in range(0,8):
                self.board_array[x][y].potentials = []
                temp_piece = brd_array[x][y]
                temp_piece.potentials.clear()
                if(temp_piece.colour == "black"):

                    #print(temp_piece.name, temp_piece.x, temp_piece.y)
                    potential = temp_piece.get_potential(brd_array)

                    if(potential is not None):

                        can_move = 0
                        a_temp_array = []
                        for p in potential:
                            can_move = 1
                            a_temp_array.append(p)

                        if(can_move == 1):
                            temp_piece.set_potential(a_temp_array)
                            new_piece = piece(temp_piece.name, temp_piece.colour, temp_piece.x, temp_piece.y, temp_piece.id, a_temp_array)
                            pieces_that_can_move.append(new_piece)


        return pieces_that_can_move
Пример #4
0
 def __init__(self):
     
     counter = 0
     for x in range(0, 8):
         for i in range(0,8):
             temp = piece("", "", x, i, counter)
             self.board_array[x][i] = temp
             counter = counter+1
Пример #5
0
    def get_black_potentials(self):

        brd_array = self.board_array

        pieces_that_can_move = []

        for x in range(0,8):
            for y in range(0,8):
                self.board_array[x][y].potentials = []
                temp_piece = brd_array[x][y]
                temp_piece.potentials.clear()
                if(temp_piece.colour == "black"):
                    potential = temp_piece.get_potential(brd_array)

                    if(potential is not None):
                        #print(temp_piece.name)
                        can_move = 0
                        a_temp_array = []
                        for p in potential:
                            #print(p.x, p.y, "   ", end = "")
                            #print()
                            is_legal = is_move_legal(brd_array, temp_piece, p.x, p.y)
                            #print(temp_piece.name, p.x, p.y)
                            if(is_legal == True):
                                can_move = 1
                                a_temp_array.append(p)
                                #print(temp_piece.name)

                        if(can_move == 1):
                            temp_piece.set_potential(a_temp_array)
                            new_piece = piece(temp_piece.name, temp_piece.colour, temp_piece.x, temp_piece.y, temp_piece.id, a_temp_array)
                            pieces_that_can_move.append(new_piece)

        
        king_side, queen_side = self.black_castling()

        if(king_side == 1):
            print("KING SIDE")
            for x in pieces_that_can_move:
                #print(x.name)
                if(x.name == "king"):
                    x.potentials.append(brd_array[6][7])
                    print("APPENDED")
        if(queen_side == 1):
            print("QUEEN SIDE")
            for x in pieces_that_can_move:
                if(x.name == "king"):
                    x.potentials.append(brd_array[2][7])

        return pieces_that_can_move