From 5af76a1b16eb984d73f0f0f24d92f3380d478724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 26 Apr 2020 00:03:38 +0200 Subject: [PATCH] Change succesor method in AutomaticMovement.py Now succesor takes state as an argument and returns all possible moves for that state. --- src/AI/AutomaticMovement.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/AI/AutomaticMovement.py b/src/AI/AutomaticMovement.py index 761d3ee..26c92eb 100644 --- a/src/AI/AutomaticMovement.py +++ b/src/AI/AutomaticMovement.py @@ -57,13 +57,21 @@ class AutomaticMovement: def succesor(self): movesList = [Movement.ROTATE_L, Movement.ROTATE_R] - # Check if can move forward - facingCoord = self.player.getFacingCoord() - facingEntity = self.map.getEntityOnCoord(facingCoord) - if facingEntity is not None: - movesList.append(Movement.FORWARD) + def succesor(self, elemState): + ''' + :param elemState: [x, y, Rotation] + :return: list of (Movement, NewState) + ''' + result = [(Movement.ROTATE_R, self.newStateAfterAction(elemState, Movement.ROTATE_R)), + (Movement.ROTATE_L, self.newStateAfterAction(elemState, Movement.ROTATE_L))] - return movesList + stateAfterForward = self.newStateAfterAction(elemState, Movement.FORWARD) + facingEntity = self.map.getEntityOnCoord(stateAfterForward) + + if facingEntity is not None: + result.append((Movement.FORWARD, stateAfterForward)) + + return result def goalTest(self, coords): entity = self.map.getEntityOnCoord(coords)