rpg-szi/actions.py

48 lines
1.4 KiB
Python
Raw Normal View History

# Funkcja konwertujaca wspolrzedne nastepnego pola do odwiedzenia
# pole to element wziety z kolejki path
from state import AgentState
from direction import Direction
def actionsInterpreter(actionIndex, defaultState, directions):
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
}