Example #1
0
 public Level(int LevelNum, List <List <string> > Stacks)
 {
     this.LevelNum     = LevelNum;
     this.Error        = null;
     this.Stacks       = Stacks;
     this.Instructions = new List <string>();
     this.Solutions    = new List <List <Move> >();
     this.WrongMoves   = new List <Move>();
     this.Stacks       = new List <List <string> >();
     HoopStackSolver.solveLevel(this);
 }
        public void numMovesTest()
        {
            //arrange
            // 0 moves list
            List <List <string> > stacks1 = new List <List <string> >
            {
                new List <string> {
                    "Blue", "Red", "Red"
                },
                new List <string> {
                    "Blue", "Green"
                },
                new List <string> {
                    "Blue"
                }
            };
            // 1 move list
            List <List <string> > stacks2 = new List <List <string> >
            {
                new List <string> {
                    "Blue", "Red", "Green"
                },
                new List <string> {
                    "Blue", "Green"
                },
                new List <string> {
                    "Blue"
                }
            };
            // 1+ move list
            List <List <string> > stacks3 = new List <List <string> >
            {
                new List <string> {
                    "Blue", "Red", "Green"
                },
                new List <string> {
                    "Blue", "Green"
                },
                new List <string> {
                    "Blue"
                },
                new List <string>()
            };
            //act
            List <Move> moves1 = HoopStackSolver.numMoves(stacks1, 3, 0);
            List <Move> moves2 = HoopStackSolver.numMoves(stacks2, 3, 0);
            List <Move> moves3 = HoopStackSolver.numMoves(stacks3, 3, 0);

            //assert
            Assert.AreEqual(moves1.Count, 0);
            Assert.AreEqual(moves2.Count, 1);
            Assert.IsTrue(moves3.Count > 1);
        }
Example #3
0
        public Level(LevelEntryModel LevelModel)
        {
            //create level from levelentrymodel
            this.LevelNum     = LevelModel.LevelNum; //get level number
            this.Stacks       = new List <List <string> >();
            this.Instructions = new List <string>();
            this.Solutions    = new List <List <Move> >();
            this.WrongMoves   = new List <Move>();
            int numStacks = LevelModel.NumStacks; //get the colors for numStacks stacks

            for (int i = 0; i < numStacks; i++)
            {
                string stack = i switch
                {
                    0 => LevelModel.Stack1,
                    1 => LevelModel.Stack2,
                    2 => LevelModel.Stack3,
                    3 => LevelModel.Stack4,
                    4 => LevelModel.Stack5,
                    5 => LevelModel.Stack6,
                    6 => LevelModel.Stack7,
                    7 => LevelModel.Stack8,
                    8 => LevelModel.Stack9,
                    9 => LevelModel.Stack10,
                    _ => "Could not retrieve stack.",
                };
                /*string[] words = stack.Split(",");*/
                string[]      words = Regex.Split(stack, @"(?:\s*,\s*)|\s+");
                List <string> temp  = new List <string>();
                foreach (var word in words)
                {
                    temp.Add(word);
                }
                this.Stacks.Add(temp);
            }
            //solve the stacks in this constructor or do it another way?
            HoopStackSolver.solveLevel(this);
        }
        public void checkTest()
        {
            //arrange
            List <List <string> > stacksEmpty = new List <List <string> >();
            List <List <string> > stacksFull  = new List <List <string> >
            {
                new List <string> {
                    "Blue", "Blue", "Blue"
                },
                new List <string> {
                    "Green", "Green", "Green"
                },
                new List <string> {
                    "Red", "Red", "Red"
                }
            };;
            List <List <string> > stacksNotDone = new List <List <string> >
            {
                new List <string> {
                    "Blue", "Red", "Green"
                },
                new List <string> {
                    "Blue", "Green"
                },
                new List <string> {
                    "Blue"
                }
            };;
            //act
            bool checkEmpty   = HoopStackSolver.check(stacksEmpty);
            bool checkFull    = HoopStackSolver.check(stacksFull);
            bool checkNotDone = HoopStackSolver.check(stacksNotDone);

            //assert
            Assert.IsTrue(checkEmpty);
            Assert.IsTrue(checkFull);
            Assert.IsFalse(checkNotDone);
        }
        public void moveTest()
        {
            //arrange
            List <List <string> > stacks = new List <List <string> >
            {
                new List <string> {
                    "Blue", "Red", "Green"
                },
                new List <string> {
                    "Blue", "Green"
                },
                new List <string> {
                    "Blue"
                }
            };;
            //act
            Move possible    = HoopStackSolver.move(ref stacks, 0, 0, 1);
            Move notPossible = HoopStackSolver.move(ref stacks, 0, 0, 2);

            //assert
            Assert.IsNotNull(possible);
            Assert.IsNull(notPossible);
        }