a* update, showing path to target

This commit is contained in:
Juundi 2022-04-29 04:34:44 +02:00
parent 80aa2995ff
commit ee2e1180af
10 changed files with 91 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

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

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/SI-projekt-smieciarka2.iml" filepath="$PROJECT_DIR$/.idea/SI-projekt-smieciarka2.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

BIN
hole.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
house.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
junkyard.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

51
src/astar.py Normal file
View File

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