Beispiel #1
0
    def get_delta(self, actions, spawn=True):
        delta = []

        def dest(loc):
            if actions[loc][0] == 'move':
                return actions[loc][1]
            else:
                return loc

        contenders = self._get_contenders(dest)
        new_locations = self._get_new_locations(dest, contenders)
        collisions = self._get_collisions(dest, contenders)
        damage_map = self._get_damage_map(actions)
        damage_caused = defaultdict(lambda: 0)  # {loc: damage_caused}

        for loc, robot in list(self.robots.items()):
            robot_delta = AttrDict({
                'loc': loc,
                'hp': robot.hp,
                'player_id': robot.player_id,
                'loc_end': new_locations[loc],
                'hp_end': robot.hp,  # to be adjusted
                'damage_caused': 0  # to be adjusted
            })

            is_guard = actions[loc][0] == 'guard'

            # collision damage
            if not is_guard:
                damage = settings.collision_damage

                for other_loc in collisions[loc]:
                    if robot.player_id != self.robots[other_loc].player_id:
                        robot_delta.hp_end -= damage
                        damage_caused[other_loc] += damage

            # attack and suicide damage
            for player_id, player_damage_map in enumerate(
                    damage_map[new_locations[loc]]):
                if player_id != robot.player_id:
                    for actor_loc, damage in list(player_damage_map.items()):
                        if is_guard:
                            damage //= 2

                        robot_delta.hp_end -= damage
                        damage_caused[actor_loc] += damage

            # account for suicides
            if actions[loc][0] == 'suicide':
                robot_delta.hp_end = 0

            delta.append(robot_delta)

        self._apply_damage_caused(delta, damage_caused)

        if spawn and self.turn % settings.spawn_every == 0:
            self._apply_spawn(delta, self._get_spawn_locations())

        return delta
Beispiel #2
0
    def get_delta(self, actions, spawn=True):
        delta = []

        def dest(loc):
            if actions[loc][0] == 'move':
                return actions[loc][1]
            else:
                return loc

        contenders = self._get_contenders(dest)
        new_locations = self._get_new_locations(dest, contenders)
        collisions = self._get_collisions(dest, contenders)
        damage_map = self._get_damage_map(actions)
        damage_caused = defaultdict(lambda: 0)  # {loc: damage_caused}

        for loc, robot in self.robots.iteritems():
            robot_delta = AttrDict({
                'loc': loc,
                'hp': robot.hp,
                'player_id': robot.player_id,
                'loc_end': new_locations[loc],
                'hp_end': robot.hp,  # to be adjusted
                'damage_caused': 0  # to be adjusted
            })

            is_guard = actions[loc][0] == 'guard'

            # collision damage
            if not is_guard:
                damage = settings.collision_damage

                for other_loc in collisions[loc]:
                    if robot.player_id != self.robots[other_loc].player_id:
                        robot_delta.hp_end -= damage
                        damage_caused[other_loc] += damage

            # attack and suicide damage
            for player_id, player_damage_map in enumerate(
                    damage_map[new_locations[loc]]):
                if player_id != robot.player_id:
                    for actor_loc, damage in player_damage_map.iteritems():
                        if is_guard:
                            damage /= 2

                        robot_delta.hp_end -= damage
                        damage_caused[actor_loc] += damage

            # account for suicides
            if actions[loc][0] == 'suicide':
                robot_delta.hp_end = 0

            delta.append(robot_delta)

        self._apply_damage_caused(delta, damage_caused)

        if spawn and self.turn % settings.spawn_every == 0:
            self._apply_spawn(delta)

        return delta
Beispiel #3
0
    def get_game_info(self, player_id):
        game_info = AttrDict()

        game_info.robots = dict((loc, AttrDict(robot))
                                for loc, robot in self.robots.iteritems())
        for robot in game_info.robots.itervalues():
            if robot.player_id != player_id:
                del robot.robot_id

        game_info.turn = self.turn

        return game_info
Beispiel #4
0
    def get_game_info(self, player_id):
        game_info = AttrDict()

        game_info.robots = dict(
            (loc, AttrDict(robot)) for loc, robot in self.robots.iteritems())
        for robot in game_info.robots.itervalues():
            if robot.player_id != player_id:
                del robot.robot_id

        game_info.turn = self.turn

        return game_info
Beispiel #5
0
    def add_robot(self, loc, player_id, hp=None, robot_id=None):
        if hp is None:
            hp = settings.robot_hp

        if robot_id is None:
            robot_id = self._next_robot_id
            self._next_robot_id += 1

        self.robots[self._loc_from_json(loc)] = AttrDict({
            'location': self._loc_from_json(loc),
            'hp': int(hp),
            'player_id': int(player_id),
            'robot_id': int(robot_id),
        })
Beispiel #6
0
    def add_robot(self, loc, player_id, hp=None, robot_id=None):
        if hp is None:
            hp = settings.robot_hp

        if robot_id is None:
            robot_id = self._next_robot_id
            self._next_robot_id += 1

        self.robots[loc] = AttrDict({
            'location': loc,
            'hp': hp,
            'player_id': player_id,
            'robot_id': robot_id
        })
Beispiel #7
0
    def _apply_spawn(delta, spawn_locations):
        # clear robots on spawn
        for robot_delta in delta:
            if robot_delta.loc_end in settings.spawn_coords:
                robot_delta.hp_end = 0

        # spawn robots
        for i in range(settings.spawn_per_player):
            for player_id in range(settings.player_count):
                loc = spawn_locations[player_id*settings.spawn_per_player+i]
                delta.append(AttrDict({
                    'loc': loc,
                    'hp': 0,
                    'player_id': player_id,
                    'loc_end': loc,
                    'hp_end': settings.robot_hp,
                    'damage_caused': 0
                }))
Beispiel #8
0
    def get_game_info(self, player_id=None, json=None, seed=None):
        game_info = AttrDict()

        if json:
            game_info.robots = list(self.robots.values())
        else:
            game_info.robots = dict((loc, AttrDict(robot))
                                    for loc, robot in self.robots.items())

        if player_id is not None:
            for robot in game_info.robots.values():
                if robot.player_id != player_id:
                    del robot.robot_id

        if seed:
            game_info.seed = self._seed

        game_info.turn = self.turn
        if json:
            game_info.turn = str(game_info.turn)

        return game_info
Beispiel #9
0
settings = AttrDict({
    'FPS': 60,  # frames per second
    'turn_interval': 300,  # milliseconds per turn

    # colors
    'colors': [(0.49, 0.14, 0.14), (0.14, 0.14, 0.49)],
    'color_guard': None,  # (0.0, 0.14, 0.0),
    'color_guard_border': (0.0, 0.49, 0.0),
    # 'colors': [(0.9, 0, 0.2), (0, 0.9, 0.2)],
    'obstacle_color': (.2, .2, .2),
    'text_color': (0.6, 0.6, 0.6),  # for labelling rows/columns
    'text_color_dark': (0.1, 0.1, 0.1),  # HP color when bots are bright
    'text_color_bright': (0.9, 0.9, 0.9),  # HP color when bots are dark
    'normal_color': (.9, .9, .9),
    'highlight_color': (0.6, 0.6, 0.6),
    'target_color': (0.6, 0.6, 1),

    # highlighting
    'clear_highlight_between_turns': False,
    # 'clear_highlight_between_turns': True,
    'clear_highlight_target_between_turns': True,
    'highlight_cursor_blink': True,
    'rate_cursor_blink': 1000,
    # 'highlight_cursor_blink': True,
    'highlight_cursor_blink_interval': 0.5,

    'bot_shape': 'square',
    # 'bot_shape': 'circle',
    'draw_movement_arrow': True,
    # 'draw_movement_arrow': False,

    # animations (only enabled if -A is used)
    'bot_die_animation': True,
    'bot_move_animation': False,
    'bot_suicide_animation': False,
    'bot_hp_animation': False,
})