Пример #1
0
        /// <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;
                }
            }
        }
Пример #2
0
        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;
                }
            }
        }