from constant import width, height, rows, cols class Stan: def __init__(self, row, col, dir): self.p = [] self.a = "" self.row = row self.col = col self.direction = dir 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): if(action == "up"): if(self.direction == "left"): if not board.is_rock(max(self.col - 1, 0), self.row): return Stan( self.row , max(self.col - 1, 0), self.direction) return Stan(self.row, self.col, self.direction) if(self.direction == "up"): if not board.is_rock(self.col, max(self.row - 1, 0)): return Stan(max(self.row - 1,0) , self.col, self.direction) return Stan(self.row, self.col, self.direction) if(self.direction == "right"): if not board.is_rock(min(self.col + 1, cols - 1), self.row): return Stan(self.row, min(self.col + 1, cols - 1) , self.direction) return Stan(self.row, self.col, self.direction) if(self.direction == "down"): if not board.is_rock(self.col, min(self.row + 1,rows - 1 )): return Stan(min(self.row + 1,rows - 1 ) , self.col, self.direction) return Stan(self.row, self.col, self.direction) if(action == "left"): if(self.direction == "left"): return Stan(self.row , self.col, "down") if(self.direction == "up"): return Stan(self.row, self.col, "left") if(self.direction == "right"): return Stan(self.row, self.col, "up") if(self.direction == "down"): return Stan(self.row, self.col , "right") if(action == "right"): if(self.direction == "left"): return Stan(self.row, self.col, "up") if(self.direction == "up"): return Stan(self.row, self.col, "right") if(self.direction == "right"): return Stan(self.row, self.col, "down") if(self.direction == "down"): return Stan(self.row, self.col,"left") class Kolejka: def __init__(self): self.id = 0 self.len = 0 self.stany = [] def dodaj_stan(self, stan): self.stany.append(stan) self.len += 1 def usun_stan(self): if not self.czy_pusta(): self.id += 1 return self.stany[self.id - 1] else: raise IndexError("Kolejka stanów jest pusta") def czy_pusta(self): return self.len <= self.id def check(self, stan): indeks = 0 for i in self.stany: if(stan.direction == i.direction and stan.col == i.col and stan.row == i.row): return True return False 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)