Example #1
0
    def wolf_action(self, actions, rewards):
        """
        Perform wolf action, that is kill agent based on votes and reward
        :param actions: dict, map id to vote
        :param rewards: dict, maps agent id to curr reward
        :return: updated rewards
        """

        # get wolves ids
        wolves_ids = self.get_ids(ww, alive=True)
        # filter action to get only wolves
        actions = {k: v for k, v in actions.items() if k in wolves_ids}

        # upvote suicide info
        self.infos["suicide"] += suicide_num(actions)

        if not len(wolves_ids):
            raise Exception("Game not done but wolves are dead")

        # get choices by wolves
        actions = [actions[id] for id in wolves_ids]

        logger.debug(f"wolves votes :{actions}")

        # get agent to be eaten
        target = most_frequent(actions)
        # if target is alive
        if self.status_map[target]:
            # kill him
            self.status_map[target] = 0
            # penalize dead player
            rewards[target] += self.penalties.get("death")
            # reward wolves
            for id in wolves_ids:
                rewards[id] += self.penalties.get("kill")
            logger.debug(f"Wolves killed {target} ({self.role_map[target]})")



        else:
            logger.debug(f"Wolves tried to kill dead agent {target}")
            # penalize the wolves for eating a dead player
            for id in wolves_ids:
                rewards[id] += self.penalties.get('execute_dead')
            # log it
            self.infos["dead_man_kill"] += 1

        if target in wolves_ids:
            # penalize the agent for eating one of their kind
            for id in wolves_ids:
                rewards[id] += self.penalties.get('kill_wolf')
            # log it
            self.infos["cannibalism"] += 1

        return rewards
Example #2
0
        def execution(actions, rewards):
            """
            To be called when is execution phase
            :return:
            """

            self.custom_metrics["suicide"] += suicide_num(actions)

            # get the agent to be executed
            target = most_frequent(actions)

            # penalize for non divergent target
            rewards = self.target_accord(target, rewards,
                                         self.get_ids("all", alive=True))

            # if target is alive
            if self.status_map[target]:
                # log
                logger.debug(
                    f"Player {target} ({self.role_map[target]}) has been executed"
                )

                # for every agent alive, [to be executed agent too]
                for id_ in [
                        elem for elem in rewards.keys()
                        if self.status_map[elem]
                ]:
                    # add/subtract penalty
                    if id_ == target:
                        rewards[id_] += self.penalties.get("death")
                    else:
                        rewards[id_] += self.penalties.get("execution")

                # kill target
                self.status_map[target] = 0
            else:
                # penalize agents for executing a dead one
                for id_ in self.get_ids("all", alive=True):
                    rewards[id_] += self.penalties.get('execute_dead')
                logger.debug(f"Players tried to execute dead agent {target}")

                # increase the number of dead_man_execution in info
                self.custom_metrics["dead_man_execution"] += 1

            # update day
            self.day_count += 1

            return rewards
Example #3
0
    def day(self, actions, rewards):
        """
        Run the day phase, that is execute target based on votes and reward accordingly
        :param actions: dict, map id to vote
        :param rewards: dict, maps agent id to curr reward
        :return: updated rewards
        """

        # update vote list
        for idx in range(self.num_players):
            # use -1 if agent is dead
            self.votes[idx] = actions.get(idx, -1)

        self.infos["suicide"] += suicide_num(actions)

        # get the agent to be executed
        target = most_frequent(actions)
        logger.debug(f"Villagers votes {[elem for elem in actions.values()]}")

        # if target is alive
        if self.status_map[target]:
            # log
            logger.debug(f"Player {target} ({self.role_map[target]}) has been executed")
            # kill target
            self.status_map[target] = 0

            # for every agent alive
            for id in [elem for elem in rewards.keys() if self.status_map[elem]]:
                # add/subtract penalty
                if id == target:
                    rewards[id] += self.penalties.get("death")
                else:
                    rewards[id] += self.penalties.get("execution")
        else:
            # penalize agents for executing a dead one
            for id in self.get_ids("all", alive=True):
                rewards[id] += self.penalties.get('execute_dead')
            logger.debug(f"Players tried to execute dead agent {target}")

            # increase the number of dead_man_execution in info
            self.infos["dead_man_execution"] += 1

        # update day
        self.day_count += 1

        return rewards
Example #4
0
        def kill(actions, rewards):

            # upvote suicide info
            self.custom_metrics["suicide"] += suicide_num(actions)

            if not len(wolves_ids):
                raise Exception(
                    "Game not done but wolves are dead, have reset been called?"
                )

            # get agent to be eaten
            target = most_frequent(actions)

            # penalize for different ids
            rewards = self.target_accord(target, rewards, wolves_ids)

            # if target is alive
            if self.status_map[target]:
                # kill him
                self.status_map[target] = 0
                # penalize dead player
                rewards[target] += self.penalties.get("death")
                # reward wolves
                for id_ in wolves_ids:
                    rewards[id_] += self.penalties.get("kill")
                logger.debug(
                    f"Wolves killed {target} ({self.role_map[target]})")

            else:
                logger.debug(f"Wolves tried to kill dead agent {target}")
                # penalize the wolves for eating a dead player
                for id_ in wolves_ids:
                    rewards[id_] += self.penalties.get('execute_dead')
                # log it
                self.custom_metrics["dead_man_kill"] += 1

            if target in wolves_ids:
                # penalize the agent for eating one of their kind
                for id_ in wolves_ids:
                    rewards[id_] += self.penalties.get('kill_wolf')
                # log it
                self.custom_metrics["cannibalism"] += 1

            return rewards
Example #5
0
        def kill(actions, rewards):

            if not len(wolves_ids):
                raise Exception(
                    "Game not done but wolves are dead, have reset been called?"
                )

            # get agent to be eaten
            target = most_frequent(actions)

            # penalize for different ids
            rewards = self.target_accord(target, rewards, actions)

            # kill agent and remember
            self.status_map[target] = 0
            self.just_died = target

            # penalize dead player
            rewards[target] += self.penalties.get("death")

            return rewards
Example #6
0
        def execution(actions, rewards):
            """
            To be called when is execution phase
            :return:
            """

            # get the agent to be executed
            target = most_frequent(actions)

            # penalize for non divergent target
            rewards = self.target_accord(target, rewards, actions)

            # penalize target agent
            rewards[target] += self.penalties.get("death")

            # kill him
            self.status_map[target] = 0
            self.just_died = target

            # update day
            self.day_count += 1

            return rewards