Esempio n. 1
0
 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")
Esempio n. 2
0
 def test_mapLoaded__FullPath_True(self):
     path = self._RealPath
     print(path)
     holder = MapHolder(self._ConfigProvider)
     holder.loadMap(path)
     self.assertTrue(holder.mapLoaded, "error")
     self.assertTrue(holder.graphLoaded, "error")
Esempio n. 3
0
 def test_mapLoaded_GetDim_Loaded(self):
     path = self._RealPath
     holder = MapHolder(self._ConfigProvider)
     holder.loadMap(path)
     dim = holder.getMapDim()
     self.assertTrue(dim.width == 10, "error")
     self.assertTrue(dim.height == 10, "error")
Esempio n. 4
0
 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")
Esempio n. 5
0
    def __init__(self, mapname, maximumAllowedPath):
        ConfigProvider = UnitTestDummyConfigProvider()
        ConfigProvider.addValue('Game.Config', 'DrawMapHolderGraph', 'False')
        ConfigProvider.addValue('Game.MovementDefinations',
                                'maximumAllowedPath', str(maximumAllowedPath))

        self._MapHolder = MapHolder(ConfigProvider)

        self._Valid = self._MapHolder.loadMap(mapname)
Esempio n. 6
0
    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")
Esempio n. 7
0
    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")
Esempio n. 8
0
    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")
Esempio n. 9
0
    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")
Esempio n. 10
0
    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")
Esempio n. 11
0
    def test_Get_ControllingPoints_2(self):
        path = self._NoControllingPointsMap
        print(path)
        holder = MapHolder(self._ConfigProvider)
        holder.loadMap(path)
        cotrolledpoints = holder.pointscontrol
        controllingpointsLen = len(cotrolledpoints[0][0].controllingpoints)
        controlledpointsLen = len(cotrolledpoints[0][0].controlledpoints)

        self.assertTrue(controllingpointsLen == 0, "error")
        self.assertTrue(controlledpointsLen == 7, "error")
Esempio n. 12
0
 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)
Esempio n. 13
0
    def test_Creation(self):
        path = self._RealPath
        print(path)
        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.id == 1)
        self.assertTrue(engine.GetGameState().EnemyPlayer.id == 2)
Esempio n. 14
0
 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")
Esempio n. 15
0
    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))
Esempio n. 16
0
 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)
Esempio n. 17
0
 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")
Esempio n. 18
0
 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")
Esempio n. 19
0
    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))
Esempio n. 20
0
    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))
Esempio n. 21
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)
Esempio n. 22
0
class InfraDisplayMode(object):
    def __init__(self, mapname, maximumAllowedPath):
        ConfigProvider = UnitTestDummyConfigProvider()
        ConfigProvider.addValue('Game.Config', 'DrawMapHolderGraph', 'False')
        ConfigProvider.addValue('Game.MovementDefinations',
                                'maximumAllowedPath', str(maximumAllowedPath))

        self._MapHolder = MapHolder(ConfigProvider)

        self._Valid = self._MapHolder.loadMap(mapname)

    def Draw(self):
        if (self._Valid):
            drawinfra = InfraDrawing(self._MapHolder)

    @property
    def valid(self) -> bool:
        return self._Valid
Esempio n. 23
0
 def test_GetAlt_Success_2(self):
     path = self._RealPath
     print(path)
     holder = MapHolder(self._ConfigProvider)
     holder.loadMap(path)
     self.assertTrue(holder.getAlt(Point(1, 2)) == 3, "error")
Esempio n. 24
0
 def test_mapLoaded_GraphLoaded_Loaded(self):
     path = self._RealPath
     holder = MapHolder(self._ConfigProvider)
     holder.loadMap(path)
     self.assertTrue(holder.graphLoaded, "error")
Esempio n. 25
0
 def test_mapLoaded_GetDim_Not_Loaded(self):
     path = self._NotRealPath
     holder = MapHolder(self._ConfigProvider)
     holder.loadMap(path)
     self.assertTrue(holder.getMapDim().width == 0, "error")
     self.assertTrue(holder.getMapDim().height == 0, "error")
Esempio n. 26
0
 def test_mapLoaded_GraphLoaded_WithDraw(self):
     path = self._SimpleRealPath
     holder = MapHolder(self._ConfigProvider)
     holder.loadMap(path)
     holder.drawGraph()
     self.assertTrue(holder.graphLoaded, "error")
Esempio n. 27
0
 def test_mapLoaded_False(self):
     path = self._NotRealPath
     holder = MapHolder(self._ConfigProvider)
     holder.loadMap(path)
     self.assertFalse(holder.mapLoaded, "error")