diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/SI-projekt-smieciarka2.iml b/.idea/SI-projekt-smieciarka2.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/SI-projekt-smieciarka2.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d56657a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..085e946 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/hole.png b/hole.png new file mode 100644 index 0000000..461d79e Binary files /dev/null and b/hole.png differ diff --git a/house.png b/house.png new file mode 100644 index 0000000..9d5f021 Binary files /dev/null and b/house.png differ diff --git a/junkyard.png b/junkyard.png new file mode 100644 index 0000000..785706d Binary files /dev/null and b/junkyard.png differ diff --git a/src/astar.py b/src/astar.py new file mode 100644 index 0000000..b50b2e2 --- /dev/null +++ b/src/astar.py @@ -0,0 +1,51 @@ +from queue import PriorityQueue + +def heuristic(xy1, xy2): + return abs(xy1[0] - xy2[0]) + abs(xy1[1] - xy2[1]) + +def neighbours(point): + x, y = point + list=((x+1,y), (x,y+1), (x,y-1), (x-1,y)) + return list + +#determining the cost of a specific field in the grid +def checkCost(grid, xy): + x, y = xy + cost = grid[x][y] + return cost + +def aStar(grid, start, goal): + openlist = PriorityQueue() + openlist.put(start, 0) + + fScore = {} + origin = {start: None} + fScore[start] = 0 + closedlist=[] + + while openlist!= {} : + current = openlist.get() + + if current == goal: + path = [] + #following from the succesors to the root our starting point + while current != start: + path.append(current) + current = origin[current] + path.reverse() + break + + # successor function + for succ in neighbours(current): + #checking if didn't go out of the maze + if(succ[0] < 0 or succ[1] < 0 or succ[0] > 14 or succ[1] > 14): + continue + + gScore = fScore[current[0],current[1]] + checkCost(grid, current) + if succ not in closedlist or gScore < fScore[succ[0],succ[1]]: + closedlist.append(succ) + origin[succ[0],succ[1]] = current + fScore[succ[0],succ[1]] = gScore + priority = gScore + heuristic(goal, succ) + openlist.put(succ, priority) + return path \ No newline at end of file