Advertisement
mvandevander

Exponential Puzzle Solver

Sep 17th, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1.     public IEnumerator RecursiveTileIterator(int i)
  2.     {
  3.         currently_checking_for_solutions = true;
  4.         numIterations++;
  5.         if(numIterations % 10000 == 0)
  6.         {
  7.             yield return null;
  8.         }
  9.         if(i < (width*height-1))
  10.         {
  11.             if(!lockedTiles[i] && !disabledTiles[i])
  12.             {
  13.                 currentState[i] = false;
  14.                 if(symbols[i] > 0 && symbols[i] <= 6) tiles[i].symbols[0].SetColor(Color.white);
  15.                
  16.                 //Not part of the above if, just a scope to kill the IEnumerator when we leave it
  17.                 {
  18.                     IEnumerator count = RecursiveTileIterator(i+1);
  19.                     while (count.MoveNext()) if(numIterations % 10000 == 0) yield return null;
  20.                 }
  21.                
  22.                 currentState[i] = true;
  23.                 if(symbols[i] > 0 && symbols[i] <= 6) tiles[i].symbols[0].SetColor(Color.black);
  24.  
  25.                 //Not part of the above if, just a scope to kill the IEnumerator when we leave it                
  26.                 {
  27.                     IEnumerator count = RecursiveTileIterator(i+1);
  28.                     while (count.MoveNext()) if(numIterations % 10000 == 0) yield return null;
  29.                 }
  30.             }
  31.             else
  32.             {
  33.                 //just a scope to kill the IEnumerator when we leave it
  34.                 {
  35.                     IEnumerator count = RecursiveTileIterator(i+1);
  36.                     while (count.MoveNext()) if(numIterations % 10000 == 0) yield return null;
  37.                     RecursiveTileIterator(i+1);
  38.                 }
  39.             }
  40.         }
  41.         else
  42.         {
  43.             if(!lockedTiles[i] && !disabledTiles[i])
  44.             {
  45.                 currentState[i] = false;
  46.                 if(symbols[i] > 0 && symbols[i] <= 6) tiles[i].symbols[0].SetColor(Color.white);
  47.                 if(isSolved())
  48.                 {
  49.                      SolutionList.Add(currentState.Clone());
  50.                 }
  51.                 currentState[i] = true;
  52.                 if(symbols[i] > 0 && symbols[i] <= 6) tiles[i].symbols[0].SetColor(Color.black);
  53.                
  54.                 if(isSolved())
  55.                 {
  56.                      SolutionList.Add(currentState.Clone());
  57.                 }
  58.                
  59.             }
  60.             else
  61.             {
  62.                 if(isSolved())
  63.                 {
  64.                      SolutionList.Add(currentState.Clone());
  65.                 }
  66.             }
  67.         }
  68.        
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement