Exemplo n.º 1
0
    def update_board(self, old_row, old_col, new_row, new_col):
        board = self.board
        piece = board[old_row][old_col]
        delta_x = new_row - old_row
        delta_y = new_col - old_col
        all_moves = self.space_available(piece)
        if (new_row, new_col) in [move[0] for move in all_moves]:
            if (delta_x % 2 == 0):
                jumped_x = delta_x // 2
                jumped_y = delta_y // 2
                if (jumped_y == -1 and jumped_x == 1) or \
                        (jumped_y == 1 and jumped_x == -1):
                    board[old_row - jumped_y][old_col - jumped_x] = None
                else:
                    board[old_row + jumped_y][old_col + jumped_x] = None
                if piece.get_type() == 'USER' or \
                   piece.get_type() == 'USER_KING':
                    self.num_cpu_pieces -= 1
                else:
                    self.num_user_pieces -= 1
            board[old_row][old_col] = None
            piece.set_location(new_row, new_col)

            if piece.get_type() == 'USER' and new_row == 0:
                piece = Piece('USER_KING', new_row, new_col)
            elif piece.get_type() == 'CPU' and new_row == 7:
                piece = Piece('CPU_KING', new_row, new_col)
            board[new_row][new_col] = piece
        return board