From 4e18cd852bdd8b7c886b7df56ea6e9677b067c69 Mon Sep 17 00:00:00 2001 From: Michal Kijowski Date: Tue, 28 Apr 2020 10:18:15 +0000 Subject: [PATCH] Upload files to '' --- AStar.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ AStarState.py | 12 ++++++++ Evencik.py | 4 +++ box.py | 5 ++++ boxOnTheFloor.py | 16 +++++++++++ 5 files changed, 109 insertions(+) create mode 100644 AStar.py create mode 100644 AStarState.py create mode 100644 Evencik.py create mode 100644 box.py create mode 100644 boxOnTheFloor.py diff --git a/AStar.py b/AStar.py new file mode 100644 index 0000000..13407c0 --- /dev/null +++ b/AStar.py @@ -0,0 +1,72 @@ +import numpy +from AStarState import AStarState + +class AStar: + def returnPath(self, currentNode, grid): + path = [] + noRows, noColumns = numpy.shape(grid) + result = [[-1 for i in range(noColumns)] for j in range(noRows)] + current = currentNode + while current is not None: + path.append(current.position) + current = current.parent + path = path[::-1] + startValue = 0 + for i in range(len(path)): + result[path[i][0]][path[i][1]] = startValue + startValue+=1 + return result + + def search(self, start, end, grid, cost): + noRows, noColumns = numpy.shape(grid) + startNode = AStarState(None, tuple(start)) + endNode = AStarState(None, tuple(end)) + startNode.g = 0 + startNode.h = 0 + startNode.f = 0 + endNode.g = 0 + endNode.h = 0 + endNode.f = 0 + toVisit = [] + visited = [] + toVisit.append(startNode) + iterations = 0 + max = (len(grid) // 2) ** 10 + moves = [[-1, 0], [1, 0], [0, 1], [0, -1]] + while len(toVisit)>0: + iterations=iterations+1 + current = toVisit[0] + currentIndeks = 0 + for indeks, item in enumerate(toVisit): + if item.gmax: + return self.returnPath(current, grid) + visited.append(current) + toVisit.pop(currentIndeks) + if current==endNode: + return self.returnPath(current, grid) + children = [] + for new in moves: + positions = (current.position[0]+new[0], current.position[1]+new[1]) + if (positions[0] > (noRows - 1) or + positions[0] < 0 or + positions[1] > (noColumns - 1) or + positions[1] < 0): + continue + if grid[positions[0]][positions[1]]!=0: + continue + children.append(AStarState(current, positions)) + for child in children: + if len([visitedChild for visitedChild in visited if visitedChild==child])>0: + continue + if child.position[0]<=(len(grid)-4) and child.position[0]>=3 and child.position[1]>=4 and child.position[1]<=(len(grid[0])-1): + child.g = current.g + (10 * cost) + else: + child.g = current.g + cost + child.h = (((child.position[0]-endNode.position[0]) ** 2) + ((child.position[1]-endNode.position[1]) ** 2)) + child.f = child.g + child.h + if len([i for i in toVisit if child==i and child.g>i.g])>0: + continue + toVisit.append(child) diff --git a/AStarState.py b/AStarState.py new file mode 100644 index 0000000..fc16648 --- /dev/null +++ b/AStarState.py @@ -0,0 +1,12 @@ + +class AStarState: + def __init__(self, parent, position): + self.parent = parent + self.position = position + self.g = 0 + self.h = 0 + self.f = 0 + def __eq__(self, other): + return self.position == other.position + def show(self): + return str("{("+str(self.position[0])+", "+str(self.position[1])+") "+str(self.g)+"}") \ No newline at end of file diff --git a/Evencik.py b/Evencik.py new file mode 100644 index 0000000..155bf83 --- /dev/null +++ b/Evencik.py @@ -0,0 +1,4 @@ + +class Evencik: + def __init__(self, key): + self.key = key \ No newline at end of file diff --git a/box.py b/box.py new file mode 100644 index 0000000..91f4d6a --- /dev/null +++ b/box.py @@ -0,0 +1,5 @@ +import pygame + +class Box: + def __init__(self): + self.nazwa = "Nazwa" \ No newline at end of file diff --git a/boxOnTheFloor.py b/boxOnTheFloor.py new file mode 100644 index 0000000..76ca9b2 --- /dev/null +++ b/boxOnTheFloor.py @@ -0,0 +1,16 @@ +import pygame + +class BoxOnTheFloor: + def __init__(self, screen, cell, we, ns, box): + self.cell = cell + self.ns = ns + self.occupied = True + self.box = box + self.we = we + self.screen = screen + self.image = pygame.image.load(r'images/pa.png') + self.image = pygame.transform.scale(self.image, (cell, cell)) + def get(self): + return self.box + def draw(self): + self.screen.blit(self.image, (self.cell*self.ns, self.cell*self.we)) \ No newline at end of file