Advertisement
mvandevander

Non Recursive Puzzle Solver

Sep 17th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1.     public IEnumerator NonRecursiveTileIterator(int i)
  2.     {
  3.         ulong possibilities = (ulong)Mathf.Pow(2, width*height);
  4.         bool skip_this_iteration;
  5.         while (true)
  6.         {
  7.         currently_checking_for_solutions = true;
  8.             skip_this_iteration = false;
  9.             if (possibilities % 1000000 == 0) yield return null;
  10.             for(int x = 0; x < currentState.Length; x++)
  11.             {
  12.                 currentState[x] = ((possibilities & (ulong)(1<<x)) != 0);
  13.                 if(lockedTiles[x] && currentState[x] != startingState[x])
  14.                 {
  15.                     skip_this_iteration = true;
  16.                     break;
  17.                 }
  18.             }
  19.             if(!skip_this_iteration)
  20.             {
  21.                 if(isSolved())
  22.                 {
  23.                      SolutionList.Add(currentState.Clone());
  24.                 }
  25.             }
  26.             if(possibilities==0) yield break;
  27.             possibilities--;
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement