diff --git a/__pycache__/bfs.cpython-310.pyc b/__pycache__/bfs.cpython-310.pyc new file mode 100644 index 0000000..f9f8ace Binary files /dev/null and b/__pycache__/bfs.cpython-310.pyc differ diff --git a/__pycache__/garbage_truck.cpython-310.pyc b/__pycache__/garbage_truck.cpython-310.pyc new file mode 100644 index 0000000..d4dcb18 Binary files /dev/null and b/__pycache__/garbage_truck.cpython-310.pyc differ diff --git a/__pycache__/main.cpython-310.pyc b/__pycache__/main.cpython-310.pyc new file mode 100644 index 0000000..6af3024 Binary files /dev/null and b/__pycache__/main.cpython-310.pyc differ diff --git a/__pycache__/state.cpython-310.pyc b/__pycache__/state.cpython-310.pyc new file mode 100644 index 0000000..b39f434 Binary files /dev/null and b/__pycache__/state.cpython-310.pyc differ diff --git a/__pycache__/succ.cpython-310.pyc b/__pycache__/succ.cpython-310.pyc new file mode 100644 index 0000000..6927dcf Binary files /dev/null and b/__pycache__/succ.cpython-310.pyc differ diff --git a/bfs.py b/bfs.py index 58d7f4e..dc4a11f 100644 --- a/bfs.py +++ b/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) diff --git a/main.py b/main.py index b33ffb2..e22a4e9 100644 --- a/main.py +++ b/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) diff --git a/state.py b/state.py index a6b5e2b..56e67df 100644 --- a/state.py +++ b/state.py @@ -4,4 +4,5 @@ class State: self.xpos = xpos self.ypos = ypos self.orientation = orientation - self.action = action \ No newline at end of file + self.action = action + # self.priority = priority \ No newline at end of file diff --git a/succ.py b/succ.py index 8ebe570..a01b49a 100644 --- a/succ.py +++ b/succ.py @@ -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':