Example #1
0
        public void Solve()
        {
            while (PossibleSolutions.Count > 0)
            {
                Console.WriteLine("Possible solutions: " + PossibleSolutions.Count);
                BoardState currentState = PossibleSolutions[0];
                PossibleSolutions.RemoveAt(0);

                if (currentState.IsValidSolution())
                {
                    currentState.PrintSolution();
                    break;
                }

                List <BoardState> newStates = BoardUtils.GenerateNextStates(currentState);

                foreach (var state in newStates)
                {
                    string hash = string.Join(",", state.Board.Select(x => x.ToString()).ToArray());

                    if (!statesReached.Contains(hash))
                    {
                        PossibleSolutions.Add(state);
                        statesReached.Add(hash);
                    }
                }
            }
        }
Example #2
0
 public PegGameSolver(int initialOpenSlotIndex)
 {
     PossibleSolutions = new List <BoardState>()
     {
         new BoardState(BoardUtils.CreateInitialBoard(initialOpenSlotIndex), null)
     };
 }
Example #3
0
 public bool IsValidSolution()
 {
     return(BoardUtils.IsBoardSolved(m_BoardState));
 }