Esempio n. 1
1
 private int SolveFive(BombSettings settings, IList<Color> colors)
 {
     if (settings.SerialLastDigit == Parity.NotSet)
     {
         throw new NeedSerialLastDigitException();
     }
     // If the last wire is black and the last digit of the serial number is odd, cut the fourth wire.
     else if (colors.Last() == Color.Black && settings.SerialLastDigit == Parity.Odd)
     {
         return 4;
     }
     // Otherwise, if there is exactly one red wire and there is more than one yellow wire, cut the first wire.
     else if (colors.Count(c => c == Color.Red) == 1 && colors.Count(c => c == Color.Yellow) > 1)
     {
         return 1;
     }
     // Otherwise, if there are no black wires, cut the second wire.
     else if (colors.Count(c => c == Color.Black) == 0)
     {
         return 2;
     }
     // Otherwise, cut the first wire.
     else
     {
         return 1;
     }
 }
        private IEnumerable<Tuple<Color, ButtonLabel, BombSettings>> GetAllStates()
        {
            var colors = Enum.GetValues(typeof(Color)).Cast<Color>().ToList();
            var labels = Enum.GetValues(typeof(ButtonLabel)).Cast<ButtonLabel>().ToList();
            var bools = new List<bool>() { true, false };

            foreach (var color in colors)
            {
                foreach (var label in labels)
                {
                    foreach (var car in bools)
                    {
                        foreach (var freak in bools)
                        {
                            for (var batteries = 0; batteries < 5; batteries++)
                            {
                                var settings = new BombSettings()
                                {
                                    BatteryCount = batteries,
                                    IndicatorCAR = car,
                                    IndicatorFRK = freak
                                };

                                yield return new Tuple<Color, ButtonLabel, BombSettings>(color, label, settings);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public SimonHandler(
     BombSettings settings    
 )
     : base("Simon")
 {
     this.settings = settings;
 }
Esempio n. 4
0
        public WiresHandler(
            BombSettings settings
        )
            : base("Wires")
        {
            this.settings = settings;

            this.solver = new WiresSolver();
        }
Esempio n. 5
0
        public ButtonHandler(
            BombSettings settings    
        )
            : base("Button")
        {
            this.settings = settings;

            this.solver = new ButtonSolver();
        }
Esempio n. 6
0
        private void DrawAbilityPageEnabled()
        {
            calculator = new TLW.TLWBombCalculatorV1();
            bombStats  = BombSettings.Load(typeof(TLW.TLWBombCalculatorV1));

            localBombStats = new float[4];
            //localBombStats[0] = Bomb.MyBombRad;
            //localBombStats[1] = Bomb.MyBombRange;
            //localBombStats[2] = Bomb.MyBombSpeed;
            //localBombStats[3] = Bomb.MyBombCD;
        }
Esempio n. 7
0
 public BombHandler(
     BombSettings settings,
     MemoryHandler memoryHandler,
     SequencesHandler sequencesHandler,
     PasswordsHandler passwordsHandler
 )
     : base("Bomb")
 {
     this.settings = settings;
     this.memoryHandler = memoryHandler;
     this.sequencesHandler = sequencesHandler;
     this.passwordsHandler = passwordsHandler;
 }
 public ButtonAction Invoke(BombSettings settings, Color color, ButtonLabel label)
 {
     // If the button is blue and the button says "Abort", hold the button and refer to "Releasing a Held Button".
     if (color == Color.Blue && label == ButtonLabel.Abort)
     {
         return ButtonAction.Hold;
     }
     else if (settings.BatteryCount.HasValue == false)
     {
         throw new NeedBatteryCountException();
     }
     // If there is more than one battery on the bomb and the button says "Detonate", press and immediately release the button.
     else if (settings.BatteryCount.Value > 1 && label == ButtonLabel.Detonate)
     {
         return ButtonAction.Tap;
     }
     else if (settings.IndicatorCAR.HasValue == false)
     {
         throw new NeedIndicatorCARException();
     }
     // If the button is white and there is a lit indicator with label CAR, hold the button and refer to "Releasing a Held Button".
     else if (color == Color.White && settings.IndicatorCAR.Value == true)
     {
         return ButtonAction.Hold;
     }
     else if (settings.IndicatorFRK.HasValue == false)
     {
         throw new NeedIndicatorFRKException();
     }
     // If there are more than 2 batteries on the bomb and there is a lit indicator with label FRK, press and immediately release the button.
     else if (settings.BatteryCount.Value > 2 && settings.IndicatorFRK.Value == true)
     {
         return ButtonAction.Tap;
     }
     // If the button is yellow, hold the button and refere to "Releasing a Held Button".
     else if (color == Color.Yellow)
     {
         return ButtonAction.Hold;
     }
     // If the button is red and the button says "Hold", press and immediately release the button.
     else if (color == Color.Red && label == ButtonLabel.Hold)
     {
         return ButtonAction.Tap;
     }
     // If none of the above apply, hold the button and refer to "Releasing a Held Button".
     else
     {
         return ButtonAction.Hold;
     }
 }
Esempio n. 9
0
        private int SolveFour(BombSettings settings, IList<Color> colors)
        {
            // If there is more than one red wire and the last digit of the serial number is odd, cut the last red wire.
            if (colors.Count(c => c == Color.Red) > 1)
            {
                if (settings.SerialLastDigit == Parity.NotSet)
                {
                    throw new NeedSerialLastDigitException();
                }
                else if (settings.SerialLastDigit == Parity.Odd)
                {

                    var index = colors.Select((w, i) => new KeyValuePair<int, Color>(i, w))
                        .Where(p => p.Value == Color.Red)
                        .Last()
                        .Key;

                    return index + 1;
                }
            }

            // Otherwise, if the last wire is yellow and there are no red wires, cut the first wire.
            if (colors.Last() == Color.Yellow && colors.Count(c => c == Color.Red) == 0)
            {
                return 1;
            }
            // Otherwise, if there is exactly one blue wire, cut the first wire.
            else if (colors.Count(c => c == Color.Blue) == 1)
            {
                return 1;
            }
            // Otherwise, if there is more than one yellow wire, cut the last wire.
            else if (colors.Count(c => c == Color.Yellow) > 1)
            {
                return 4;
            }
            // Otherwise, cut the second wire.
            else
            {
                return 2;
            }
        }
Esempio n. 10
0
 public int Invoke(BombSettings settings, IList<Color> colors)
 {
     if (colors.Count == 3)
     {
         return this.SolveThree(colors);
     }
     else if (colors.Count == 4)
     {
         return this.SolveFour(settings, colors);
     }
     else if (colors.Count == 5)
     {
         return this.SolveFive(settings, colors);
     }
     else if (colors.Count == 6)
     {
         return this.SolveSix(settings, colors);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Esempio n. 11
0
        private void DrawAbilityPageDisabled()
        {
            if (bombStats != null)
            {
                BombStats toSave = calculator.ValidateStats(bombStats);
                BombSettings.WriteToStorage(toSave, calculator.GetType());
            }

            if (localBombStats != null)
            {
                //Bomb.MyBombRad.Value = Mathf.RoundToInt(localBombStats[0]);
                //Bomb.MyBombRange.Value = Mathf.RoundToInt(localBombStats[1]);
                //Bomb.MyBombSpeed.Value = Mathf.RoundToInt(localBombStats[2]);
                //Bomb.MyBombCD.Value = Mathf.RoundToInt(localBombStats[3]);
                //if (Bomb.MyBombRad.Value + Bomb.MyBombRange.Value + Bomb.MyBombSpeed.Value + Bomb.MyBombCD.Value > 20)
                //{
                //    Bomb.MyBombRad.Value = 5;
                //    Bomb.MyBombCD.Value = 5;
                //    Bomb.MyBombSpeed.Value = 5;
                //    Bomb.MyBombRange.Value = 5;
                //}
                localBombStats = null;
            }
        }
Esempio n. 12
0
        public void Complete()
        {
            var solver = new WiresSolver();
            var originalSolver = new OriginalWiresSolver();

            var settings = new BombSettings();
            var permutations = this.GetAllColorPermutations();
            foreach (var p in permutations)
            {
                settings.SerialLastDigit = Parity.Even;

                Assert.AreEqual(
                    originalSolver.Invoke(settings, p),
                    solver.Invoke(settings, p)
                );

                settings.SerialLastDigit = Parity.Odd;

                Assert.AreEqual(
                    originalSolver.Invoke(settings, p),
                    solver.Invoke(settings, p)
                );
            }
        }
Esempio n. 13
0
 private int SolveSix(BombSettings settings, IList<Color> colors)
 {
     if (settings.SerialLastDigit == Parity.NotSet)
     {
         throw new NeedSerialLastDigitException();
     }
     // If there are no yellow wires and the last digit of the serial number is odd, cut the third wire.
     else if (colors.Count(c => c == Color.Yellow) == 0 && settings.SerialLastDigit == Parity.Odd)
     {
         return 3;
     }
     // Otherwise, if there is exactly one yellow wire and there is more than one white wire, cut the fourth wire.
     else if (colors.Count(c => c == Color.Yellow) == 1 && colors.Count(c => c == Color.White) > 1)
     {
         return 4;
     }
     // Otherwise, if there are no red wires, cut the last wire.
     else if (colors.Count(c => c == Color.Red) == 0)
     {
         return 6;
     }
     // Otherwise, cut the fourth wire.
     else
     {
         return 4;
     }
 }