Add method calculating new state with given action

This commit is contained in:
Michał Czekański 2020-04-25 23:55:31 +02:00
parent 7d9dd06d09
commit cef686a74f

View File

@ -1,5 +1,7 @@
from copy import copy
from src.entities.Entity import Entity
from src.entities.Player import Movement
from src.entities.Player import Movement, Rotations
from queue import PriorityQueue
@ -11,6 +13,7 @@ class AutomaticMovement:
self.nextMove = None
self.movesList = None
self.actualTarget = None
self.moveOffset = self.player.rect.w
def gotoToTarget(self, target: Entity):
self.actualTarget = target
@ -81,6 +84,31 @@ class AutomaticMovement:
return apprDist + stepCost
'''
state[0] - x
state[1] - y
state[2] - rotation
'''
def newStateAfterAction(self, state, action: Movement):
newState = copy(state)
if action == Movement.FORWARD:
if state[2] == Rotations.NORTH:
newState[1] -= self.moveOffset
elif state[2] == Rotations.EAST.value:
newState[0] += self.moveOffset
elif state[2] == Rotations.SOUTH.value:
newState[1] += self.moveOffset
elif state[2] == Rotations.WEST.value:
newState[0] -= self.moveOffset
elif action == Movement.ROTATE_L:
newState[2] = Rotations((state[2] + 1) % 4)
elif action == Movement.ROTATE_R:
newState[2] = Rotations((state[2] - 1) % 4)
return newState
class node:
def __init__(self, parent, action):
self.parent = parent