Example #1
0
    def create(self, conf):
        assert isinstance(conf, BaseConfiguration)
        game_map = Map(width=conf.map_width,
                       height=conf.map_height,
                       default_field=conf.default_empty_map_field)

        if game_map.width * game_map.height < sum((conf.bots, conf.treasures, conf.blocks)):
            raise InvalidMapError('Cannot place {} bots, {} treasures and {} blocks into {}x{} map.'
                                  .format(conf.bots, conf.treasures, conf.blocks, game_map.width, game_map.height))

        for _i in range(conf.treasures):
            treasure = TreasureField()
            position = random_position(game_map)
            while not isinstance(game_map[position], EmptyField):
                position = random_position(game_map)
            game_map[position] = treasure

        for _i in range(conf.bots):
            bot = BotField(Orientation.NORTH)
            position = random_position(game_map)
            while not isinstance(game_map[position], EmptyField):
                position = random_position(game_map)
            game_map[position] = bot

        self._place_blocks_to_map(game_map, blocks=conf.blocks)
        return game_map
Example #2
0
 def _place_blocks_to_map(self, game_map, blocks):
     for _i in range(blocks):
         block = BlockField()
         position = random_position(game_map)
         while not isinstance(game_map[position], EmptyField):
             position = random_position(game_map)
         game_map[position] = block
 def place_bots(self, game_map=None, count=None, field_class=BotField, *args, **kwargs):
     self._check_place_args(game_map, count, field_class)
     for _ in range(count):
         bot = field_class(Orientation.NORTH)
         position = random_position(game_map)
         while not isinstance(game_map[position], self.default_empty_map_field):
             position = random_position(game_map)
         game_map[position] = bot
 def place_blocks(self, game_map=None, count=None, field_class=BlockField, *args, **kwargs):
     self._check_place_args(game_map, count, field_class)
     for _i in range(count):
         block = field_class()
         position = random_position(game_map)
         while not isinstance(game_map[position], self.default_empty_map_field):
             position = random_position(game_map)
         game_map[position] = block
    def place_treasures(self, game_map=None, count=None, field_class=TreasureField, *args, **kwargs):
        self._check_place_args(game_map, count, field_class)

        def random(a, b):
            return int(triangular(a, b))

        for _ in range(count):
            treasure = field_class()
            position = random_position(game_map)
            while not isinstance(game_map[position], self.default_empty_map_field):
                position = random_position(game_map, fce=random)
            game_map[position] = treasure
Example #6
0
 def place_blocks(self,
                  game_map=None,
                  count=None,
                  field_class=BlockField,
                  *args,
                  **kwargs):
     self._check_place_args(game_map, count, field_class)
     for _i in range(count):
         block = field_class()
         position = random_position(game_map)
         while not isinstance(game_map[position],
                              self.default_empty_map_field):
             position = random_position(game_map)
         game_map[position] = block
Example #7
0
 def place_bots(self,
                game_map=None,
                count=None,
                field_class=BotField,
                *args,
                **kwargs):
     self._check_place_args(game_map, count, field_class)
     for _i in range(count):
         bot = field_class(Orientation.NORTH)
         position = random_position(game_map)
         while not isinstance(game_map[position],
                              self.default_empty_map_field):
             position = random_position(game_map)
         game_map[position] = bot