예제 #1
0
        private void SetBotStructure(string command, BotNet workspace)
        {
            // example command: "bot 149 gives low to bot 17 and high to output 5"
            string[] commandWords = command.Split(' ');

            int  botId         = Convert.ToInt32(commandWords[1]);
            bool giveLowToBot  = commandWords[5] == "bot";
            int  giveLowTo     = Convert.ToInt32(commandWords[6]);
            bool giveHighToBot = commandWords[10] == "bot";
            int  giveHighTo    = Convert.ToInt32(commandWords[11]);

            workspace.EnsureBot(botId, giveLowToBot ? giveLowTo : botId,
                                giveHighToBot ? giveHighTo : botId);
            if (!giveLowToBot)
            {
                workspace.EnsureOutput(giveLowTo);
            }
            if (!giveHighToBot)
            {
                workspace.EnsureOutput(giveHighTo);
            }

            workspace.GetBot(botId).SendHigherValueTo = giveHighToBot ? (BaseNode)workspace.GetBot(giveHighTo) :
                                                        workspace.GetOutput(giveHighTo);
            workspace.GetBot(botId).SendLowerValueTo = giveLowToBot ? (BaseNode)workspace.GetBot(giveLowTo) :
                                                       workspace.GetOutput(giveLowTo);
        }
예제 #2
0
        public void ProcessCommands(string commands, BotNet workspace)
        {
            Dictionary <int, int> valuesToDistribute = new Dictionary <int, int>();

            foreach (string command in commands.Split(Environment.NewLine.ToCharArray(),
                                                      StringSplitOptions.RemoveEmptyEntries))
            {
                if (command.StartsWith("value"))
                {
                    int botId;
                    int value;
                    DecodeValueCommand(command, out botId, out value);
                    workspace.EnsureBot(botId);
                    workspace.GetBot(botId).TakeValue(value);
                }
                if (command.StartsWith("bot"))
                {
                    SetBotStructure(command, workspace);
                }
            }
        }
예제 #3
0

        
예제 #4
0
 public Bot(BotNet workspace, int botId)
 {
     _botnet = workspace;
     _botId  = botId;
     _values = new List <int>();
 }