diff --git a/.gitignore b/.gitignore index f6fa1a7..169ffb9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ env **/__pycache__ .vscode *.swp +linux_env diff --git a/DataModels/GC.py b/DataModels/GC.py index 546ed41..cbd22e0 100644 --- a/DataModels/GC.py +++ b/DataModels/GC.py @@ -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)] diff --git a/Traversal/DFS.py b/Traversal/DFS.py new file mode 100644 index 0000000..252fc73 --- /dev/null +++ b/Traversal/DFS.py @@ -0,0 +1,2 @@ +def DFS(grid, avaliable_movement, starting_point): + x, y = starting_point \ No newline at end of file diff --git a/main.py b/main.py old mode 100644 new mode 100755 index ca26f9b..3d157ce --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ +#!linux_env/bin/python3 + import pygame import sys - from random import randint from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y