Funkcja zwracajaca mozliwe ruchy
This commit is contained in:
parent
3ce89a6f2d
commit
5257a3ec30
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ env
|
||||
**/__pycache__
|
||||
.vscode
|
||||
*.swp
|
||||
linux_env
|
||||
|
@ -9,17 +9,40 @@ class GC(Cell):
|
||||
def __init__(self, x, y, max_rubbish, yellow=0, green=0, blue=0):
|
||||
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue)
|
||||
|
||||
def move(self, direction, environment):
|
||||
x, y = [self.x, self.y]
|
||||
def movement(self, environment, x = None ,y = None):
|
||||
if((x,y) == (None, None)):
|
||||
x = self.x
|
||||
y = self.y
|
||||
|
||||
movement = {
|
||||
"right": (x + 1, y) if x + 1 < GRID_WIDTH and type(environment[x + 1][y]) == Road else (x, y),
|
||||
"left": (x - 1, y) if x - 1 >= 0 and type(environment[x - 1][y]) == Road else (x, y),
|
||||
"down": (x, y + 1) if y + 1 < GRID_HEIGHT and type(environment[x][y + 1]) == Road else (x, y),
|
||||
"up": (x, y - 1) if y - 1 >= 0 and type(environment[x][y - 1]) == Road else (x, y)
|
||||
}
|
||||
self.x, self.y = movement[direction]
|
||||
|
||||
forbidden_movement = {
|
||||
"right": "left",
|
||||
"left": "right",
|
||||
"up": "down",
|
||||
"down": "up"
|
||||
}
|
||||
|
||||
return (movement, forbidden_movement)
|
||||
|
||||
def check_moves(self, direction, environment, x = None, y = None):
|
||||
if((x,y) == (None, None)):
|
||||
x = self.x
|
||||
y = self.y
|
||||
|
||||
return ([dir for dir in self.movement(environment)[0] if self.movement(environment)[0][dir] != (x,y) and dir != self.movement(environment)[1][direction]])
|
||||
|
||||
def move(self, direction, environment):
|
||||
self.x, self.y = self.movement(environment)[0][direction]
|
||||
self.update_rect(self.x, self.y)
|
||||
|
||||
print(self.check_moves(direction, environment))
|
||||
|
||||
def collect(self, enviromnent):
|
||||
x, y = [self.x, self.y]
|
||||
coordinates = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]
|
||||
|
2
Traversal/DFS.py
Normal file
2
Traversal/DFS.py
Normal file
@ -0,0 +1,2 @@
|
||||
def DFS(grid, avaliable_movement, starting_point):
|
||||
x, y = starting_point
|
Loading…
Reference in New Issue
Block a user