def test_mapLoaded_MayMove_Failure_OutOfBounds_Y(self): path = self._SimpleRealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) PointFrom = Point(0, 900) PointTo = Point(1, 1) may = holder.mayMove(PointFrom, PointTo) self.assertFalse(may, "error")
def test_mapLoaded_GetPath_Success_LongPath_Draw(self): path = self._SimpleRealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) PointFrom = Point(0, 0) PointTo = Point(1, 2) path = holder.getPath(PointFrom, PointTo) self.assertTrue(path.valid, "error")
def test_mapLoaded_GetPath_Failure_OutOfBounds_Y(self): path = self._SimpleRealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) PointFrom = Point(0, 900) PointTo = Point(1, 1) path = holder.getPath(PointFrom, PointTo) self.assertFalse(path.valid, "error")
def CalcMovment(self, engine: PlayerEngineFacade) -> MovementCommand: X = engine.GetGameState().MyPlayer.position.x Y = engine.GetGameState().MyPlayer.position.y - 1 if engine.MayIMove(Point(X, Y)): self._Evades += 1 return MovementCommand(Point(X, Y)) return MovementCommand.GetEmpty()
def test_mapLoaded_MayMove_Success_LongPath(self): path = self._SimpleRealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) PointFrom = Point(0, 0) PointTo = Point(1, 2) may = holder.mayMove(PointFrom, PointTo) self.assertTrue(may, "error")
def test_IsLos_Success_SameRow_LeftMovment(self): RealPath = os.path.join(os.path.dirname(__file__), '..\Maps\ChallangeMap\Map.csv') csvreader = CSVMatrixReader() csvreader.parse(RealPath) p1 = Point(1, 1) p2 = Point(0, 1) calc = LosCalculator() isLos = calc.IsLos(p1, p2, csvreader.Matrix) self.assertTrue(isLos)
def test_IsLos_Fail_SameCol_UpMovment(self): RealPath = os.path.join(os.path.dirname(__file__), '..\Maps\ChallangeMap\Map.csv') csvreader = CSVMatrixReader() csvreader.parse(RealPath) p1 = Point(7, 4) p2 = Point(7, 2) calc = LosCalculator() isLos = calc.IsLos(p1, p2, csvreader.Matrix) self.assertFalse(isLos)
def generateDict(self): # Depending on rows in self.object.dimDict, calculate number of points pointsnumber = int(self.obj.dimDict.get("rows")) * 2 # for loop from point 0 to point pointsnumber. We decide that point 0 is at the beginning of the first row point0 = Point(0, 0) point0.name = "Point" + str(0) self.pointDict[point0.name] = point0 point1 = Point(0, int(self.obj.dimDict.get("length"))) point1.name = "Point" + str(1) self.pointDict[point1.name] = point1 for x in range(2, pointsnumber): point = Point(Mapping.x, Mapping.y) point.name = "Point" + str(x) if x % 2 == 0: Mapping.y = 0 Mapping.x += int(self.obj.dimDict.get("distanceBetweenRows")) else: Mapping.y = int(self.obj.dimDict.get("length")) Mapping.x += int(self.obj.dimDict.get("distanceBetweenRows")) self.pointDict[point.name] = point print self.pointDict
def test_mapLoaded_MayMove_Fail_UnReachable(self): path = self._SimpleRealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) PointFrom = Point(0, 0) PointTo = Point(3, 3) self._ConfigProvider.addValue('Game.MovementDefinations', 'maximumAllowedPath', '1') path = holder.getPath(PointFrom, PointTo) self.assertFalse(path.valid, "error")
def test_mapLoaded_MayMove_Fail_Too_LongDistance(self): path = self._SimpleRealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) PointFrom = Point(0, 0) PointTo = Point(2, 2) self._ConfigProvider.addValue('Game.MovementDefinations', 'maximumAllowedPath', '1') may = holder.mayMove(PointFrom, PointTo) self.assertFalse(may, "error")
def _RandomizeGame(self, gamestate: CompleteGameState): gamestate.player_1_State.position = Point(random.randint(0, 9), random.randint(0, 9)) gamestate.player_1_State.threatenedTime = random.randint(0, 9) gamestate.player_1_State.threateningTime = random.randint(0, 10) gamestate.player_1_State.score = random.randint(1, 40) gamestate.player_2_State.position = Point(random.randint(0, 9), random.randint(0, 9)) gamestate.player_2_State.threatenedTime = random.randint(0, 9) gamestate.player_2_State.threateningTime = random.randint(0, 10) gamestate.player_2_State.score = random.randint(1, 40)
def test_GetPath_Fail(self): path = self._RealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) player1 = PlayerState(1) player2 = PlayerState(2) gamestate = GameState(player1, player2, 10) gamestate.MyPlayer.position = Point(1, 7) gamestate.EnemyPlayer.position = Point(9, 9) engine = PlayerEngine.PlayerEngine(gamestate, self._ConfigProvider, holder) path = engine.GetPathForMe(gamestate.EnemyPlayer.position) self.assertFalse(path.valid)
def mayMove(self,pFrom:Point,pTo:Point): if not self._Csvreader.fileLoaded: return False if not self._GraphLoaded: return False dim=self.getMapDim() if dim.IsPointInDim(pFrom)==False: return False if dim.IsPointInDim(pTo)==False: return False NodeFrom = Point.ToGridNodeFromPoint(pFrom, dim.height) NodeTo = Point.ToGridNodeFromPoint(pTo, dim.height) return self._MovementCalculator.mayMove(NodeFrom,NodeTo,self._Graph)
def test_NoMovementController_OK_FOR_MOVEMENT_NotSafePoint(self): nomovementcontroller = NoMovementController(self._ConfigProvider) playerPosition = Point(2, 2) result = nomovementcontroller.IStaticForTooLong( playerPosition, 2, self._IsSafePoint) self.assertTrue(result == PlayerNoMovmentState.OK, "OK") playerPosition = Point(2, 5) result = nomovementcontroller.IStaticForTooLong( playerPosition, 2, self._IsSafePoint) self.assertTrue(result == PlayerNoMovmentState.OK, "OK") playerPosition = Point(3, 2) result = nomovementcontroller.IStaticForTooLong( playerPosition, 2, self._IsSafePoint) self.assertTrue(result == PlayerNoMovmentState.OK, "OK")
def test_Movement_Success(self): path = self._RealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) player1 = PlayerState(1) player2 = PlayerState(2) gamestate = GameState(player1, player2, 10) engine = PlayerEngine.PlayerEngine(gamestate, self._ConfigProvider, holder) PointFrom = Point(0, 0) PointTo = Point(1, 2) self.assertTrue(engine.MayIMove(PointTo)) self.assertTrue(engine.MayMoveBetweenPoints(PointFrom, PointTo))
def test_GetPath_Success_and_Draw(self): path = self._RealPath self._ConfigProvider.addValue('Game.Config', 'DrawMapHolderGraph', 'True') holder = MapHolder(self._ConfigProvider) holder.loadMap(path) player1 = PlayerState(1) player2 = PlayerState(2) gamestate = GameState(player1, player2, 10) gamestate.MyPlayer.position = Point(1, 1) gamestate.EnemyPlayer.position = Point(1, 3) engine = PlayerEngine.PlayerEngine(gamestate, self._ConfigProvider, holder) path = engine.GetPathForMe(gamestate.EnemyPlayer.position) self.assertTrue(path.valid)
def test_ThreatController_Safe(self): path = self._RealPath p1 = Point(3, 4) p2 = Point(7, 1) holder = MapHolder(self._ConfigProvider) holder.loadMap(path) threatController = ThreatController(holder, self._ConfigProvider) playerstate1 = PlayerState(1) playerstate1.position = p1 playerstate2 = PlayerState(2) playerstate2.position = p2 self.assertTrue( threatController.GetPlayerThreatState( playerstate1, playerstate2) == PlayerThreatState.SAFEPOINT, "OK")
def test_ThreatController_NotThreat(self): path = self._RealPath p1 = Point(6, 4) p2 = Point(6, 6) holder = MapHolder(self._ConfigProvider) holder.loadMap(path) threatController = ThreatController(holder, self._ConfigProvider) playerstate1 = PlayerState(1) playerstate1.position = p1 playerstate2 = PlayerState(2) playerstate2.position = p2 self.assertTrue( threatController.GetPlayerThreatState( playerstate1, playerstate2) == PlayerThreatState.NOT_THREATENED, "OK")
def test_NoMovementController_OK_SafePoint(self): playerPosition = Point(2, 2) self._IsSafePoint = True nomovementcontroller = NoMovementController(self._ConfigProvider) result = nomovementcontroller.IStaticForTooLong( playerPosition, 1, self._IsSafePoint) self.assertTrue(result == PlayerNoMovmentState.OK, "OK")
def test_NoMovementController_STATIC_TIMEOUT_NotSafePoint(self): playerPosition = Point(2, 2) nomovementcontroller = NoMovementController(self._ConfigProvider) result = nomovementcontroller.IStaticForTooLong( playerPosition, 7, self._IsSafePoint) self.assertTrue(result == PlayerNoMovmentState.STATIC_TIMEOUT, "OK")
def test_GetAlt_Failed_2(self): path = self._RealPath print(path) holder = MapHolder(self._ConfigProvider) holder.loadMap(path) self.assertTrue( holder.getAlt(Point(-1, -1)) == self._Consts.InValidAlt, "error")
def _UpdateWeight(self, cord, colIndex, rowIndex, dim, xFactor, yFactor): newColIndex = colIndex + xFactor newRowIndex = rowIndex + yFactor if (newColIndex) >= dim.width: return if (newColIndex) < 0: return if (newRowIndex) >= dim.height: return if (newRowIndex) < 0: return # we try to go to Cover -not connected NextCord = Point.ToGridNode(newColIndex, newRowIndex, dim.height) if self._Csvreader.Matrix.item( (colIndex, rowIndex )) == self._Consts.SafePointValue or self._Csvreader.Matrix.item( (newColIndex, newRowIndex)) == self._Consts.SafePointValue: # we set connectivity self._Graph.add_edge( NextCord, cord, weight=self._Consts.ConnectedGraphVertexWeight) else: # Alt Diff Issue AltDiff = abs( self._Csvreader.Matrix.item((colIndex, rowIndex)) - self._Csvreader.Matrix.item((newColIndex, newRowIndex))) if AltDiff >= self._Consts.MaximumAltDif: return # we set connectivity self._Graph.add_edge( NextCord, cord, weight=self._Consts.ConnectedGraphVertexWeight)
def test_ThreatController_Destroryed(self): path = self._RealPath p1 = Point(3, 4) p2 = Point(5, 6) holder = MapHolder(self._ConfigProvider) holder.loadMap(path) threatController = ThreatController(holder, self._ConfigProvider) playerstate1 = PlayerState(1) playerstate1.position = p1 playerstate1.threateningTime = 5 playerstate2 = PlayerState(2) playerstate2.position = p2 playerstate2.threatenedTime = 5 self.assertTrue( threatController.GetPlayerThreatState( playerstate1, playerstate2) == PlayerThreatState.DESTROYED, "OK")
def test_DrawAll_FinalState_Threat(self): RealPath = os.path.join(os.path.dirname(__file__), '../Maps/TestMap/Map.csv') csvreader = CSVMatrixReader() csvreader.parse(RealPath) game1 = CompleteGameState(100) game1.player_1_State.position = Point(0, 0) game1.player_2_State.position = Point(9, 9) game1.player_2_State.threatened = True game2 = CompleteGameState(100) game2.player_1_State.position = Point(1, 1) game2.player_2_State.position = Point(2, 4) game2.player_2_State.threatened = False game3 = CompleteGameState(100) game3.player_1_State.position = Point(2, 7) game3.player_2_State.position = Point(9, 3) game3.player_1_State.score = 10 game3.player_2_State.score = 20 game3.player_2_State.threatened = True game4 = CompleteGameState(100) game4.player_1_State.position = Point(1, 1) game4.player_2_State.position = Point(3, 3) game4.player_1_State.score = 10 game4.player_2_State.score = 20 game4.player_2_State.threatened = True game5 = CompleteGameState(100) game5.player_1_State.position = Point(1, 1) game5.player_2_State.position = Point(2, 2) game5.player_1_State.score = 10 game5.player_2_State.score = 20 game5.player_2_State.threatened = True games = [] games.append(game1) games.append(game2) games.append(game3) games.append(game4) games.append(game5) drawMatch = GameDrawing(csvreader.Matrix, games) self.assertTrue(csvreader.fileLoaded, "error")
def test_Movement_Fail(self): path = self._RealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) player1 = PlayerState(1) player2 = PlayerState(2) gamestate = GameState(player1, player2, 10) self._ConfigProvider.addValue('Game.MovementDefinations', 'maximumAllowedPath', '1') engine = PlayerEngine.PlayerEngine(gamestate, self._ConfigProvider, holder) PointFrom = Point(0, 0) PointTo = Point(3, 3) self.assertFalse(engine.MayIMove(PointTo)) self.assertFalse(engine.MayMoveBetweenPoints(PointFrom, PointTo))
def _LoadSafePoints(self): self._SafePoints = [] dim = self._getMapDim() goodvalues = [self._Consts.SafePointValue] safepointsindexes = np.isin(self._Csvreader.Matrix, goodvalues) Y, X = np.where(safepointsindexes) for i in range(len(Y)): self._SafePoints.append(Point(X[i], Y[i])) print(safepointsindexes)
def test_Los_Fail(self): path = self._RealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) player1 = PlayerState(1) player2 = PlayerState(2) gamestate = GameState(player1, player2, 10) gamestate.MyPlayer.position = Point(1, 1) gamestate.EnemyPlayer.position = Point(1, 3) engine = PlayerEngine.PlayerEngine(gamestate, self._ConfigProvider, holder) self.assertFalse(engine.IsLosToEnemy()) self.assertFalse(engine.IsLosFromMeToPoint(Point(1, 4))) p1 = Point(2, 1) p2 = Point(6, 5) self.assertFalse(engine.IsLosBetweenPoints(p1, p2))
def __init__(self,id:int): self._Position=Point(0,0) self._ID = int(id) self._Score=0 self._TimeInPosition=0 self._IsDestoryed=False self._IsThretened=False self._ThreatenedTime=0 self._ThreateningTime=0 self._RestPointTime=0
def test_Update_GameState(self): path = self._RealPath holder = MapHolder(self._ConfigProvider) holder.loadMap(path) player1 = PlayerState(1) player2 = PlayerState(2) gamestate = GameState(player1, player2, 10) engine = PlayerEngine.PlayerEngine(gamestate, self._ConfigProvider, holder) self.assertTrue(engine.GetGameState().MyPlayer.position.x == 0) self.assertTrue(engine.GetGameState().EnemyPlayer.position.x == 0) self.assertTrue(engine.GetGameState().playingtime == 0) gamestate.playingtime = 100 gamestate.MyPlayer.position = Point(10, 10) gamestate.EnemyPlayer.position = Point(20, 20) self.assertTrue(engine.GetGameState().MyPlayer.position.x == 10) self.assertTrue(engine.GetGameState().EnemyPlayer.position.x == 20) self.assertTrue(engine.GetGameState().playingtime == 100)
def _GetControllingPointsForPoint(self, x, y): dim = self._getMapDim() point = Point(x, y) pointcontrol = PointsControl(point) for ColIndex in range(0, dim.height): for RowIndex in range(0, dim.width): targetpoint = Point(RowIndex, ColIndex) if (targetpoint != point): if (self._LosCalculator.IsLos(point, targetpoint, self._Csvreader.Matrix)): pointcontrol.controlledpoints.append(targetpoint) if not self._LosCalculator.IsSafePoint( targetpoint, self._Csvreader. Matrix) and self._LosCalculator.IsLos( targetpoint, point, self._Csvreader.Matrix): pointcontrol.controllingpoints.append(targetpoint) self._PointsControl[x][y] = pointcontrol