From e01dfeb85a6ba6b10414883530cc45a1578228c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 26 Apr 2020 00:22:03 +0200 Subject: [PATCH] Change priority method in AutomaticMovement.py Now priority method calculates pr for given node --- src/AI/AutomaticMovement.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/AI/AutomaticMovement.py b/src/AI/AutomaticMovement.py index ee8de30..b8e0989 100644 --- a/src/AI/AutomaticMovement.py +++ b/src/AI/AutomaticMovement.py @@ -2,8 +2,11 @@ from copy import copy from src.entities.Entity import Entity from src.entities.Player import Movement, Rotations +from src.AI.AStarNode import AStarNode from queue import PriorityQueue +from src.game.TerrainTile import TerrainTile + class AutomaticMovement: @@ -81,22 +84,21 @@ class AutomaticMovement: return False - def approximateDistanceFromTarget(self, nextTileX, nextTileY): - return abs(nextTileX - self.actualTarget.x) + abs(nextTileY - self.actualTarget.y) + def approximateDistanceFromTarget(self, tileX, tileY): + return abs(tileX - self.actualTarget.x) + abs(tileY - self.actualTarget.y) - def stepCost(self, destinationTile): - # TODO : w oparciu o koszt danej kratki - return 1 - - def priority(self, apprDist, stepCost): - return apprDist + stepCost + def stepCost(self, terrainTile: TerrainTile): + return terrainTile.cost + def priority(self, elem: AStarNode): + return self.approximateDistanceFromTarget(elem.state[0], elem.state[1]) + self.stepCost(self.map.getTileOnCoord(elem.state)) ''' state[0] - x state[1] - y state[2] - rotation ''' + def newStateAfterAction(self, state, action: Movement): newState = copy(state)