def test_battery_setter(self):
        battery_level = randint(0, 100)
        bot = LaserBatteryBotField(battery_level=battery_level)

        with self.assertRaises(CriticalBatteryLevel):
            while True:
                bot.drain(1)
    def test_battery_charging(self):
        battery_level = randint(10, 100)
        bot = LaserBatteryBotField(battery_level=battery_level)
        bot.charge(bot.battery_charge)
        self.assertEqual(bot.actual_battery_level, battery_level + bot.battery_charge)

        bot.charge(2)
        self.assertEqual(bot.actual_battery_level, battery_level + bot.battery_charge + 2)
 def test_export(self):
     battery_level = randint(0, 100)
     bot = LaserBatteryBotField(battery_level=battery_level, name='Tester')
     self.assertEqual(bot.export(), {
         FIELD_KEY: Field.LASER_BATTERY_BOT,
         'orientation': LaserBatteryBotField.DEFAULT_ORIENTATION,
         'battery_level': battery_level,
         'name': 'Tester'
     }, 'Battery bot field export.')
    def test_battery_draining(self):
        battery_level = randint(10, 100)
        bot = LaserBatteryBotField(battery_level=battery_level)
        bot.drain(LaserBatteryBotField.DEFAULT_STEP_BATTERY_COST)
        self.assertEqual(bot.actual_battery_level, battery_level - LaserBatteryBotField.DEFAULT_STEP_BATTERY_COST)

        bot.drain(LaserBatteryBotField.DEFAULT_LASER_BATTERY_COST)
        self.assertEqual(bot.actual_battery_level, battery_level -
                         LaserBatteryBotField.DEFAULT_STEP_BATTERY_COST -
                         LaserBatteryBotField.DEFAULT_LASER_BATTERY_COST)
Esempio n. 5
0
    def test_laser_beam_bot_fight(self):
        class Conf(BaseConfiguration, RandomFieldPlacerMixin):
            map_width = 1
            map_height = 3
            bots = 1
            treasures = 0
            blocks = 0
            battery_game = True
            laser_game = True

        conf = Conf()
        game_map = Map(width=3, height=1)
        fake_map = [
            [LaserBatteryBotField(Orientation.SOUTH)],
            [EmptyField()],
            [LaserBatteryBotField(Orientation.NORTH)]
        ]
        setattr(game_map, '_{}__map'.format(game_map.__class__.__name__), fake_map)
        game = Game(game_map, configuration=conf)
        bot_id = 1
        game._bots_positions = {
            bot_id: (0, 0)
        }

        game.action(bot_id, Action.LASER_BEAM)
        self.assertIsInstance(
            game.map[0, 0],
            LaserBatteryBotField
        )
        self.assertIsInstance(
            game.map[0, 1],
            EmptyField
        )
        self.assertIsInstance(
            game.map[0, 2],
            LaserBatteryBotField
        )

        defender = game.map[0, 2]
        assert isinstance(defender, LaserBatteryBotField)
        self.assertEqual(
            LaserBatteryBotField.DEFAULT_BATTERY_LEVEL - LaserBatteryBotField.DEFAULT_LASER_DAMAGE,
            defender.actual_battery_level
        )
        attacker = game.map[0, 0]
        assert isinstance(attacker, LaserBatteryBotField)
        self.assertEqual(
            LaserBatteryBotField.DEFAULT_BATTERY_LEVEL - LaserBatteryBotField.DEFAULT_LASER_BATTERY_COST,
            attacker.actual_battery_level
        )
    def test_battery_charging(self):
        battery_level = randint(10, 100)
        bot = LaserBatteryBotField(battery_level=battery_level)
        bot.charge(bot.battery_charge)
        self.assertEqual(bot.actual_battery_level,
                         battery_level + bot.battery_charge)

        bot.charge(2)
        self.assertEqual(bot.actual_battery_level,
                         battery_level + bot.battery_charge + 2)
Esempio n. 7
0
    def test_charging_battery_in_battery_game(self):
        class Conf(BaseConfiguration, RandomFieldPlacerMixin):
            map_width = 1
            map_height = 3
            bots = 1
            treasures = 0
            blocks = 0
            battery_game = True

        conf = Conf()
        game_map = Map(width=3, height=1)
        fake_map = [
            [LaserBatteryBotField(Orientation.EAST)],
            [EmptyField()],
            [EmptyField()]
        ]
        setattr(game_map, '_{}__map'.format(game_map.__class__.__name__), fake_map)
        game = Game(game_map, configuration=conf)

        my_bot_id = 1

        game.add_bot(my_bot_id)
        bot_field = game.map[game._bots_positions[my_bot_id]]

        game.action(my_bot_id, Action.TURN_RIGHT)
        assert isinstance(bot_field, LaserBatteryBotField)
        self.assertEqual(LaserBatteryBotField.DEFAULT_BATTERY_LEVEL,
                         bot_field.actual_battery_level,
                         'Default battery level')

        game.action(my_bot_id, Action.STEP)

        self.assertEqual(LaserBatteryBotField.DEFAULT_BATTERY_LEVEL - 1,
                         bot_field.actual_battery_level,
                         'Drained battery level')

        game.action(my_bot_id, Action.WAIT)

        self.assertEqual(LaserBatteryBotField.DEFAULT_BATTERY_LEVEL,
                         bot_field.actual_battery_level,
                         'Charged battery level to default.')

        game.action(my_bot_id, Action.WAIT)

        self.assertEqual(LaserBatteryBotField.DEFAULT_BATTERY_LEVEL + 1,
                         bot_field.actual_battery_level,
                         'Charged battery level to higher level than default.')
    def test_battery_draining(self):
        battery_level = randint(10, 100)
        bot = LaserBatteryBotField(battery_level=battery_level)
        bot.drain(LaserBatteryBotField.DEFAULT_STEP_BATTERY_COST)
        self.assertEqual(
            bot.actual_battery_level,
            battery_level - LaserBatteryBotField.DEFAULT_STEP_BATTERY_COST)

        bot.drain(LaserBatteryBotField.DEFAULT_LASER_BATTERY_COST)
        self.assertEqual(
            bot.actual_battery_level,
            battery_level - LaserBatteryBotField.DEFAULT_STEP_BATTERY_COST -
            LaserBatteryBotField.DEFAULT_LASER_BATTERY_COST)
Esempio n. 9
0
    def test_draining_battery_in_battery_game(self):
        class Conf(BaseConfiguration, RandomFieldPlacerMixin):
            map_width = 12
            map_height = 1
            bots = 1
            treasures = 0
            blocks = 0
            battery_game = True

        conf = Conf()
        game_map = Map(width=12, height=1)
        fake_map = [
            [LaserBatteryBotField(Orientation.SOUTH)],
        ]
        fake_map.extend([[EmptyField()] for _ in range(11)])
        setattr(game_map, '_{}__map'.format(game_map.__class__.__name__), fake_map)
        game = Game(game_map, configuration=conf)

        bot_id = 1
        game.add_bot(bot_id)
        with self.assertRaises(CriticalBatteryLevel):
            while True:
                game.action(bot_id, Action.STEP)
Esempio n. 10
0
    def test_laser_beam_action_block_destroy(self):
        class Conf(BaseConfiguration, RandomFieldPlacerMixin):
            map_width = 1
            map_height = 3
            bots = 1
            treasures = 0
            blocks = 0
            battery_game = True
            laser_game = True

        conf = Conf()
        game_map = Map(width=3, height=1)
        fake_map = [
            [LaserBatteryBotField(Orientation.SOUTH)],
            [EmptyField()],
            [BlockField()]
        ]
        setattr(game_map, '_{}__map'.format(game_map.__class__.__name__), fake_map)
        game = Game(game_map, configuration=conf)
        bot_id = 1

        game.action(bot_id, Action.LASER_BEAM)
        self.assertIsInstance(
            game.map[0, 0],
            LaserBatteryBotField
        )
        self.assertIsInstance(
            game.map[0, 1],
            EmptyField
        )
        self.assertIsInstance(
            game.map[0, 2],
            EmptyField
        )
        with self.assertRaises(MovementError):
            while True:
                game.action(bot_id, Action.LASER_BEAM)
 def test_init(self):
     battery_level = randint(0, 100)
     bot = LaserBatteryBotField(battery_level=battery_level)
     self.assertEqual(bot.actual_battery_level, battery_level,
                      'Bot has to save battery level.')