Exemplo n.º 1
0
    def test_get_positions_in_row(self):
        game_map = Map(width=3, height=3)

        with self.assertRaises(AssertionError):
            next(get_positions_in_row(None, (0, 0), Orientation.WEST))

        with self.assertRaises(AssertionError):
            next(get_positions_in_row(game_map, None, Orientation.WEST))

        with self.assertRaises(AssertionError):
            next(get_positions_in_row(game_map, (0, 0), None))

        with self.assertRaises(AssertionError):
            next(
                get_positions_in_row(game_map, (0, 0),
                                     Orientation.WEST,
                                     limit='foobar'))

        self.assertEqual(
            tuple(get_positions_in_row(game_map, (0, 0), Orientation.SOUTH)),
            ((0, 1), (0, 2)))

        self.assertEqual(
            tuple(get_positions_in_row(game_map, (0, 0), Orientation.WEST)),
            ())

        self.assertEqual(
            tuple(
                get_positions_in_row(game_map, (0, 0),
                                     Orientation.SOUTH,
                                     limit=1)), ((0, 1), ))
Exemplo n.º 2
0
    def _action_laser_beam(self, bot_field, bot_position, **kwargs):
        if not self._configuration.laser_game:
            raise ActionError('This game is not a laser game.')

        assert isinstance(bot_field, LaserBatteryBotField)
        try:
            bot_field.drain(bot_field.laser_battery_cost)
        except CriticalBatteryLevel:
            raise

        for position in get_positions_in_row(self.map, bot_position, bot_field.orientation):
            field = self.map[position]
            if isinstance(field, self._configuration.default_empty_map_field):
                continue
            if isinstance(field, LaserBatteryBotField):
                field.drain(bot_field.laser_damage)
                break
            if isinstance(field, BlockField):
                self.map[position] = self._configuration.default_empty_map_field()
                break
Exemplo n.º 3
0
    def _action_laser_beam(self, bot_field, bot_position, **kwargs):
        if not self._configuration.laser_game:
            raise ActionError('This game is not a laser game.')

        assert isinstance(bot_field, LaserBatteryBotField)
        try:
            bot_field.drain(bot_field.laser_battery_cost)
        except CriticalBatteryLevel:
            raise

        for position in get_positions_in_row(self.map, bot_position,
                                             bot_field.orientation):
            field = self.map[position]
            if isinstance(field, self._configuration.default_empty_map_field):
                continue
            if isinstance(field, LaserBatteryBotField):
                field.drain(bot_field.laser_damage)
                break
            if isinstance(field, BlockField):
                self.map[
                    position] = self._configuration.default_empty_map_field()
                break
Exemplo n.º 4
0
    def test_get_positions_in_row(self):
        game_map = Map(width=3, height=3)

        with self.assertRaises(AssertionError):
            next(get_positions_in_row(None, (0, 0), Orientation.WEST))

        with self.assertRaises(AssertionError):
            next(get_positions_in_row(game_map, None, Orientation.WEST))

        with self.assertRaises(AssertionError):
            next(get_positions_in_row(game_map, (0, 0), None))

        with self.assertRaises(AssertionError):
            next(get_positions_in_row(game_map, (0, 0), Orientation.WEST, limit="foobar"))

        self.assertEqual(tuple(get_positions_in_row(game_map, (0, 0), Orientation.SOUTH)), ((0, 1), (0, 2)))

        self.assertEqual(tuple(get_positions_in_row(game_map, (0, 0), Orientation.WEST)), ())

        self.assertEqual(tuple(get_positions_in_row(game_map, (0, 0), Orientation.SOUTH, limit=1)), ((0, 1),))