graphserach v0.6.4

This commit is contained in:
Łukasz 2021-04-14 14:34:57 +02:00
parent d45ec38792
commit 1bdef8cc56
4 changed files with 29 additions and 19 deletions

View File

@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.8 (AI_Tractor)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

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

View File

@ -28,6 +28,7 @@ def whichStateLookingFor(tractor, TillageUnit):
searching_field = "toFertilize"
return searching_field
def nearestLookingField(board, tractor, TillageUnit):
end_horizontal_index = 0
end_vertical_index = 0
@ -39,8 +40,10 @@ def nearestLookingField(board, tractor, TillageUnit):
end_horizontal_index = field.horizontal_index
end_vertical_index = field.vertical_index
break
return end_horizontal_index, end_vertical_index
def graphsearch(tractor, board, TillageUnit, fringe: Queue, explored):
start_horizontal_index = tractor.horizontal_index
start_vertical_index = tractor.vertical_index
@ -59,8 +62,8 @@ def graphsearch(tractor, board, TillageUnit, fringe: Queue, explored):
if goaltest(elem, end_state):
break
#TODO
#return droga ktora musi pokonac traktor
# TODO
# return droga ktora musi pokonac traktor
else:
explored.append(elem)
elem = succ(start_state, end_state, tractor)
@ -68,36 +71,43 @@ def graphsearch(tractor, board, TillageUnit, fringe: Queue, explored):
def goaltest(elem, end_state):
print('element: ',elem,' stan koncowy; ', end_state)
if elem == end_state:
print("heeee")
return True
else:
return False
def succ(start_state, end_state, tractor):
print(tractor.horizontal_index, ' ', tractor.vertical_index)
a = input()
if start_state[1] < end_state[1]:
if tractor.direction == "RIGHT":
tractor.drive()
print("przesunalem sie w prawo")
else:
tractor.direction = "RIGHT"
print("przesunalem sie w prawo")
elif start_state[1] > end_state[1]:
if tractor.direction == "LEFT":
tractor.drive()
else:
tractor.direction = "LEFT"
print("przesunalem sie w lewo")
else:
if start_state[0] < end_state[0]:
tractor.direction = "LEFT"
elif start_state[0] < end_state[0]:
if tractor.direction == "DOWN":
tractor.drive()
print("przesunalem sie w dol")
else:
tractor.direction = "DOWN"
print("przesunalem sie w dol")
elif start_state[0] > end_state[0]:
if tractor.direction == "UP":
tractor.drive()
else:
tractor.direction = "UP"
print("przesunalem sie w gore")
else:
tractor.direction = "UP"
else:
return tractor.horizontal_index, tractor.horizontal_index

View File

@ -59,7 +59,7 @@ while working:
clock.tick(FPS)
graphsearch(tractor, board, TillageUnit, Queue(), list())
graphsearch(tractor, board, TillageUnit, Queue(), list())
pygame.quit()
quit()