movement_planning #2

Merged
s473585 merged 13 commits from movement_planning into master 2023-05-24 14:28:17 +02:00
9 changed files with 12 additions and 10 deletions
Showing only changes of commit 674393a4d9 - Show all commits

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

4
bfs.py
View File

@ -1,6 +1,6 @@
from succ import succ as successors from succ import succ as successors
def bfs(istate, goalx, goaly): def bfs(istate, goalx, goaly, passedFields):
fringe = [istate] fringe = [istate]
explored = [] explored = []
steps = [] steps = []
@ -13,7 +13,7 @@ def bfs(istate, goalx, goaly):
steps.insert(0, state) steps.insert(0, state)
return steps return steps
element = successors(state) element = successors(state, passedFields)
explored.append((state.xpos, state.ypos, state.orientation)) explored.append((state.xpos, state.ypos, state.orientation))
for value in element : for value in element :
val = (value.xpos, value.ypos, value.orientation) val = (value.xpos, value.ypos, value.orientation)

13
main.py
View File

@ -34,7 +34,9 @@ def randomize_map(): # tworzenie mapy z losowymi polami
field_array_2 = [] field_array_2 = []
for i in range(16): for i in range(16):
for j 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_1.append(field_array_2)
field_array_2 = [] field_array_2 = []
return field_array_1 return field_array_1
@ -43,7 +45,7 @@ def randomize_map(): # tworzenie mapy z losowymi polami
def draw_window(agent, fields): def draw_window(agent, fields):
for i in range(16): for i in range(16):
for j 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 window.blit(AGENT, (agent.rect.x, agent.rect.y)) # wyswietlanie agenta
pygame.display.update() pygame.display.update()
@ -58,7 +60,6 @@ def draw_window(agent, fields):
# if keys_pressed[pygame.K_DOWN] and agent.y < 750: # if keys_pressed[pygame.K_DOWN] and agent.y < 750:
# agent.y += 50 # agent.y += 50
def main(): def main():
clock = pygame.time.Clock() clock = pygame.time.Clock()
run = True run = True
@ -71,13 +72,13 @@ def main():
run = False run = False
#keys_pressed = pygame.key.get_pressed() #keys_pressed = pygame.key.get_pressed()
draw_window(agent, fields) 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: for interm in steps:
if interm.action == 'LEFT': if interm.action == 'LEFT':
agent.turn_left() agent.turn_left()
if interm.action == 'RIGHT': elif interm.action == 'RIGHT':
agent.turn_right() agent.turn_right()
if interm.action == 'FORWARD': elif interm.action == 'FORWARD':
agent.forward() agent.forward()
draw_window(agent, fields) draw_window(agent, fields)
time.sleep(0.5) time.sleep(0.5)

View File

@ -4,4 +4,5 @@ class State:
self.xpos = xpos self.xpos = xpos
self.ypos = ypos self.ypos = ypos
self.orientation = orientation self.orientation = orientation
self.action = action self.action = action
# self.priority = priority

View File

@ -1,7 +1,7 @@
from state import State from state import State
FIELDWIDTH, FIELDCOUNT = 50, 16 FIELDWIDTH, FIELDCOUNT = 50, 16
def succ(st: State): def succ(st: State, passedFields):
successors = [] successors = []
if st.orientation == 'N': if st.orientation == 'N':