daily pastebin goal
58%
SHARE
TWEET

Non Recursive Puzzle Solver

mvandevander Sep 17th, 2018 4 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top