movement_planning #2
BIN
__pycache__/bfs.cpython-310.pyc
Normal file
BIN
__pycache__/bfs.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/garbage_truck.cpython-310.pyc
Normal file
BIN
__pycache__/garbage_truck.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/main.cpython-310.pyc
Normal file
BIN
__pycache__/main.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/state.cpython-310.pyc
Normal file
BIN
__pycache__/state.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/succ.cpython-310.pyc
Normal file
BIN
__pycache__/succ.cpython-310.pyc
Normal file
Binary file not shown.
4
bfs.py
4
bfs.py
@ -1,6 +1,6 @@
|
||||
from succ import succ as successors
|
||||
|
||||
def bfs(istate, goalx, goaly):
|
||||
def bfs(istate, goalx, goaly, passedFields):
|
||||
fringe = [istate]
|
||||
explored = []
|
||||
steps = []
|
||||
@ -13,7 +13,7 @@ def bfs(istate, goalx, goaly):
|
||||
steps.insert(0, state)
|
||||
return steps
|
||||
|
||||
element = successors(state)
|
||||
element = successors(state, passedFields)
|
||||
explored.append((state.xpos, state.ypos, state.orientation))
|
||||
for value in element :
|
||||
val = (value.xpos, value.ypos, value.orientation)
|
||||
|
13
main.py
13
main.py
@ -34,7 +34,9 @@ def randomize_map(): # tworzenie mapy z losowymi polami
|
||||
field_array_2 = []
|
||||
for i in range(16):
|
||||
for j in range(16):
|
||||
field_array_2.append(random.choice(fields_list))
|
||||
randomChoiceOfBlock = random.choice(fields_list)
|
||||
priorityOfBlock = fields_list.index(randomChoiceOfBlock)
|
||||
field_array_2.append([randomChoiceOfBlock,priorityOfBlock])
|
||||
field_array_1.append(field_array_2)
|
||||
field_array_2 = []
|
||||
return field_array_1
|
||||
@ -43,7 +45,7 @@ def randomize_map(): # tworzenie mapy z losowymi polami
|
||||
def draw_window(agent, fields):
|
||||
for i in range(16):
|
||||
for j in range(16):
|
||||
window.blit(fields[i][j], (i * 50, j * 50))
|
||||
window.blit(fields[i][j][0], (i * 50, j * 50))
|
||||
window.blit(AGENT, (agent.rect.x, agent.rect.y)) # wyswietlanie agenta
|
||||
pygame.display.update()
|
||||
|
||||
@ -58,7 +60,6 @@ def draw_window(agent, fields):
|
||||
# if keys_pressed[pygame.K_DOWN] and agent.y < 750:
|
||||
# agent.y += 50
|
||||
|
||||
|
||||
def main():
|
||||
clock = pygame.time.Clock()
|
||||
run = True
|
||||
@ -71,13 +72,13 @@ def main():
|
||||
run = False
|
||||
#keys_pressed = pygame.key.get_pressed()
|
||||
draw_window(agent, fields)
|
||||
steps = bfs(State(None, None, 0, 0, 'E'), 450, 600)
|
||||
steps = bfs(State(None, None, 0, 0, 'E'), 100, 50, fields)
|
||||
for interm in steps:
|
||||
if interm.action == 'LEFT':
|
||||
agent.turn_left()
|
||||
if interm.action == 'RIGHT':
|
||||
elif interm.action == 'RIGHT':
|
||||
agent.turn_right()
|
||||
if interm.action == 'FORWARD':
|
||||
elif interm.action == 'FORWARD':
|
||||
agent.forward()
|
||||
draw_window(agent, fields)
|
||||
time.sleep(0.5)
|
||||
|
3
state.py
3
state.py
@ -4,4 +4,5 @@ class State:
|
||||
self.xpos = xpos
|
||||
self.ypos = ypos
|
||||
self.orientation = orientation
|
||||
self.action = action
|
||||
self.action = action
|
||||
# self.priority = priority
|
Loading…
Reference in New Issue
Block a user