2021-04-25 22:48:55 +02:00
|
|
|
# Funkcja konwertujaca wspolrzedne nastepnego pola do odwiedzenia
|
2021-04-13 16:59:43 +02:00
|
|
|
|
2021-04-25 22:48:55 +02:00
|
|
|
# pole to element wziety z kolejki path
|
|
|
|
from state import AgentState
|
|
|
|
from direction import Direction
|
2021-04-13 16:59:43 +02:00
|
|
|
|
2021-04-25 22:48:55 +02:00
|
|
|
def actionsInterpreter(actionIndex, defaultState, directions):
|
2021-04-13 16:59:43 +02:00
|
|
|
|
2021-04-25 22:48:55 +02:00
|
|
|
if actionIndex == -1:
|
|
|
|
return AgentState(
|
|
|
|
defaultState.get_x(),
|
|
|
|
defaultState.get_y(),
|
|
|
|
defaultState.get_direction().counterClockwise()
|
|
|
|
)
|
|
|
|
elif actionIndex == 0:
|
|
|
|
move_x = 0
|
|
|
|
move_y = 0
|
|
|
|
|
|
|
|
if defaultState.get_direction() == Direction.N:
|
|
|
|
move_y = 1
|
|
|
|
elif defaultState.get_direction() == Direction.E:
|
|
|
|
move_x = 1
|
|
|
|
elif defaultState.get_direction() == Direction.S:
|
|
|
|
move_y = -1
|
|
|
|
elif defaultState.get_direction() == Direction.W:
|
|
|
|
move_x = -1
|
|
|
|
|
|
|
|
return AgentState(
|
|
|
|
defaultState.get_x() + move_x, # directions[defaultState.get_direction()[0]], - is not subscriptable ???
|
|
|
|
defaultState.get_y() + move_y, # directions[defaultState.get_direction()][1], - is not subscriptable ???
|
|
|
|
defaultState.get_direction()
|
|
|
|
)
|
|
|
|
elif actionIndex == 1:
|
|
|
|
return AgentState(
|
|
|
|
defaultState.get_x(),
|
|
|
|
defaultState.get_y(),
|
|
|
|
defaultState.get_direction().clockwise()
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return defaultState
|
|
|
|
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
"rotateLeft": -1,
|
|
|
|
"moveForward": 0,
|
|
|
|
"rotateRight": 1
|
|
|
|
}
|