added priority for blocks

This commit is contained in:
Maksymilian Mikołajczak 2023-05-03 12:07:13 +02:00
parent 15abf755b9
commit 674393a4d9
9 changed files with 12 additions and 10 deletions

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
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
View File

@ -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)

View File

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

View File

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