from constant import rows, cols class Stan: def __init__(self, row, col, direction): self.p = [] self.a = "" self.row = row self.col = col self.direction = direction def __str__(self): return f"row: {self.row}, col: {self.col}, direction: {self.direction}" def parrent(self, stan, action): if len(self.p) == 0: self.p.append(stan) self.a = action def succ(self, action, board): move_offsets = { "up": {"up": (-1, 0), "left": (0, -1), "down": (1, 0), "right": (0, 1)}, "left": {"up": "left", "left": "down", "down": "right", "right": "up"}, "right": {"up": "right", "right": "down", "down": "left", "left": "up"} } if action == "up": row_offset, col_offset = move_offsets[action][self.direction] new_row = self.row + row_offset new_col = self.col + col_offset if 0 <= new_row < rows and 0 <= new_col < cols and not board.is_rock(new_row, new_col): return Stan(new_row, new_col, self.direction) elif action in ["left", "right"]: new_direction = move_offsets[action][self.direction] return Stan(self.row, self.col, new_direction) return None class Odwiedzone: def __init__(self): self.stany = [] def check(self, stan): for i in self.stany: if(stan.direction == i.direction and stan.col == i.col and stan.row == i.row): return True return False def dodaj_stan(self, stan): self.stany.append(stan)