def generate_moves(self): tuples = [(1, 0), (-1, 0), (0, 1), (0, -1), (-1, 1), (-1, -1), (1, 1), (1, -1)] moves = [] for i in tuples: newpos = add(self.game_pos, i) if self.board.check_bounds(newpos): if self.board.get_square(newpos).has_piece: if self.can_capture(newpos): moves.append(newpos) else: moves.append(newpos) tuples = [] for key, value in self.bonuses.items(): if value is True: tuples += key.tuples for i in tuples: i = add(self.game_pos, i) if self.board.check_bounds(i): if self.board.get_square(i).has_piece and i != self.game_pos: if self.can_capture_(i): moves.append(i) else: moves.append(i) # for i in moves: # if self.check_if_check(i): # moves.remove(i) return moves
def simulate_capture(self, newpos: tuple): movement = -1 if self.color else 1 temp = [ add(self.game_pos, (1, movement)), add(self.game_pos, (-1, movement)) ] return temp
def smolFunction(self, x, y): for i in range(1, self.board.size): newpos = add(self.game_pos, (i * x, i * y)) if self.board.check_bounds(newpos): if self.board.get_square( newpos).has_piece and newpos != self.game_pos: if self.can_capture(newpos): self.moves.append(newpos) break self.moves.append(newpos)
def generate_moves(self): moves = [] movement = -1 if self.color else 1 if not self.has_moved: if self.color: moves.append(add(self.game_pos, (0, -2))) else: moves.append(add(self.game_pos, (0, 2))) newpos = add(self.game_pos, (0, movement)) if self.board.check_bounds( newpos) and not self.board.get_square(newpos).has_piece: moves.append(newpos) newpos = add(self.game_pos, (1, movement)) if self.board.check_bounds(newpos) and self.can_capture(newpos): moves.append(newpos) newpos = add(self.game_pos, (-1, movement)) if self.board.check_bounds(newpos) and self.can_capture(newpos): moves.append(newpos) return moves
def generate_moves(self): self.moves = [] self.smolFunction(0, 1) self.smolFunction(0, -1) self.smolFunction(1, 0) self.smolFunction(-1, 0) tuples = [] for key, value in self.bonuses.items(): if value is True: tuples += key.tuples for i in tuples: i = add(self.game_pos, i) if self.board.check_bounds(i): if self.board.get_square(i).has_piece and i != self.game_pos: if self.can_capture_(i): self.moves.append(i) else: self.moves.append(i) return self.moves
def generate_moves(self): moves = [] # up right for i in range(1, self.board.size): newpos = add(self.game_pos, (i, i)) if self.board.check_bounds(newpos): if self.board.get_square( newpos).has_piece and newpos != self.pos: if self.can_capture(newpos): moves.append(newpos) break moves.append(newpos) for i in range(1, self.board.size): newpos = add(self.game_pos, (i, -i)) if self.board.check_bounds(newpos): if self.board.get_square( newpos).has_piece and newpos != self.pos: if self.can_capture(newpos): moves.append(newpos) break moves.append(newpos) for i in range(1, self.board.size): newpos = add(self.game_pos, (-i, i)) if self.board.check_bounds(newpos): if self.board.get_square( newpos).has_piece and newpos != self.pos: if self.can_capture(newpos): moves.append(newpos) break moves.append(newpos) for i in range(1, self.board.size): newpos = add(self.game_pos, (-i, -i)) if self.board.check_bounds(newpos): if self.board.get_square( newpos).has_piece and newpos != self.pos: if self.can_capture(newpos): moves.append(newpos) break moves.append(newpos) for i in range(self.game_pos[1], self.board.size, 1): newpos = add(self.game_pos, (0, i)) if self.board.check_bounds(newpos): if self.board.get_square( newpos).has_piece and newpos != self.pos: if self.can_capture(newpos): moves.append(newpos) break moves.append(newpos) # down for i in range(self.game_pos[1], self.board.size, 1): newpos = self.game_pos[0], i if self.board.check_bounds(newpos): if newpos != self.game_pos: if self.board.get_square(newpos).has_piece: if self.can_capture(newpos): moves.append(newpos) break moves.append(newpos) # up for i in range(self.game_pos[1], -1, -1): newpos = self.game_pos[0], i if self.board.check_bounds(newpos): if newpos != self.game_pos: if self.board.get_square(newpos).has_piece: if self.can_capture(newpos): moves.append(newpos) break moves.append(newpos) # right for i in range(self.game_pos[0], self.board.size, 1): newpos = i, self.game_pos[1] if self.board.check_bounds(newpos): if newpos != self.game_pos: if self.board.get_square(newpos).has_piece: if self.can_capture(newpos): moves.append(newpos) break moves.append(newpos) # left for i in range(self.game_pos[0], -1, -1): newpos = i, self.game_pos[1] if self.board.check_bounds(newpos): if newpos != self.game_pos: if self.board.get_square(newpos).has_piece: if self.can_capture(newpos): moves.append(newpos) break moves.append(newpos) tuples = [] for key, value in self.bonuses.items(): if value is True: tuples += key.tuples for i in tuples: i = add(self.game_pos, i) if self.board.check_bounds(i): if self.board.get_square(i).has_piece and i != self.game_pos: if self.can_capture_(i): moves.append(i) else: moves.append(i) return moves