Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var randomSource    = new RandomSource(seed: 1234);
            var initialPosition = new GameState(size: 4, randomSource: randomSource);

            Console.WriteLine(initialPosition);

            var movesToExamine = new Stack <StateAndDirection>();

            var availableMovesFromCurrentPosition = initialPosition.FindAvailableMoves();

            foreach (var move in availableMovesFromCurrentPosition)
            {
                movesToExamine.Push(new StateAndDirection(initialPosition, move));
            }


            while (movesToExamine.Any())
            {
                var moveToTry = movesToExamine.Pop();

                var newPosition = moveToTry.GameState.MakeMove(moveToTry.Direction);
                Console.WriteLine("");
                Console.WriteLine(newPosition);

                if (newPosition.IsAWin())
                {
                    Console.WriteLine("It is possible :: " + newPosition.Moves());
                    Console.ReadKey();
                }

                if (!newPosition.IsALoss())
                {
                    var availableMovesFromNewPosition = newPosition.FindAvailableMoves();
                    foreach (var move in availableMovesFromNewPosition)
                    {
                        movesToExamine.Push(new StateAndDirection(newPosition, move));
                    }
                }
            }

            Console.WriteLine("It is NOT possible");
            Console.ReadKey();
        }