1
0
forked from s444417/ProjektAI

Merge branch 'master' of https://git.wmi.amu.edu.pl/s444417/ProjektAI into mikolaj_branch

 Conflicts:
	.idea/ProjektAI.iml
	.idea/misc.xml
	kelner/src/managers/WaiterManager.py
This commit is contained in:
s444417 2020-04-27 12:33:50 +02:00
commit aa3fb8c414
3 changed files with 55 additions and 0 deletions

3
.gitignore vendored
View File

@ -30,6 +30,7 @@ share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
.idea
/idea/workspace.xml
MANIFEST
@ -56,6 +57,8 @@ coverage.xml
*.cover
.hypothesis/
.pytest_cache/
.idea
.idea/*
# Translations
*.mo

View File

@ -0,0 +1,49 @@
import queue
class BFS:
def __init__(self, grid):
self.grid = grid
self.visited = []
def get_neighbors(self, node, grid):
dr = [-1, +1, 0, 0]
dc = [0, 0, +1, -1]
x = node[0]
y = node[1]
node = (x, y)
neighbors = []
for i in range(4):
new_col = x + dc[i]
new_row = y + dr[i]
node = (new_col, new_row)
if 0 <= new_row < len(grid) and 0 <= new_col < len(grid[0]):
if (new_col, new_row) not in self.visited:
if grid[new_row][new_col] != 1:
neighbors.append((new_col, new_row))
return neighbors
def find_path(self, start, end):
grid = self.grid
queue = [(start, [])]
while len(queue) > 0:
node, path = queue.pop(0)
path.append(node)
self.visited.append(node)
if node == end:
if len(path) > 1:
path.pop(0)
return path
adj_nodes = self.get_neighbors(node, grid)
for item in adj_nodes:
if item not in self.visited:
queue.append((item, path[:]))
return None

View File

@ -3,6 +3,7 @@ import time
import sys
from kelner.src.components.Table import Status
from kelner.src.algorithms.AStar.Finder import Finder
from kelner.src.algorithms.BFS.BFS import BFS
# creates new thread
@ -21,11 +22,13 @@ class WaiterManager (threading.Thread):
if tables:
reservedPlaces = self.__drawableManager.getReservedPlaces(waiter)
finder = Finder(reservedPlaces)
# bfs = BFS(reservedPlaces)
origin = (waiter.getX(), waiter.getY())
for table in tables:
targets = finder.getNeighbours((table.getX(), table.getY()), False)
for target in targets:
if target is not None:
# path = bfs.find_path(origin, target)
path = finder.getPath(origin, target, True)
if path:
result = len(path)