feat: result function

This commit is contained in:
korzepadawid 2022-04-11 23:53:50 +02:00
parent fbbb521a4b
commit 6c27199988

View File

@ -11,6 +11,10 @@ RIGHT = 'RIGHT'
UP = 'UP'
DOWN = 'DOWN'
TURN_LEFT = 'TURN_LEFT'
TURN_RIGHT = 'TURN_RIGHT'
FORWARD = 'FORWARD'
directions = {
LEFT: (0, -1),
RIGHT: (0, 1),
@ -18,10 +22,6 @@ directions = {
DOWN: (1, 0)
}
TURN_LEFT = 'TURN_LEFT'
TURN_RIGHT = 'TURN_RIGHT'
FORWARD = 'FORWARD'
@dataclass
class State:
@ -93,8 +93,42 @@ def remove_forward(possible_actions: List[str]) -> None:
possible_actions.remove(FORWARD)
def result(state: State, action: str, grid: List[List[str]]) -> State:
pass
def result(state: State, action: str) -> State:
new_state = State(state.position, state.direction)
if state.direction == UP:
if action == TURN_LEFT:
new_state.direction = LEFT
elif action == TURN_RIGHT:
new_state.direction = RIGHT
elif action == FORWARD:
new_state.position = next_position(state.position, UP)
elif state.direction == DOWN:
if action == TURN_LEFT:
new_state.direction = RIGHT
elif action == TURN_RIGHT:
new_state.direction = LEFT
elif action == FORWARD:
new_state.position = next_position(state.position, DOWN)
elif state.direction == LEFT:
if action == TURN_LEFT:
new_state.direction = DOWN
elif action == TURN_RIGHT:
new_state.direction = UP
elif action == FORWARD:
new_state.position = next_position(state.position, LEFT)
elif state.direction == RIGHT:
if action == TURN_LEFT:
new_state.direction = UP
elif action == TURN_RIGHT:
new_state.direction = DOWN
elif action == FORWARD:
new_state.position = next_position(state.position, RIGHT)
return new_state
def goal_test(state: State, goal_list: List[Tuple[int, int]]) -> bool: