Пример #1
0
        public override string Command(Bomb bomb, string command)
        {
            var color  = "";
            var number = "";

            foreach (var word in command.Split(' '))
            {
                if (InternalFunctions.IsNumber(word))
                {
                    number = word;
                }
                if (InternalFunctions.IsColor(word))
                {
                    color = word;
                }
                if (!string.IsNullOrWhiteSpace(number) && !string.IsNullOrWhiteSpace(word))
                {
                    Numbers.Add(color, number);
                    color  = "";
                    number = "";
                }
            }

            if (Numbers.Count != 3)
            {
                return("Could not find enought numbers.");
            }

            return(Solve(bomb));
        }
Пример #2
0
        public override string Command(Bomb bomb, string command)
        {
            var connection = new Connection();

            foreach (var word in command.Split(' '))
            {
                if (InternalFunctions.IsNumber(word))
                {
                    connection.LeftSide  = word[0].ToString();
                    connection.RightSide = word[1].ToString();
                }

                if (connection.IsComplete())
                {
                    Connections.Add(connection);
                    connection = new Connection();
                }
            }

            if (Connections.Count == 4)
            {
                return(Solve(bomb));
            }
            else
            {
                return("Not enought connections.");
            }
        }
Пример #3
0
        public override string Command(Bomb bomb, string command)
        {
            var row    = -1;
            var column = -1;

            foreach (var word in command.Split(' '))
            {
                if (InternalFunctions.GetLetterFromPhoneticLetter(word) != "")
                {
                    column = InternalFunctions.GetNumberFromLetter(InternalFunctions.GetLetterFromPhoneticLetter(word)) - 1;
                }
                if (InternalFunctions.IsNumber(word))
                {
                    row = int.Parse(word) - 1;
                }
                if (row != -1 && column != -1)
                {
                    Positions.Add(InternalFunctions.GetPhoneticLetterFromLetter(InternalFunctions.GetLetterFromNumber(column + 1)) + '-' + (row + 1));
                    row    = -1;
                    column = -1;
                }
            }

            return(Solve(bomb));
        }
Пример #4
0
        public override string Command(Bomb bomb, string command)
        {
            if (command == "combination locks")
            {
                return(Solve(bomb));
            }

            foreach (var word in command.Split(' '))
            {
                if (InternalFunctions.IsNumber(word))
                {
                    if (TwoFactor1.Length < 6)
                    {
                        TwoFactor1 += InternalFunctions.GetNumber(word);
                    }
                    else
                    {
                        TwoFactor2 += InternalFunctions.GetNumber(word);
                    }
                }
            }

            if (TwoFactor1.Length != 6 || TwoFactor2.Length != 6)
            {
                return("Could not get two factors.");
            }

            return(Solve(bomb));
        }
Пример #5
0
        public override string Command(Bomb bomb, string command)
        {
            bool?NumberInTheFront = null;
            var  splitCommand     = command.Split(' ').ToList();

            foreach (var word in command.Split(' '))
            {
                if (word.Contains("dollar"))
                {
                    var itemIndex = splitCommand.FindIndex(x => x == word);
                    ValuePaid = double.Parse(splitCommand[itemIndex - 1], CultureInfo.InvariantCulture);
                    continue;
                }
                if (word == "sunday" || word == "monday" || word == "tuesday" || word == "wednesday" || word == "thursday" || word == "friday" || word == "saturday")
                {
                    Day = word;
                    continue;
                }
                if (!PossibleItems.Select(x => x.Name).Contains(word))
                {
                    continue;
                }
                ItemsBought.Add(PossibleItems.Where(x => x.Name == word).First());
                if (ItemsBought.Last().BuyPerPound)
                {
                    var itemIndex = splitCommand.FindIndex(x => x == ItemsBought.Last().Name);
                    switch (NumberInTheFront)
                    {
                    case true: { ItemsBought.Last().Quantity = double.Parse(splitCommand[itemIndex - 1], CultureInfo.InvariantCulture); break; }

                    case false: { ItemsBought.Last().Quantity = double.Parse(splitCommand[itemIndex + 1], CultureInfo.InvariantCulture); break; }

                    default:
                    {
                        NumberInTheFront = InternalFunctions.IsNumber(splitCommand[itemIndex - 1]);
                        if (NumberInTheFront.Value)
                        {
                            ItemsBought.Last().Quantity = double.Parse(splitCommand[itemIndex - 1], CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            ItemsBought.Last().Quantity = double.Parse(splitCommand[itemIndex + 1], CultureInfo.InvariantCulture);
                        }
                        break;
                    }
                    }
                }
                else
                {
                    ItemsBought.Last().Quantity = 1;
                }
            }

            return(Solve(bomb));
        }
        public override string Command(Bomb bomb, string command)
        {
            if (command.Contains("serial"))
            {
                foreach (var word in command.Split(' '))
                {
                    Serial += InternalFunctions.GetLetterFromPhoneticLetter(word).ToUpper();
                    Serial += InternalFunctions.GetNumber(word) == -1 ? "" : InternalFunctions.GetNumber(word).ToString();
                }
                return("Serial added.");
            }
            if (command.Contains("type"))
            {
                if (command.Contains("strk"))
                {
                    Type = "STRK";
                }
                if (command.Contains("leds"))
                {
                    Type = "LEDS";
                }
                if (command.Contains("cntd"))
                {
                    Type = "CNTD";
                }
                if (command.Contains("expl"))
                {
                    Type = "EXPL";
                }

                if (Type != "")
                {
                    return("Type added.");
                }
            }
            foreach (var word in command.Split(' '))
            {
                if (InternalFunctions.IsNumber(word))
                {
                    if (command.Contains("pins"))
                    {
                        PinQuantity = InternalFunctions.GetNumber(word);
                        return("Pin quantity added.");
                    }
                    else
                    {
                        PinNumber = InternalFunctions.GetNumber(word);
                        return(Solve(bomb));
                    }
                }
            }
            return("Cannot resolve, try again.");
        }
        public override string Command(Bomb bomb, string command)
        {
            StartPosition = new Wire();
            var positionList = new List <int>()
            {
            };
            var colorList = new List <string>();

            foreach (var word in command.Split(' '))
            {
                if (InternalFunctions.IsNumber(word))
                {
                    positionList.Add(InternalFunctions.GetNumber(word));
                }
                if (InternalFunctions.IsColor(word))
                {
                    colorList.Add(word);
                }
            }

            if (positionList.Count != colorList.Count || positionList.Count == 0 || colorList.Count == 0)
            {
                return("Different number of colors and positions.");
            }

            var originalStart = StartPosition;

            for (int i = 0; i < positionList.Count - 1; i++)
            {
                StartPosition.Start         = positionList[i];
                StartPosition.End           = positionList[i + 1 % positionList.Count];
                StartPosition.Color         = colorList[i];
                StartPosition.Next          = new Wire();
                StartPosition.Next.Previous = StartPosition;
                StartPosition = StartPosition.Next;
            }

            StartPosition.Start         = positionList[positionList.Count - 1];
            StartPosition.End           = positionList[0];
            StartPosition.Color         = colorList[colorList.Count - 1];
            StartPosition.Next          = originalStart;
            StartPosition.Next.Previous = StartPosition;
            StartPosition = StartPosition.Next;

            return(Solve(bomb));
        }
Пример #8
0
        public override string Command(Bomb bomb, string command)
        {
            foreach (var word in command.Split(' '))
            {
                if (InternalFunctions.IsNumber(word))
                {
                    Quantity = InternalFunctions.GetNumber(word);
                }
                if (InternalFunctions.IsColor(word))
                {
                    Color = word;
                }
            }
            if (Quantity == 0 || string.IsNullOrEmpty(Color))
            {
                return("Cannot find quantity and color");
            }

            return(Solve(bomb));
        }
Пример #9
0
        public override string Command(Bomb bomb, string command)
        {
            foreach (var word in command.Split(' '))
            {
                if (InternalFunctions.IsNumber(word))
                {
                    Numbers.Add(InternalFunctions.GetNumber(word));
                }
                if (InternalFunctions.IsPhoneticLetter(word))
                {
                    Letters.Add(InternalFunctions.GetLetterFromPhoneticLetter(word));
                }
            }

            if (Letters.Count != 5)
            {
                return("Not enought phonetic letters.");
            }

            return(Solve(bomb));
        }
Пример #10
0
        public override string Command(Bomb bomb, string command)
        {
            foreach (var word in command.Split(' '))
            {
                if (InternalFunctions.IsColor(word))
                {
                    Color = word;
                }

                if (InternalFunctions.IsNumber(word))
                {
                    Volume = InternalFunctions.GetNumber(word);
                }
            }

            if (string.IsNullOrEmpty(Color))
            {
                return("Could not identify solution.");
            }
            return(Solve(bomb));
        }