Example #1
0
    def setUp(self):
        shape = (8, 8)
        self.board = GameBoard(shape)
        self.state = GameState(shape)

        self.blue_tank = buildFigure('Tank', (6, 4), BLUE)
        self.red_tank = buildFigure('Tank', (1, 4), RED)
        self.red_inf = buildFigure('Infantry', (2, 4), RED)

        self.state.addFigure(self.red_tank, self.red_inf, self.blue_tank)
    def testMoveOnRoad(self):
        shape = (1, 16)
        board = GameBoard(shape)

        t = buildFigure('Tank', (0, 0), RED)
        i = buildFigure('Infantry', (0, 15), RED)

        stateTank = GameState(shape)
        stateTank.addFigure(t)

        stateInf = GameState(shape)
        stateInf.addFigure(i)

        # movements without road
        nTankNoRoad = len(GM.buildMovements(board, stateTank, t))
        nInfNoRoad = len(GM.buildMovements(board, stateInf, i))

        # adding road
        road = np.zeros(shape, 'uint8')
        road[0, :] = TERRAIN_TYPE['ROAD'].level
        board.addTerrain(road)

        # test for vehicles
        nTankRoad = len(GM.buildMovements(board, stateTank, t))
        nInfRoad = len(GM.buildMovements(board, stateInf, i))

        # tank
        self.assertNotEqual(nTankRoad, nTankNoRoad,
                            'road has no influence for tank')
        self.assertEqual(nTankRoad, 8, 'invalid distance with road for tank')
        self.assertEqual(nTankNoRoad, 6,
                         'invalid distance without road for tank')
        self.assertEqual(nTankRoad - nTankNoRoad, 2,
                         'road does not increase by 2 the distance for tank')

        # infantry
        self.assertNotEqual(nInfRoad, nInfNoRoad,
                            'road has no influence on infantry')
        self.assertEqual(nInfRoad, 4,
                         'invalid distance with road for infantry')
        self.assertEqual(nInfNoRoad, 3,
                         'invalid distance without road  for infantry')
        self.assertEqual(
            nInfRoad - nInfNoRoad, 1,
            'road does not increase by 1 the distance for infantry')

        # test for road change
        board.terrain[0, 0] = 0
        board.terrain[0, 15] = 0

        nTankRoad = len(GM.buildMovements(board, stateTank, t))
        nInfRoad = len(GM.buildMovements(board, stateInf, i))

        self.assertEqual(nTankRoad, 8, 'invalid distance for tank')
        self.assertEqual(nInfRoad, 4, 'invalid distance for infantry')
    def setUp(self):
        collect()

        shape = (16, 16)
        self.board = GameBoard(shape)
        self.state = GameState(shape)

        self.red_tank = buildFigure('Tank', (0, 6), RED)
        self.red_inf = buildFigure('Infantry', (0, 12), RED)

        self.blue_tank = buildFigure('Tank', (15, 6), BLUE)
        self.blue_inf = buildFigure('Infantry', (15, 12), BLUE)

        self.state.addFigure(self.red_tank, self.red_inf, self.blue_tank,
                             self.blue_inf)
Example #4
0
    def setUp(self):
        collect()

        self.shape = (8, 8)
        self.board = GameBoard(self.shape)
        self.state = GameState(self.shape)

        self.blue_tank = buildFigure('Tank', (4, 6), BLUE)
        self.red_tank = buildFigure('Tank', (4, 1), RED)
        self.red_inf = buildFigure('Infantry', (1, 4), RED)

        self.state.addFigure(self.red_tank, self.red_inf, self.blue_tank)

        los_on_target = self.state.getLOS(self.blue_tank)

        self.los_tank = los_on_target[self.red_tank.index]
        self.los_inf = los_on_target[self.red_inf.index]
    def setUp(self):
        collect()

        shape = (16, 16)
        self.board = GameBoard(shape)
        self.state = GameState(shape)

        self.tank = buildFigure('Tank', (8, 8), RED)
        self.state.addFigure(self.tank)
Example #6
0
    def setUp(self):
        shape = (16, 16)
        self.board = GameBoard(shape)
        self.state = GameState(shape)

        self.inf_1 = buildFigure('Infantry', (4, 0), RED)
        self.inf_2 = buildFigure('Infantry', (8, 0), BLUE)

        self.state.addFigure(
            self.inf_1,
            self.inf_2,
        )

        self.red = Puppet(RED)
        self.red.action = GM.actionMove(self.board, self.state, self.inf_1, destination=self.inf_1.position)
        self.red.response = GM.actionNoResponse(RED)

        self.blue = Puppet(BLUE)
        self.blue.action = GM.actionMove(self.board, self.state, self.inf_2, destination=self.inf_2.position)
        self.blue.response = GM.actionNoResponse(BLUE)

        self.mm = MatchManager('', self.red, self.blue)
Example #7
0
    def testIndirectFire(self):
        blocker = np.zeros(self.shape, 'uint8')
        blocker[2, 5] = TERRAIN_TYPE['CONCRETE_BUILDING'].level
        blocker[3, 5] = TERRAIN_TYPE['CONCRETE_BUILDING'].level
        self.board.addTerrain(blocker)

        # we replace the blue tank with an infantry so we can use the mortar for an indirect hit
        self.state.clearFigures(BLUE)
        blue_inf = buildFigure('Infantry', (4, 6), BLUE)
        self.state.addFigure(blue_inf)

        los_on_target = self.state.getLOS(blue_inf)
        self.los_inf = los_on_target[self.red_inf.index]

        self.assertFalse(GM.checkLine(self.board, self.state, self.los_inf), 'indirect: infantry has LOS on target')

        # self.blue_tank.kind = FigureType.INFANTRY

        self.assertTrue(
            GM.canShoot(self.board, self.state, self.red_inf, blue_inf, self.red_inf.weapons['MT']),
            'indirect: infantry cannot shot at the target'
        )
Example #8
0
def addFigure(state: GameState, team: str, fName: str, fData: dict) -> None:
    """
    Add figures to a state for the given team, if needed add the color scheme, and also add the loaded units if there
    are any.
    """
    # setup main figure
    s = stat(fData['status']) if 'status' in fData else stat('NO_EFFECT')
    figure: Figure = buildFigure(fData['type'], fData['position'], team, fName,
                                 s)

    # setup colors
    color = fData.get('color', None)
    if color:
        state.addChoice(team, color, figure)
    else:
        state.addFigure(figure)

    for x in fData.get('loaded', []):
        # parse loaded figures
        for lName, lData in x.items():
            # setup loaded figure
            lt = TMPL_FIGURES[lData['type']]
            lFigure = Figure(fData['position'], lName, team, lt['kind'])

            # add parameters to loaded figure
            for lk, lv in lt.items():
                if lk == 'weapons':
                    setup_weapons(lFigure, lv)
                else:
                    setattr(lFigure, lk, lv)

            if color:
                state.addChoice(team, color, lFigure)
            else:
                state.addFigure(lFigure)

            figure.transportLoad(lFigure)
Example #9
0
    def setUp(self):
        shape = (16, 16)
        self.board = GameBoard(shape)
        self.state = GameState(shape)

        self.inf_1 = buildFigure('Infantry', (5, 11), RED)
        self.inf_2 = buildFigure('Infantry', (7, 12), RED)

        self.target_1 = buildFigure('Infantry', (3, 13), BLUE)
        self.target_2 = buildFigure('Infantry', (5, 13), BLUE)
        self.target_3 = buildFigure('Infantry', (7, 13), BLUE)
        self.target_4 = buildFigure('Infantry', (9, 13), BLUE)

        self.state.addFigure(
            self.inf_1,
            self.inf_2,
            self.target_1,
            self.target_2,
            self.target_3,
            self.target_4,
        )
    def testMoveWithTransport(self):
        inf1 = buildFigure('Infantry', (7, 7), RED, 'Inf1', stat('NO_EFFECT'))
        inf2 = buildFigure('Infantry', (7, 8), RED, 'Inf2', stat('NO_EFFECT'))
        inf3 = buildFigure('Infantry', (7, 9), RED, 'Inf3', stat('NO_EFFECT'))

        # add infantry units
        self.state.addFigure(inf1)
        self.state.addFigure(inf2)
        self.state.addFigure(inf3)

        # load 2 units
        load1 = GM.actionLoadInto(self.board, self.state, inf1, self.tank)
        load2 = GM.actionLoadInto(self.board, self.state, inf2, self.tank)
        load3 = GM.actionLoadInto(self.board, self.state, inf3, self.tank)

        GM.step(self.board, self.state, load1)
        GM.step(self.board, self.state, load2)

        # load a third unit: cannot do that!
        self.assertRaises(ValueError, GM.step, self.board, self.state, load3)

        self.assertEqual(inf1.position, self.tank.position)
        self.assertEqual(inf2.position, self.tank.position)
        self.assertNotEqual(inf3.position, self.tank.position)

        # move figure in same position of tank
        move = GM.actionMove(self.board,
                             self.state,
                             inf3,
                             destination=self.tank.position)
        GM.step(self.board, self.state, move)

        figures = self.state.getFiguresByPos(RED, self.tank.position)
        self.assertEqual(len(figures), 4,
                         'not all figures are in the same position')
        self.assertEqual(inf1.transported_by, self.tank.index,
                         'Inf1 not in transporter')
        self.assertEqual(inf2.transported_by, self.tank.index,
                         'Inf2 not in transporter')
        self.assertEqual(inf3.transported_by, -1, 'Inf3 is in transporter')

        # move tank
        dst = Hex(8, 2).cube()
        move = GM.actionMove(self.board,
                             self.state,
                             self.tank,
                             destination=dst)
        GM.step(self.board, self.state, move)

        # figures moves along with tank
        self.assertEqual(inf1.position, self.tank.position,
                         'Inf1 not moved with transporter')
        self.assertEqual(inf2.position, self.tank.position,
                         'Inf2 not moved with transporter')
        self.assertEqual(len(self.tank.transporting), 2,
                         'Transporter not transporting all units')

        self.assertGreater(inf1.transported_by, -1)

        # unload 1 figure
        dst = Hex(8, 4).cube()
        move = GM.actionMove(self.board, self.state, inf1, destination=dst)
        GM.step(self.board, self.state, move)

        self.assertEqual(len(self.tank.transporting), 1,
                         'transporter has less units than expected')
        self.assertNotEqual(
            inf1.position, self.tank.position,
            'Inf1 has not been moved together with transporter')