def make_move(self, chess_board, point_to): self.was_moved = True # roque check if abs(point_to.x - self.position.x) > 1: chess_board.set(point_to, self) chess_board.set(self.position, None) if self.side is Side.WHITE: if point_to.x - self.position.x > 0: rook_pos = gb.GameBoard.default_white_rook_right_pos delta_rook = Vector2d(-1, 0) else: rook_pos = gb.GameBoard.default_white_rook_left_pos delta_rook = Vector2d(1, 0) else: if point_to.x - self.position.x > 0: rook_pos = gb.GameBoard.default_black_rook_right_pos delta_rook = Vector2d(-1, 0) else: rook_pos = gb.GameBoard.default_black_rook_left_pos delta_rook = Vector2d(1, 0) self.position = copy.deepcopy(point_to) chess_board.make_move(Move(rook_pos, point_to + delta_rook)) return super().make_move(chess_board, point_to)
def click(self, hiSq, pos): if self.cur_clicked is None or self.game_state.figures[ self.cur_clicked] is None: if self.game_state.figures[hiSq] is None: return cur_side = self.game_state.get_cur_turn_side() if cur_side is None: return if cur_side is Side.WHITE and self.game_state.figures[hiSq].getTag("figue_lat").isupper() or \ cur_side is Side.BLACK and self.game_state.figures[hiSq].getTag("figue_lat").islower(): self.cur_clicked = hiSq self.cur_clicked_pos = pos return else: return # We have let go of the piece, but we are not on a square if self.render_fsm_ref.process_set_move_player is not None: move = Move(self.cur_clicked_pos, Vector2d(hiSq % 8, hiSq // 8)) if self.game_state.figures[self.cur_clicked].getTag( "figue_lat") is "p" and hiSq // 8 is 7: if self.game_state.get_cur_turn_side( ) is Side.BLACK and self.game_state.check_move_func( move, Side.BLACK) != MoveResult.INCORRECT: self.game_state.swap_figures(self.cur_clicked, hiSq) if self.game_state.figures[self.cur_clicked] is not None: self.game_state.figures[self.cur_clicked].removeNode() self.cur_clicked = None self.game_state.fire_pawn_change_panel( Side.BLACK, copy.deepcopy(move)) self.game_state.dragging = False return if self.game_state.figures[self.cur_clicked].getTag( "figue_lat") is "P" and hiSq // 8 is 0: if self.game_state.get_cur_turn_side( ) is Side.WHITE and self.game_state.check_move_func( move, Side.WHITE) != MoveResult.INCORRECT: self.game_state.swap_figures(self.cur_clicked, hiSq) if self.game_state.figures[self.cur_clicked] is not None: self.game_state.figures[self.cur_clicked].removeNode() self.cur_clicked = None self.game_state.fire_pawn_change_panel( Side.WHITE, copy.deepcopy(move)) self.game_state.dragging = False return self.render_fsm_ref.process_set_move_player( Move(self.cur_clicked_pos, Vector2d(hiSq % 8, hiSq // 8))) self.cur_clicked = None
def generate_moves(self, chess_board): maybe_moves = [ Vector2d(1, 2), Vector2d(-1, 2), Vector2d(2, 1), Vector2d(-2, 1), Vector2d(1, -2), Vector2d(-1, -2), Vector2d(2, -1), Vector2d(-2, -1) ] correct_cells = [] for i in range(len(maybe_moves)): maybe_move = self.position + maybe_moves[i] if maybe_move.x >= Board.ROW_SIZE or maybe_move.x < 0: continue elif maybe_move.y >= Board.COLUMN_SIZE or maybe_move.y < 0: continue if _is_none_or_enemy(chess_board, self.position + maybe_moves[i], self.side) is True: correct_cells.append(self.position + maybe_moves[i]) return correct_cells
def _add_correct_cells_by_ray(position, correct_cells, chess_board, figure_side, dx, dy, step_len=Board.COLUMN_SIZE, can_step_on_figure=True): delta = Vector2d(dx, dy) cur_step_len = 0 while cur_step_len < step_len and \ Board.ROW_SIZE > position.x + delta.x >= 0 and \ 0 <= position.y + delta.y < Board.COLUMN_SIZE and \ _is_none_or_enemy(chess_board, position + delta, figure_side): if _is_enemy(chess_board, position + delta, figure_side): if can_step_on_figure: correct_cells.append(position + delta) break else: break elif _is_enemy(chess_board, position + delta, Side.get_oposite(figure_side)): break correct_cells.append(position + delta) delta.x = delta.x + dx delta.y = delta.y + dy cur_step_len = cur_step_len + 1
def __init__(self, board_position=DEFAULT_BOARD_POSITION): """ Initialize ChessBoard class function :param board_position: board position in special format (str), see: BOARD_FORMAT_DESCRIPTION """ assert len(board_position) == Board.FULL_SIZE self.board = [[None for j in range(0, Board.ROW_SIZE)] for i in range(0, Board.COLUMN_SIZE)] for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): figure_letter = board_position[i * Board.COLUMN_SIZE + j] if figure_letter.isupper(): side = Side.WHITE figure_letter = figure_letter.lower() else: side = Side.BLACK if figure_letter == 'k': figure_type = FigureType.KING elif figure_letter == 'q': figure_type = FigureType.QUEEN elif figure_letter == 'b': figure_type = FigureType.BISHOP elif figure_letter == 'n': figure_type = FigureType.KNIGHT elif figure_letter == 'r': figure_type = FigureType.ROOK elif figure_letter == 'p': figure_type = FigureType.PAWN else: continue self.board[j][i] = Figure(figure_type, side, Vector2d(j, i))
def generate_moves(self, chess_board, is_attack=False): correct_cells = [] if self.side == Side.WHITE: delta_y = -1 elif self.side == Side.BLACK: delta_y = 1 else: assert (False, "generate moves: Pawn") return None # pawn attack figure if self.position.x > 0: # en passent attack self.en_passant(chess_board, correct_cells, -1, delta_y) x = self.position.x - 1 y = self.position.y + delta_y if Board.COLUMN_SIZE > y >= 0: attack_cell = chess_board.get_by_pos(x, y) if attack_cell is not None and attack_cell.side != self.side or is_attack: correct_cells.append(Vector2d(x, y)) if self.position.x < Board.ROW_SIZE - 1: # en passent attack self.en_passant(chess_board, correct_cells, 1, delta_y) x = self.position.x + 1 y = self.position.y + delta_y if Board.COLUMN_SIZE > y >= 0: attack_cell = chess_board.get_by_pos(x, y) if attack_cell is not None and attack_cell.side != self.side or is_attack: correct_cells.append(Vector2d(x, y)) if is_attack: return correct_cells # pawn go forward if self.was_moved is False: _add_correct_cells_by_ray(self.position, correct_cells, chess_board, self.side, 0, delta_y, 2, False) else: _add_correct_cells_by_ray(self.position, correct_cells, chess_board, self.side, 0, delta_y, 1, False) return correct_cells
def grab_piece(self): if self.is_in_past: return # If a square is highlighted and it has a piece, set it to dragging # mode if self.hiSq is not False and self.figures[self.hiSq]: self.dragging = self.hiSq self.dragging_figure_position = Vector2d(self.hiSq % 8, self.hiSq // 8) if self.tap_movement_manager is not None: self.tap_movement_manager.click(self.hiSq, self.dragging_figure_position) self.hiSq = False return if self.hiSq is not None and self.tap_movement_manager is not None: self.tap_movement_manager.click( self.hiSq, Vector2d(self.hiSq % 8, self.hiSq // 8))
def release_piece(self): # Letting go of a piece. If we are not on a square, return it to its original # position. Otherwise, swap it with the piece in the new square # Make sure we really are dragging something if self.dragging is not False: # We have let go of the piece, but we are not on a square if self.dimension is Dimension._3D: self.figures[self.dragging].setPos( self.FigurePos(self.dragging)) else: self.figures[self.dragging].setPos( self.FigurePos(self.dragging)) if self.render_fsm_ref.process_set_move_player is not None: move = Move(self.dragging_figure_position, Vector2d(self.hiSq % 8, self.hiSq // 8)) if self.figures[self.dragging].getTag( "figue_lat") is "p" and self.hiSq // 8 is 7: if self.get_cur_turn_side( ) is Side.BLACK and self.check_move_func( move, Side.BLACK) != MoveResult.INCORRECT: self.swap_figures(self.dragging, self.hiSq) if self.figures[self.dragging] is not None: self.figures[self.dragging].removeNode() self.dragging = False self.fire_pawn_change_panel(Side.BLACK, move) return if self.figures[self.dragging].getTag( "figue_lat") is "P" and self.hiSq // 8 is 0: if self.get_cur_turn_side( ) is Side.WHITE and self.check_move_func( move, Side.WHITE) != MoveResult.INCORRECT: self.swap_figures(self.dragging, self.hiSq) if self.figures[self.dragging] is not None: self.figures[self.dragging].removeNode() self.dragging = False self.fire_pawn_change_panel(Side.WHITE, move) return self.render_fsm_ref.process_set_move_player( Move(self.dragging_figure_position, Vector2d(self.hiSq % 8, self.hiSq // 8))) # We are no longer dragging anything self.dragging = False
def __init__(self, figure_type, side, position): """ Initialize ChessFigure class instance :param figure_type: type of chess figure (ChessFigureType) :param side: player side (ChessSide) :param position: board position (Vector2d) """ self.figure_type = FigureType(figure_type) self.side = Side(side) self.position = Vector2d(position.x, position.y)
def __init__(self, chess_board): self.board = [[None for j in range(0, Board.ROW_SIZE)] for i in range(0, Board.COLUMN_SIZE)] for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): if chess_board.board[j][i] is None: continue figure_type = chess_board.board[j][i].figure_type side = chess_board.board[j][i].side cur_pos = Vector2d(j, i) if figure_type == FigureType.KING: was_moved = True if side == Side.WHITE: if cur_pos == GameBoard.default_white_king_pos: was_moved = False elif side == Side.BLACK: if cur_pos == GameBoard.default_black_king_pos: was_moved = False self.board[j][i] = Figures.King(side, cur_pos, was_moved) elif figure_type == FigureType.QUEEN: self.board[j][i] = Figures.Queen(side, cur_pos) elif figure_type == FigureType.ROOK: was_moved = True if side == Side.WHITE: if cur_pos == GameBoard.default_white_rook_left_pos or cur_pos == GameBoard.default_white_rook_right_pos: was_moved = False elif side == Side.BLACK: if cur_pos == GameBoard.default_black_rook_left_pos or cur_pos == GameBoard.default_black_rook_right_pos: was_moved = False self.board[j][i] = Figures.Rook(side, cur_pos, was_moved) elif figure_type == FigureType.KNIGHT: self.board[j][i] = Figures.Knight(side, cur_pos) elif figure_type == FigureType.BISHOP: self.board[j][i] = Figures.Bishop(side, cur_pos) elif figure_type == FigureType.PAWN: was_moved = True if side == Side.WHITE: if i == GameBoard.default_white_pawn_row: was_moved = False elif side == Side.BLACK: if i == GameBoard.default_black_pawn_row: was_moved = False self.board[j][i] = Figures.Pawn(side, cur_pos, was_moved) else: continue
def evaluate(self, side): total = 0 for j in range(Board.ROW_SIZE): for i in range(Board.COLUMN_SIZE): pos = Vector2d(j, i) figure = self.get(pos) if figure is not None: if figure.side is side: sign = 1 else: sign = -1 total = total + (figure.evaluate(j, i) * sign) return total
def roque_right(self, chess_board, correct_cells): # self does not move if self.was_moved is True: return # self not on check attack_cells = chess_board.summary_attacked_cells( Side.get_oposite(self.side)) if self.position in attack_cells: return if self.side == Side.WHITE: default_rook_right_pos = gb.GameBoard.default_white_rook_right_pos else: default_rook_right_pos = gb.GameBoard.default_black_rook_right_pos right_rook = chess_board.get(default_rook_right_pos) # rook does not move if not (right_rook is not None and isinstance(right_rook, Rook) and right_rook.was_moved is False): return # not on attack cell if self.position + Vector2d(1, 0) in attack_cells: return ray_to_rook = [] _add_correct_cells_by_ray(self.position, ray_to_rook, chess_board, Side.get_oposite(self.side), 1, 0) if len(ray_to_rook) == 0: return if chess_board.get(ray_to_rook[len(ray_to_rook) - 1]).position != default_rook_right_pos: return correct_cells.append(self.position + Vector2d(2, 0))
def summary_moves(self, side, my_turn=True): summary_moves = [] attacked_cells = [] for j in range(Board.ROW_SIZE): for i in range(Board.COLUMN_SIZE): attacked_cells.clear() figure = self.get_by_pos(j, i) if figure is not None and figure.side == side: if isinstance(figure, Figures.King): attacked_cells = attacked_cells + figure.generate_moves(self, my_turn) else: attacked_cells = attacked_cells + figure.generate_moves(self) for k in range(len(attacked_cells)): summary_moves.append(Move(Vector2d(j, i), attacked_cells[k])) return summary_moves
def deserialize_from_str(self, board_as_str): self.board = [[None for j in range(0, Board.ROW_SIZE)] for i in range(0, Board.COLUMN_SIZE)] str_board = ['.' for j in range(0, Board.ROW_SIZE) for i in range(0, Board.COLUMN_SIZE)] for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): str_board[i * Board.ROW_SIZE + j] = str(board_as_str).__getitem__(i * Board.ROW_SIZE + j) for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): letter = str_board[i * Board.ROW_SIZE + j] if letter.isupper(): side = Side.WHITE else: side = Side.BLACK letter = letter.lower() cur_pos = Vector2d(j, i) if letter == 'k': self.board[j][i] = Figures.King(side, cur_pos, False) elif letter == 'i': self.board[j][i] = Figures.King(side, cur_pos, True) elif letter == 'b': self.board[j][i] = Figures.Bishop(side, cur_pos) elif letter == 'r': self.board[j][i] = Figures.Rook(side, cur_pos, False) elif letter == 'o': self.board[j][i] = Figures.Rook(side, cur_pos, True) elif letter == 'n': self.board[j][i] = Figures.Knight(side, cur_pos) elif letter == 'q': self.board[j][i] = Figures.Queen(side, cur_pos) elif letter == 'p': self.board[j][i] = Figures.Pawn(side, cur_pos) elif letter == 'a': self.board[j][i] = Figures.Pawn(side, cur_pos, True) elif letter == 'w': self.board[j][i] = Figures.Pawn(side, cur_pos, False, True)
def make_move(self, chess_board, point_to): passent_cells = [] if self.side == Side.WHITE: delta_y = -1 else: delta_y = 1 if self.position.x < Board.ROW_SIZE - 1: self.en_passant(chess_board, passent_cells, 1, delta_y) if self.position.x > 0: self.en_passant(chess_board, passent_cells, -1, delta_y) if abs(self.position.y - point_to.y) > 1: self.double_move = True else: self.double_move = False if point_to in passent_cells: chess_board.set(point_to - Vector2d(0, delta_y), None) super().make_move(chess_board, point_to) else: super().make_move(chess_board, point_to) self.was_moved = True
def get_king_cell(self, side): for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): if self.board[j][i] is not None: if isinstance(self.board[j][i], Figures.King) and self.board[j][i].side == side: return Vector2d(j, i)
def en_passant(self, chess_board, correct_cells, dx, dy): enemy_pawn = chess_board.get(self.position + Vector2d(dx, 0)) if enemy_pawn is not None: if isinstance(enemy_pawn, Pawn) and enemy_pawn.side != self.side: if enemy_pawn.double_move is True: correct_cells.append(self.position + Vector2d(dx, dy))
class GameBoard: default_white_king_pos = Vector2d(4, 7) default_black_king_pos = Vector2d(4, 0) default_white_pawn_row = 6 default_black_pawn_row = 1 default_white_rook_right_pos = Vector2d(7, 7) default_white_rook_left_pos = Vector2d(0, 7) default_black_rook_right_pos = Vector2d(7, 0) default_black_rook_left_pos = Vector2d(0, 0) def __init__(self, chess_board): self.board = [[None for j in range(0, Board.ROW_SIZE)] for i in range(0, Board.COLUMN_SIZE)] for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): if chess_board.board[j][i] is None: continue figure_type = chess_board.board[j][i].figure_type side = chess_board.board[j][i].side cur_pos = Vector2d(j, i) if figure_type == FigureType.KING: was_moved = True if side == Side.WHITE: if cur_pos == GameBoard.default_white_king_pos: was_moved = False elif side == Side.BLACK: if cur_pos == GameBoard.default_black_king_pos: was_moved = False self.board[j][i] = Figures.King(side, cur_pos, was_moved) elif figure_type == FigureType.QUEEN: self.board[j][i] = Figures.Queen(side, cur_pos) elif figure_type == FigureType.ROOK: was_moved = True if side == Side.WHITE: if cur_pos == GameBoard.default_white_rook_left_pos or cur_pos == GameBoard.default_white_rook_right_pos: was_moved = False elif side == Side.BLACK: if cur_pos == GameBoard.default_black_rook_left_pos or cur_pos == GameBoard.default_black_rook_right_pos: was_moved = False self.board[j][i] = Figures.Rook(side, cur_pos, was_moved) elif figure_type == FigureType.KNIGHT: self.board[j][i] = Figures.Knight(side, cur_pos) elif figure_type == FigureType.BISHOP: self.board[j][i] = Figures.Bishop(side, cur_pos) elif figure_type == FigureType.PAWN: was_moved = True if side == Side.WHITE: if i == GameBoard.default_white_pawn_row: was_moved = False elif side == Side.BLACK: if i == GameBoard.default_black_pawn_row: was_moved = False self.board[j][i] = Figures.Pawn(side, cur_pos, was_moved) else: continue def serialize_to_str(self): str_board = ['.' for j in range(0, Board.ROW_SIZE) for i in range(0, Board.COLUMN_SIZE)] for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): if self.board[j][i] is None: continue str_board[i * Board.ROW_SIZE + j] = self.board[j][i].serialized_letter() res = "" for i in range(0, Board.COLUMN_SIZE * Board.ROW_SIZE): res += str_board[i] return res def deserialize_from_str(self, board_as_str): self.board = [[None for j in range(0, Board.ROW_SIZE)] for i in range(0, Board.COLUMN_SIZE)] str_board = ['.' for j in range(0, Board.ROW_SIZE) for i in range(0, Board.COLUMN_SIZE)] for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): str_board[i * Board.ROW_SIZE + j] = str(board_as_str).__getitem__(i * Board.ROW_SIZE + j) for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): letter = str_board[i * Board.ROW_SIZE + j] if letter.isupper(): side = Side.WHITE else: side = Side.BLACK letter = letter.lower() cur_pos = Vector2d(j, i) if letter == 'k': self.board[j][i] = Figures.King(side, cur_pos, False) elif letter == 'i': self.board[j][i] = Figures.King(side, cur_pos, True) elif letter == 'b': self.board[j][i] = Figures.Bishop(side, cur_pos) elif letter == 'r': self.board[j][i] = Figures.Rook(side, cur_pos, False) elif letter == 'o': self.board[j][i] = Figures.Rook(side, cur_pos, True) elif letter == 'n': self.board[j][i] = Figures.Knight(side, cur_pos) elif letter == 'q': self.board[j][i] = Figures.Queen(side, cur_pos) elif letter == 'p': self.board[j][i] = Figures.Pawn(side, cur_pos) elif letter == 'a': self.board[j][i] = Figures.Pawn(side, cur_pos, True) elif letter == 'w': self.board[j][i] = Figures.Pawn(side, cur_pos, False, True) def export_chess_board(self): export_board = ['.' for j in range(0, Board.ROW_SIZE) for i in range(0, Board.COLUMN_SIZE)] for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): if self.board[j][i] is None: continue figure_type = self.board[j][i].figure_type side = self.board[j][i].side if figure_type == FigureType.KING: latter = 'k' elif figure_type == FigureType.QUEEN: latter = 'q' elif figure_type == FigureType.ROOK: latter = 'r' elif figure_type == FigureType.KNIGHT: latter = 'n' elif figure_type == FigureType.BISHOP: latter = 'b' elif figure_type == FigureType.PAWN: latter = 'p' if side == Side.WHITE: latter = latter.upper() export_board[i * Board.ROW_SIZE + j] = latter return export_board def print(self): sys.stdout.write(" ") sys.stdout.write(" ") sys.stdout.write(" ") for i in range(0, Board.ROW_SIZE): sys.stdout.write(i.__str__()) sys.stdout.write(" ") print() print() for i in range(0, Board.COLUMN_SIZE): sys.stdout.write(i.__str__()) sys.stdout.write(" ") sys.stdout.write(" ") for j in range(0, Board.ROW_SIZE): if self.board[j][i] is not None: self.board[j][i].print() sys.stdout.write(" ") else: sys.stdout.write("*") sys.stdout.write(" ") print() def print_attacked_cells(self): for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): if self.board[j][i] is not None: attack_cells = self.board[j][i].generate_moves(self) self.board[j][i].print() sys.stdout.write(": ") for k in range(len(attack_cells)): sys.stdout.write(attack_cells[k].x.__str__()) sys.stdout.write(" ") sys.stdout.write(attack_cells[k].y.__str__()) sys.stdout.write("; ") print() def get_by_pos(self, x, y): return self.board[x][y] def get(self, position): return self.board[position.x][position.y] def set(self, position, game_object): self.board[position.x][position.y] = game_object def get_king_cell(self, side): for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): if self.board[j][i] is not None: if isinstance(self.board[j][i], Figures.King) and self.board[j][i].side == side: return Vector2d(j, i) def get_figures_list(self, side): figures = [] for i in range(0, Board.COLUMN_SIZE): for j in range(0, Board.ROW_SIZE): if self.board[j][i] is not None: if self.board[j][i].side == side: figures.append(self.board[j][i]) return figures def make_move(self, move): self.get(move.point_from).make_move(self, move.point_to) def summary_attacked_cells(self, side): attacked_cells = [] for j in range(Board.ROW_SIZE): for i in range(Board.COLUMN_SIZE): figure = self.get_by_pos(j, i) if figure is not None and figure.side == side: if isinstance(figure, Figures.King): attacked_cells = attacked_cells + figure.generate_moves(self, False) elif isinstance(figure, Figures.Pawn): attacked_cells = attacked_cells + figure.generate_moves(self, True) else: attacked_cells = attacked_cells + figure.generate_moves(self) return attacked_cells def summary_moves(self, side, my_turn=True): summary_moves = [] attacked_cells = [] for j in range(Board.ROW_SIZE): for i in range(Board.COLUMN_SIZE): attacked_cells.clear() figure = self.get_by_pos(j, i) if figure is not None and figure.side == side: if isinstance(figure, Figures.King): attacked_cells = attacked_cells + figure.generate_moves(self, my_turn) else: attacked_cells = attacked_cells + figure.generate_moves(self) for k in range(len(attacked_cells)): summary_moves.append(Move(Vector2d(j, i), attacked_cells[k])) return summary_moves def is_that_check(self, my_side): attacked_cells = self.summary_attacked_cells(my_side) enemy_king_cell = self.get_king_cell(Side.get_oposite(my_side)) return enemy_king_cell in attacked_cells def is_that_mate(self, my_side): enemy_figures = self.get_figures_list(Side.get_oposite(my_side)) for i in range(len(enemy_figures)): cur_figure = enemy_figures[i] available_moves = cur_figure.generate_moves(self) for j in range(len(available_moves)): new_chess_board = copy.deepcopy(self) if new_chess_board.get(cur_figure.position) is None: print(cur_figure.position.x) print(cur_figure.position.y) new_chess_board.make_move(Move(cur_figure.position, available_moves[j])) if new_chess_board.is_that_check(my_side) is False: return False return True def is_that_stalemate(self, my_side): enemy_figures = self.get_figures_list(Side.get_oposite(my_side)) for i in range(len(enemy_figures)): cur_figure = enemy_figures[i] if isinstance(cur_figure, Figures.King) is not True: available_moves = cur_figure.generate_moves(self) if len(available_moves) != 0: return False else: available_moves = cur_figure.generate_moves(self) for j in range(len(available_moves)): new_chess_board = copy.deepcopy(self) if new_chess_board.get(cur_figure.position) is None: print(cur_figure.position.x) print(cur_figure.position.y) new_chess_board.make_move(Move(cur_figure.position, available_moves[j])) if new_chess_board.is_that_check(my_side) is False: return False return True def evaluate(self, side): total = 0 for j in range(Board.ROW_SIZE): for i in range(Board.COLUMN_SIZE): pos = Vector2d(j, i) figure = self.get(pos) if figure is not None: if figure.side is side: sign = 1 else: sign = -1 total = total + (figure.evaluate(j, i) * sign) return total def delete_double_move(self, side_to_del): for j in range(Board.ROW_SIZE): for i in range(Board.COLUMN_SIZE): figure = self.get_by_pos(j, i) if figure is not None and figure.side == side_to_del: if isinstance(figure, Figures.Pawn): figure.double_move = False def swap_pawn(self, position, figure_lat): side = self.board[position.x][position.y].side lower = figure_lat.lower() if lower == 'q': self.board[position.x][position.y] = Figures.Queen(side, position) if lower == 'b': self.board[position.x][position.y] = Figures.Bishop(side, position) if lower == 'n': self.board[position.x][position.y] = Figures.Knight(side, position) if lower == 'r': self.board[position.x][position.y] = Figures.Rook(side, position, True)