Esempio n. 1
0
        private void search(GameState gs, Stack <Move> moveStack)
        {
            if (gs.PegsRemaining() == 1)
            {
                //            System.out.println("Found a winning sequence. Final state:");
                //            System.out.println(gs);

                solutions.Add(new List <Move>(moveStack));

                gamesPlayed++;

                return;
            }

            List <Move> legalMoves = gs.LegalMoves();

            if (legalMoves.Count == 0)
            {
                gamesPlayed++;
                return;
            }

            foreach (Move m in legalMoves)
            {
                GameState nextState = gs.Apply(m);
                moveStack.Push(m);
                search(nextState, moveStack);
                moveStack.Pop();
            }
        }
Esempio n. 2
0
        private void search(GameState gs, Stack<Move> moveStack)
        {
            if (gs.PegsRemaining() == 1)
            {
                //            System.out.println("Found a winning sequence. Final state:");
                //            System.out.println(gs);

                solutions.Add(new List<Move>(moveStack));

                gamesPlayed++;

                return;
            }

            List<Move> legalMoves = gs.LegalMoves();

            if (legalMoves.Count == 0)
            {
                gamesPlayed++;
                return;
            }

            foreach (Move m in legalMoves)
            {
                GameState nextState = gs.Apply(m);
                moveStack.Push(m);
                search(nextState, moveStack);
                moveStack.Pop();
            }
        }