Funkcja zwracajaca mozliwe ruchy

This commit is contained in:
s1202077 2019-04-10 11:01:20 +02:00
parent 3ce89a6f2d
commit 5257a3ec30
4 changed files with 31 additions and 4 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ env
**/__pycache__
.vscode
*.swp
linux_env

View File

@ -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
View File

@ -0,0 +1,2 @@
def DFS(grid, avaliable_movement, starting_point):
x, y = starting_point

3
main.py Normal file → Executable file
View File

@ -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