Example #1
0
        void Night()
        {
            foreach (var agent in AliveAgentList)
            {
                gameServer.DayFinish(agent);
            }

            if (!gameSetting.TalkOnFirstDay && Day == 0)
            {
                Whisper();
            }

            Agent executed = null;

            if (Day != 0)
            {
                IList <Agent> candidates = null;
                for (var i = 0; i <= gameSetting.MaxRevote; i++)
                {
                    Vote();
                    candidates = GetVotedCandidates(gameData.VoteList);
                    if (candidates.Count == 1)
                    {
                        executed = candidates[0];
                        break;
                    }
                }

                // In case of multiple candidates.
                if (executed == null && !gameSetting.EnableNoExecution)
                {
                    executed = candidates.Shuffle().First();
                }

                if (executed != null)
                {
                    gameData.Executed = executed;
                    if (GameLogger != null)
                    {
                        GameLogger.Log($"{Day},execute,{executed.AgentIdx},{RoleOf(executed)}");
                    }
                }
            }

            Divine();

            if (Day != 0)
            {
                Whisper();
                Guard();

                Agent attacked = null;
                if (AliveWolfList.Count > 0)
                {
                    IList <Agent> candidates = null;
                    for (var i = 0; i <= gameSetting.MaxAttackRevote; i++)
                    {
                        if (i > 0 && gameSetting.WhisperBeforeRevote)
                        {
                            Whisper();
                        }
                        AttackVote();
                        candidates = GetAttackVotedCandidates(gameData.AttackVoteList.Where(v => v.Agent != executed).ToList());
                        if (candidates.Count == 1)
                        {
                            attacked = candidates[0];
                            break;
                        }
                    }

                    // In case of multiple candidates.
                    if (attacked == null && !gameSetting.EnableNoAttack)
                    {
                        attacked = candidates.Shuffle().First();
                    }

                    gameData.Attacked = attacked;

                    var guarded = false;
                    if (gameData.Guard != null)
                    {
                        if (gameData.Guard.Target == attacked && attacked != null)
                        {
                            if (gameData.Executed == null || gameData.Executed != gameData.Guard.Agent)
                            {
                                guarded = true;
                            }
                        }
                    }
                    if (!guarded && attacked != null && RoleOf(attacked) != Role.FOX)
                    {
                        gameData.AttackedDead = attacked;
                        gameData.AddLastDeadAgent(attacked);
                        if (GameLogger != null)
                        {
                            GameLogger.Log($"{Day},attack,{attacked.AgentIdx},true");
                        }
                    }
                    else if (attacked != null)
                    {
                        if (GameLogger != null)
                        {
                            GameLogger.Log($"{Day},attack,{attacked.AgentIdx},false");
                        }
                    }
                    else
                    {
                        if (GameLogger != null)
                        {
                            GameLogger.Log($"{Day},attack,-1,false");
                        }
                    }
                }
            }
            gameData            = gameData.NextDay;
            gameServer.GameData = gameData;
        }
Example #2
0
        public void Night()
        {
            foreach (Agent agent in gameData.AgentList)
            {
                gameServer.DayFinish(agent);
            }

            //Vote
            List <Vote> voteList = gameData.VoteList;
            Agent       executed = GetVotedAgent(voteList);

            if (executed != null)
            {
                if (gameData.GetStatus(executed) == Status.ALIVE && gameData.Day != 0)
                {
                    gameData.Executed = executed;
                    if (GameLogger != null)
                    {
                        GameLogger.Log(string.Format("{0},execute,{1},{2}", gameData.Day, executed.AgentIdx, gameData.GetRole(executed)));
                    }
                }

                //Attack
                if (!(AliveWolfList.Count == 1 && gameData.GetRole(gameData.Executed) == Role.WEREWOLF) && gameData.Day != 0)
                {
                    List <Vote> attackCandidateList = gameData.AttackVoteList;
                    attackCandidateList.RemoveAll(v => v.Agent == executed);

                    Agent attacked = GetAttackVotedAgent(attackCandidateList);
                    if (attacked == executed)
                    {
                        attacked = null;
                    }

                    bool isGuarded = false;
                    if (gameData.Guard != null)
                    {
                        if (gameData.Guard.Target.Equals(attacked) && attacked != null)
                        {
                            if (gameData.Executed == null || !gameData.Executed.Equals(gameData.Guard.Agent))
                            {
                                isGuarded = true;
                            }
                        }
                    }
                    if (!isGuarded && attacked != null)
                    {
                        gameData.Attacked = attacked;
                        if (GameLogger != null)
                        {
                            GameLogger.Log(string.Format("{0},attack,{1},true", gameData.Day, attacked.AgentIdx));
                        }
                    }
                    else if (attacked != null)
                    {
                        if (GameLogger != null)
                        {
                            GameLogger.Log(string.Format("{0},attack,{1},false", gameData.Day, attacked.AgentIdx));
                        }
                    }
                    else
                    {
                        if (GameLogger != null)
                        {
                            GameLogger.Log(string.Format("{0},attack,-1,false", gameData.Day));
                        }
                    }
                }
            }
            gameData = gameData.NextDay();
            gameDataMap[gameData.Day] = gameData;
            gameServer.SetGameData(gameData);
        }