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__
|
**/__pycache__
|
||||||
.vscode
|
.vscode
|
||||||
*.swp
|
*.swp
|
||||||
|
linux_env
|
||||||
|
@ -9,17 +9,40 @@ class GC(Cell):
|
|||||||
def __init__(self, x, y, max_rubbish, yellow=0, green=0, blue=0):
|
def __init__(self, x, y, max_rubbish, yellow=0, green=0, blue=0):
|
||||||
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue)
|
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue)
|
||||||
|
|
||||||
def move(self, direction, environment):
|
def movement(self, environment, x = None ,y = None):
|
||||||
x, y = [self.x, self.y]
|
if((x,y) == (None, None)):
|
||||||
|
x = self.x
|
||||||
|
y = self.y
|
||||||
|
|
||||||
movement = {
|
movement = {
|
||||||
"right": (x + 1, y) if x + 1 < GRID_WIDTH and type(environment[x + 1][y]) == Road else (x, y),
|
"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),
|
"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),
|
"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)
|
"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)
|
self.update_rect(self.x, self.y)
|
||||||
|
|
||||||
|
print(self.check_moves(direction, environment))
|
||||||
|
|
||||||
def collect(self, enviromnent):
|
def collect(self, enviromnent):
|
||||||
x, y = [self.x, self.y]
|
x, y = [self.x, self.y]
|
||||||
coordinates = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, 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
|
3
main.py
Normal file → Executable file
3
main.py
Normal file → Executable file
@ -1,6 +1,7 @@
|
|||||||
|
#!linux_env/bin/python3
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from random import randint
|
from random import randint
|
||||||
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y
|
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user