graphserach v0.6.2
This commit is contained in:
parent
5bfca831f2
commit
d9597d3e26
43
FindPath.py
43
FindPath.py
@ -1,4 +1,18 @@
|
|||||||
from constants import *
|
from constants import *
|
||||||
|
from queue import Queue
|
||||||
|
|
||||||
|
|
||||||
|
class Node:
|
||||||
|
def __init__(self, parent: (int, int), index: (int, int)):
|
||||||
|
self.__index = index
|
||||||
|
self.__parent = parent
|
||||||
|
|
||||||
|
def get_index(self):
|
||||||
|
return self.__index
|
||||||
|
|
||||||
|
def get_parent(self):
|
||||||
|
return self.__parent
|
||||||
|
|
||||||
|
|
||||||
def whichStateLookingFor(tractor, TillageUnit):
|
def whichStateLookingFor(tractor, TillageUnit):
|
||||||
searching_field = "toPlow"
|
searching_field = "toPlow"
|
||||||
@ -25,10 +39,9 @@ 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):
|
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
|
||||||
start_state = (start_horizontal_index, start_vertical_index)
|
start_state = (start_horizontal_index, start_vertical_index)
|
||||||
@ -36,3 +49,29 @@ def graphsearch(tractor, board, TillageUnit):
|
|||||||
print(start_state)
|
print(start_state)
|
||||||
print(end_state)
|
print(end_state)
|
||||||
|
|
||||||
|
fringe.put(start_state)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if fringe.empty():
|
||||||
|
return False
|
||||||
|
|
||||||
|
elem = fringe.get()
|
||||||
|
|
||||||
|
if goaltest(elem, end_state):
|
||||||
|
#TODO
|
||||||
|
return #droga ktora musi pokonac traktor
|
||||||
|
|
||||||
|
explored.append(elem)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def goaltest(elem, end_state):
|
||||||
|
if elem == end_state:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def succ():
|
||||||
|
#TODO
|
||||||
|
return
|
3
main.py
3
main.py
@ -9,6 +9,7 @@ from TractorLoad import TillageUnit
|
|||||||
from animations import animationsOn, animationsOff
|
from animations import animationsOn, animationsOff
|
||||||
from constants import *
|
from constants import *
|
||||||
from manualSteering import manualSteeringDriver
|
from manualSteering import manualSteeringDriver
|
||||||
|
from queue import Queue
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ while working:
|
|||||||
|
|
||||||
clock.tick(FPS)
|
clock.tick(FPS)
|
||||||
|
|
||||||
graphsearch(tractor, board, TillageUnit)
|
graphsearch(tractor, board, TillageUnit, Queue(), list())
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
quit()
|
quit()
|
||||||
|
Loading…
Reference in New Issue
Block a user