void Divine() { foreach (var agent in AliveAgentList.Where(a => RoleOf(a) == Role.SEER)) { var target = gameServer.RequestDivineTarget(agent); var targetRole = RoleOf(target); if (target == null || StatusOf(target) == Status.DEAD || targetRole == Role.UNC) { // Do nothing. } else { var divine = new Judge(Day, agent, target, targetRole.GetSpecies()); gameData.Divine = divine; if (targetRole == Role.FOX) { gameData.AddLastDeadAgent(target); gameData.CursedFox = target; } if (GameLogger != null) { GameLogger.Log($"{Day},divine,{agent.AgentIdx},{target.AgentIdx},{divine.Result}"); } } } }
void Guard() { foreach (var agent in AliveAgentList.Where(a => RoleOf(a) == Role.BODYGUARD)) { if (agent == gameData.Executed) { continue; } var target = gameServer.RequestGuardTarget(agent); if (target == null || agent == target) { // Do nothing. } else { var guard = new Guard(Day, agent, target); gameData.Guard = guard; if (GameLogger != null) { GameLogger.Log($"{Day},guard,{agent.AgentIdx},{target.AgentIdx},{RoleOf(target)}"); } } } }
/// <summary> /// First, all agents have chances to talk. /// Next, wolves whispers. /// Continue them until all agents finish talking. /// </summary> public void Talk() { List <Agent> overList = new List <Agent>(); for (int i = 0; i < gameSetting.MaxTalk; i++) { bool continueTalk = false; List <Agent> aliveList = AliveAgentList.Union(overList).Shuffle().ToList(); foreach (Agent agent in aliveList) { if (overList.Contains(agent)) { continue; } string talkContent = gameServer.RequestTalk(agent); if (talkContent != null) { if (talkContent.Length != 0) { Talk sentence = new Talk(gameData.NextTalkIdx, gameData.Day, agent, talkContent); gameData.AddTalk(agent, sentence); if (!talkContent.Equals(Common.Data.Talk.OVER)) { continueTalk = true; overList.Clear(); } else { overList.Add(agent); } if (GameLogger != null) { GameLogger.Log(string.Format("{0},talk,{1},{2},{3}", gameData.Day, sentence.Idx, agent.AgentIdx, sentence.Content)); } } } } Whisper(); if (!continueTalk) { break; } } }
/// <summary> /// Whisper by werewolf. /// </summary> public void Whisper() { List <Agent> overList = new List <Agent>(); for (int j = 0; j < gameSetting.MaxTalk; j++) { bool continueWhisper = false; List <Agent> aliveList = AliveAgentList.Union(overList).Shuffle().ToList(); foreach (Agent agent in aliveList) { if (gameData.GetRole(agent) == Role.WEREWOLF) { if (overList.Contains(agent)) { continue; } string whisperContent = gameServer.RequestWhisper(agent); if (whisperContent != null && whisperContent.Length != 0) { Talk whisper = new Talk(gameData.NextWhisperIdx, gameData.Day, agent, whisperContent); gameData.AddWhisper(agent, whisper); if (!whisperContent.Equals(Common.Data.Talk.OVER)) { continueWhisper = true; overList.Clear(); } else { overList.Add(agent); } if (GameLogger != null) { GameLogger.Log(string.Format("{0},whisper,{1},{2},{3}", gameData.Day, whisper.Idx, agent.AgentIdx, whisper.Content)); } } } } if (!continueWhisper) { break; } } }
void Vote() { gameData.VoteList.Clear(); foreach (var agent in AliveAgentList) { var target = gameServer.RequestVote(agent); if (target == null || StatusOf(target) == Status.DEAD || agent == target) { target = AliveAgentList.Where(a => a != agent).Shuffle().First(); } var vote = new Vote(Day, agent, target); gameData.VoteList.Add(vote); if (GameLogger != null) { GameLogger.Log($"{Day},vote,{agent.AgentIdx},{target.AgentIdx}"); } } gameData.LatestVoteList = new List <Vote>(gameData.VoteList); }
void Talk() { foreach (var agent in AliveAgentList) { gameData.RemainTalkMap[agent] = gameSetting.MaxTalk; } var skipCounter = new Dictionary <Agent, int>(); for (var turn = 0; turn < gameSetting.MaxTalkTurn; turn++) { var continueTalk = false; foreach (var agent in AliveAgentList.Shuffle()) { var text = Lib.Talk.OVER; if (gameData.RemainTalkMap[agent] > 0) { text = gameServer.RequestTalk(agent); } if (text == null || text.Length == 0) { text = Lib.Talk.SKIP; } else { text = StripText(text); } if (text == Lib.Talk.SKIP) { if (skipCounter.ContainsKey(agent)) { skipCounter[agent]++; } else { skipCounter[agent] = 1; } if (skipCounter[agent] > gameSetting.MaxSkip) { text = Lib.Talk.OVER; } } var talk = new Talk(gameData.NextTalkIdx, Day, turn, agent, text); gameData.AddTalk(talk.Agent, talk); if (GameLogger != null) { GameLogger.Log($"{Day},talk,{talk.Idx},{talk.Turn},{talk.Agent.AgentIdx},{talk.Text}"); } if (text != Lib.Talk.OVER && text != Lib.Talk.SKIP) { skipCounter[agent] = 0; } if (talk.Text != Lib.Talk.OVER) { continueTalk = true; } } if (!continueTalk) { break; } } }
void ConsoleLog() { if (!ShowConsoleLog) { return; } var yesterday = gameData.DayBefore; Console.WriteLine("============================================="); if (yesterday != null) { Console.WriteLine($"Day {yesterday.Day:00}"); Console.WriteLine("========talk========"); foreach (var talk in yesterday.TalkList) { Console.WriteLine(talk); } Console.WriteLine("========Whisper========"); foreach (var whisper in yesterday.WhisperList) { Console.WriteLine(whisper); } Console.WriteLine("========Actions========"); foreach (var vote in yesterday.VoteList) { Console.WriteLine($"Vote:{vote.Agent}->{vote.Target}"); } foreach (var vote in yesterday.AttackVoteList) { Console.WriteLine($"AttackVote:{vote.Agent}->{vote.Target}"); } Console.WriteLine($"{yesterday.Executed} executed"); var divine = yesterday.Divine; if (divine != null) { Console.WriteLine($"{divine.Agent} divine {divine.Target}. Result is {divine.Result}"); } if (yesterday.Guard != null) { Console.WriteLine($"{yesterday.Guard} guarded"); } if (yesterday.AttackedDead != null) { Console.WriteLine($"{yesterday.AttackedDead} attacked"); } if (yesterday.CursedFox != null) { Console.WriteLine($"{yesterday.CursedFox} cursed"); } } Console.WriteLine("======"); foreach (var agent in OrderedAgentList) { Console.Write($"{agent}\t{agentNameMap[agent]}\t{StatusOf(agent)}\t{RoleOf(agent)}"); if (yesterday != null) { if (agent == yesterday.Executed) { Console.Write("\texecuted"); } if (agent == yesterday.AttackedDead) { Console.Write("\tattacked"); } var divine = yesterday.Divine; if (divine != null && agent == divine.Target) { Console.Write("\tdivined"); } var guard = yesterday.Guard; if (guard != null && agent == guard.Target) { Console.Write("\tguarded"); } if (agent == yesterday.CursedFox) { Console.Write("\tcursed"); } } Console.WriteLine(); } Console.Write($"Human:{AliveHumanList.Count}\nWerewolf:{AliveWolfList.Count}\n"); if (gameSetting.RoleNumMap[Role.FOX] != 0) { Console.Write($"Others:{AliveAgentList.Count(a => RoleOf(a).GetTeam() == Team.OTHERS)}\n"); } Console.WriteLine("============================================="); }