def __init__(self, position, color, image): super().__init__(position, color, image) # list that holds the steps pawn could take to move as an instance of class Position self.__move_steps = [Position(0, 1), Position(0, 2)] # list that holds the steps pawn could take to kill enemy if possible as an instance of class position self.__kill_steps = [Position(-1, 1), Position(1, 1)] self.__first_move = True
def __init__(self, position, color, image): super().__init__(position, color, image) # list that holds the steps pawn could take to move as an instance of class Position self.__move_steps = [ Position(1, 0), Position(-1, 0), Position(0, 1), Position(0, -1) ]
def calculate_moves(self, white: dict, black: dict): moves, enemies = [], [] for move in self.__move_steps: temp = Position(0, 0, None) for i in range(1, 9): temp += move possible_move = (temp + self.position).tuple if 0 < possible_move[0] < 9 and 0 < possible_move[1] < 9: if possible_move in white and self.color == "white" or possible_move in black and self.color == "black": break if possible_move in white and self.color == "black" or possible_move in black and self.color == "white": enemies.append(possible_move) break if possible_move not in white and possible_move not in black: moves.append(possible_move) else: break return moves, enemies
def __initialize_board(self): for i in range(1, 9): for j in range(1, 9): self.__tuples_to_positions[(i, j)] = Position(i, j, "images/square1.png") if (i + j) % 2 == 0 \ else Position(i, j, "images/square2.png") self.__tuples_to_rectangles[(i, j)] = self.__tuples_to_positions[(i, j)].rect