a_star #21

Merged
s464961 merged 15 commits from a_star into master 2022-04-27 19:50:51 +02:00
Showing only changes of commit 2bfaff8a30 - Show all commits

View File

@ -94,41 +94,41 @@ def remove_forward(possible_actions: List[str]) -> None:
def result(state: State, action: str) -> State: def result(state: State, action: str) -> State:
new_state = State(state.position, state.direction) next_state = State(state.position, state.direction)
if state.direction == UP: if state.direction == UP:
if action == TURN_LEFT: if action == TURN_LEFT:
new_state.direction = LEFT next_state.direction = LEFT
elif action == TURN_RIGHT: elif action == TURN_RIGHT:
new_state.direction = RIGHT next_state.direction = RIGHT
elif action == FORWARD: elif action == FORWARD:
new_state.position = next_position(state.position, UP) next_state.position = next_position(state.position, UP)
elif state.direction == DOWN: elif state.direction == DOWN:
if action == TURN_LEFT: if action == TURN_LEFT:
new_state.direction = RIGHT next_state.direction = RIGHT
elif action == TURN_RIGHT: elif action == TURN_RIGHT:
new_state.direction = LEFT next_state.direction = LEFT
elif action == FORWARD: elif action == FORWARD:
new_state.position = next_position(state.position, DOWN) next_state.position = next_position(state.position, DOWN)
elif state.direction == LEFT: elif state.direction == LEFT:
if action == TURN_LEFT: if action == TURN_LEFT:
new_state.direction = DOWN next_state.direction = DOWN
elif action == TURN_RIGHT: elif action == TURN_RIGHT:
new_state.direction = UP next_state.direction = UP
elif action == FORWARD: elif action == FORWARD:
new_state.position = next_position(state.position, LEFT) next_state.position = next_position(state.position, LEFT)
elif state.direction == RIGHT: elif state.direction == RIGHT:
if action == TURN_LEFT: if action == TURN_LEFT:
new_state.direction = UP next_state.direction = UP
elif action == TURN_RIGHT: elif action == TURN_RIGHT:
new_state.direction = DOWN next_state.direction = DOWN
elif action == FORWARD: elif action == FORWARD:
new_state.position = next_position(state.position, RIGHT) next_state.position = next_position(state.position, RIGHT)
return new_state return next_state
def goal_test(state: State, goal_list: List[Tuple[int, int]]) -> bool: def goal_test(state: State, goal_list: List[Tuple[int, int]]) -> bool: