private EightPuzzleResult Solve(PriorityQueue <AStarStateWithVisitedHashes> queue)
        {
            int visitedNodesCount = 0;

            while (true)
            {
                AStarStateWithVisitedHashes state = queue.TakeLast();
                visitedNodesCount++;

                if (state.Board.Equals(Board.FinalBoard))
                {
                    return(new EightPuzzleResult(state, visitedNodesCount));
                }

                IReadOnlyCollection <Board> neighborBoards = state.Board.GetNeighbors();

                foreach (Board board in neighborBoards)
                {
                    if (!state.BoardWasVisited(board))
                    {
                        AStarStateWithVisitedHashes newState = stateFactory.Create(board, state);
                        queue.Add(newState);
                    }
                }
            }
        }
        public AStarStateWithVisitedHashes Create(Board board, AStarStateWithVisitedHashes previousState)
        {
            AStarState baseState = baseStateFactory.Create(board, previousState);
            var        hashSet   = new HashSet <int>(previousState.VisitedStatesHashes);

            hashSet.Add(board.GetHashCode());
            return(new AStarStateWithVisitedHashes(baseState, hashSet));
        }
        public EightPuzzleResult Solve(Board startBoard)
        {
            AStarStateWithVisitedHashes startingState = stateFactory.CreateStartingState(startBoard);

            var queue = new PriorityQueue <AStarStateWithVisitedHashes>();

            queue.Add(startingState);

            return(Solve(queue));
        }