Ejemplo n.º 1
0
        public bool ProcessInstructionLineAndOkToDelete(string line)
        {
            // Bot gives microChips to something else
            List <string> splitOnGives = line.Split(new string[] { "gives" }, StringSplitOptions.RemoveEmptyEntries).ToList <string>();
            int           givingBotId  = GetIdAtEndOfString(splitOnGives[0]);
            ZoomingBot    givingBot    = CreateZoomingBotIfDoesNotExist(givingBotId);

            // If the bot does not have two microChips, then leave on instruction list
            if (givingBot.CountMicroChips() != 2)
            {
                return(false);
            }

            string        secondSection = splitOnGives[1].Trim();
            List <string> splitOnAnd    = secondSection.Split(new string[] { "and" }, StringSplitOptions.RemoveEmptyEntries).ToList <string>();

            // First receiver
            string andFirstSection = splitOnAnd[0].Trim();
            bool   firstIsHigh     = andFirstSection.Contains("high");
            int    firstMicroChip  = givingBot.GiveMicroChip(firstIsHigh);

            // If there is a receiving bot, then give the microchip, otherwise goes to output which is ignored
            if (andFirstSection.Contains("bot"))
            {
                int        receivingId  = GetIdAtEndOfString(andFirstSection);
                ZoomingBot receivingBot = CreateZoomingBotIfDoesNotExist(receivingId);
                receivingBot.AddMicroChip(firstMicroChip);
            }
            else
            {
                int receivingId = GetIdAtEndOfString(andFirstSection);
                outputs.Add(receivingId, firstMicroChip);
            }

            // Second receiver
            string andSecondSection = splitOnAnd[1].Trim();
            bool   secondIsHigh     = andFirstSection.Contains("high");
            int    secondMicroChip  = givingBot.GiveMicroChip(secondIsHigh);

            // If there is a receiving bot, then give the microchip, otherwise goes to output which is ignored
            if (andSecondSection.Contains("bot"))
            {
                int        receivingId  = GetIdAtEndOfString(andSecondSection);
                ZoomingBot receivingBot = CreateZoomingBotIfDoesNotExist(receivingId);
                receivingBot.AddMicroChip(secondMicroChip);
            }
            else
            {
                int receivingId = GetIdAtEndOfString(andSecondSection);
                outputs.Add(receivingId, secondMicroChip);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void ProcessSeedingLine(string line)
        {
            // Initial giving of microChip to bot
            List <string> splitOnGoes = line.Split(new string[] { "goes" }, StringSplitOptions.RemoveEmptyEntries).ToList <string>();
            int           microChip   = GetIdAtEndOfString(splitOnGoes[0]);
            int           botId       = GetIdAtEndOfString(splitOnGoes[1]);

            ZoomingBot zoomingBot = CreateZoomingBotIfDoesNotExist(botId);

            // Add microchip
            zoomingBot.AddMicroChip(microChip);
        }
Ejemplo n.º 3
0
        private ZoomingBot CreateZoomingBotIfDoesNotExist(int botId)
        {
            ZoomingBot zoomingBot = GetZoomingBotFromCollection(botId);

            // If bot does not exist, create it
            if (zoomingBot == null)
            {
                zoomingBot = new ZoomingBot(botId, new List <int>());
                _zoomingBots.Add(zoomingBot);
            }
            return(zoomingBot);
        }