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"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <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" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <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> </project>

View File

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

View File

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