- A* działa
- Wyszukiwanie zmienione na tree search - Do poprawki to żeby było widać ktoki traktora(na razie widać tylko w konsoli)
This commit is contained in:
parent
34039542bd
commit
3375a8adca
@ -56,7 +56,7 @@ class activities:
|
|||||||
|
|
||||||
def activity_val(self,value):
|
def activity_val(self,value):
|
||||||
self.mode = value
|
self.mode = value
|
||||||
print(self.mode)
|
print("Tryb: "+ str(self.modes[self.mode]))
|
||||||
|
|
||||||
def activity_get_value(self):
|
def activity_get_value(self):
|
||||||
return self.mode
|
return self.mode
|
||||||
|
37
functions.py
37
functions.py
@ -10,18 +10,6 @@ def quit():
|
|||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
class Node():
|
|
||||||
def __init__(self, parent=None, position=None):
|
|
||||||
self.parent = parent
|
|
||||||
self.position = position
|
|
||||||
|
|
||||||
self.g = 0
|
|
||||||
self.h = 0
|
|
||||||
self.f = 0
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
return self.position == other.position
|
|
||||||
|
|
||||||
def pressed(key, traktor_poz):
|
def pressed(key, traktor_poz):
|
||||||
if key[K_d]:
|
if key[K_d]:
|
||||||
return(move_right())
|
return(move_right())
|
||||||
@ -133,8 +121,6 @@ def pathfinding():
|
|||||||
avaiable_value = [0,1,4,5]
|
avaiable_value = [0,1,4,5]
|
||||||
elif activity == 3:
|
elif activity == 3:
|
||||||
avaiable_value = [8]
|
avaiable_value = [8]
|
||||||
opened = []
|
|
||||||
closed = []
|
|
||||||
start_position = [int(((config.TRAKTOR_POZ[1]-5)/70)-1), int(((config.TRAKTOR_POZ[0]-5)/70)-1)]
|
start_position = [int(((config.TRAKTOR_POZ[1]-5)/70)-1), int(((config.TRAKTOR_POZ[0]-5)/70)-1)]
|
||||||
end_point = search(start_position,avaiable_value)
|
end_point = search(start_position,avaiable_value)
|
||||||
if start_position == end_point:
|
if start_position == end_point:
|
||||||
@ -152,7 +138,7 @@ def pathfinding():
|
|||||||
elif i[1]< poz[1]:
|
elif i[1]< poz[1]:
|
||||||
move_left()
|
move_left()
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
time.sleep(2)
|
time.sleep(0.2)
|
||||||
work([int(((config.TRAKTOR_POZ[1]-5)/70)-1), int(((config.TRAKTOR_POZ[0]-5)/70)-1)])
|
work([int(((config.TRAKTOR_POZ[1]-5)/70)-1), int(((config.TRAKTOR_POZ[0]-5)/70)-1)])
|
||||||
|
|
||||||
def a_star(start, end):
|
def a_star(start, end):
|
||||||
@ -188,19 +174,16 @@ def a_star(start, end):
|
|||||||
|
|
||||||
return finall_path
|
return finall_path
|
||||||
|
|
||||||
closed = []
|
def search(start,value):
|
||||||
def search(point,values):
|
visited = [start]
|
||||||
global closed
|
while visited:
|
||||||
if config.POLE_STAN[point[0],point[1]] in values:
|
if config.POLE_STAN[visited[0][0],visited[0][1]] in value:
|
||||||
closed = []
|
print("Znaleziono pole: "+str(visited[0]))
|
||||||
return point
|
return visited[0]
|
||||||
else:
|
else:
|
||||||
closed.append(point)
|
for i in points(visited[0]):
|
||||||
childs = points(point)
|
visited.append(i)
|
||||||
while childs:
|
del visited[0]
|
||||||
child = childs.pop()
|
|
||||||
if child not in closed:
|
|
||||||
return search(child,values)
|
|
||||||
|
|
||||||
|
|
||||||
def points(point):
|
def points(point):
|
||||||
|
Loading…
Reference in New Issue
Block a user