From cef686a74fefeb42d539ed51699b5b2c2e0a07d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sat, 25 Apr 2020 23:55:31 +0200 Subject: [PATCH] Add method calculating new state with given action --- src/AI/AutomaticMovement.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/AI/AutomaticMovement.py b/src/AI/AutomaticMovement.py index a829364..d473df0 100644 --- a/src/AI/AutomaticMovement.py +++ b/src/AI/AutomaticMovement.py @@ -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