a_star #21
@ -94,41 +94,41 @@ def remove_forward(possible_actions: List[str]) -> None:
|
||||
|
||||
|
||||
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 action == TURN_LEFT:
|
||||
new_state.direction = LEFT
|
||||
next_state.direction = LEFT
|
||||
elif action == TURN_RIGHT:
|
||||
new_state.direction = RIGHT
|
||||
next_state.direction = RIGHT
|
||||
elif action == FORWARD:
|
||||
new_state.position = next_position(state.position, UP)
|
||||
next_state.position = next_position(state.position, UP)
|
||||
|
||||
elif state.direction == DOWN:
|
||||
if action == TURN_LEFT:
|
||||
new_state.direction = RIGHT
|
||||
next_state.direction = RIGHT
|
||||
elif action == TURN_RIGHT:
|
||||
new_state.direction = LEFT
|
||||
next_state.direction = LEFT
|
||||
elif action == FORWARD:
|
||||
new_state.position = next_position(state.position, DOWN)
|
||||
next_state.position = next_position(state.position, DOWN)
|
||||
|
||||
elif state.direction == LEFT:
|
||||
if action == TURN_LEFT:
|
||||
new_state.direction = DOWN
|
||||
next_state.direction = DOWN
|
||||
elif action == TURN_RIGHT:
|
||||
new_state.direction = UP
|
||||
next_state.direction = UP
|
||||
elif action == FORWARD:
|
||||
new_state.position = next_position(state.position, LEFT)
|
||||
next_state.position = next_position(state.position, LEFT)
|
||||
|
||||
elif state.direction == RIGHT:
|
||||
if action == TURN_LEFT:
|
||||
new_state.direction = UP
|
||||
next_state.direction = UP
|
||||
elif action == TURN_RIGHT:
|
||||
new_state.direction = DOWN
|
||||
next_state.direction = DOWN
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user