Advertisement
IhavenonameSDA

Adjacency *temp solver

Dec 2nd, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void makeMove(int cell);
  6. void checkVictory();
  7. void iterateList();
  8. void randomizeList();
  9. void printSolution();
  10. void printState();
  11. void resetState();
  12.  
  13.     int PAR = 12;
  14.     //successful movelist of cells to select.
  15.     int moves[12];
  16.     //gamestate values are as follows: 0=empty, 1=red, 2=yellow
  17.     //pools are similar, but 2 and 4 are null.
  18.     int gamestate[5];
  19.     int pools[2];
  20.     bool solution = false;
  21.     bool dupepass = true;
  22.     bool stillchance = true;
  23.     int tally=0;
  24.     int seed = 0;
  25.    
  26. int main(){
  27.     int i = 0;
  28.    
  29.     while(i<PAR){
  30.         moves[i]=1;
  31.         i++;
  32.     }
  33.    
  34.     while(solution != true){
  35.     resetState();
  36.     i=0;
  37.         while(i<PAR){
  38.             makeMove(moves[i]-1);
  39.             checkVictory();
  40.             i++;
  41.         }
  42. //  printState();
  43.     iterateList();
  44. //  randomizeList();
  45.     tally++;
  46.         if(tally%1000000==0){
  47.             cout<<tally<<endl;
  48.         }
  49.     }
  50. }
  51.  
  52. void makeMove(int cell){
  53.     //cells 0-2 are the play area. cell 3 is the one time only. cell 4 is a power switch. Cell 3 is inaccessible if the power is off.
  54.     if(cell==0&&gamestate[0]!=0){
  55.         if(pools[0]==0){
  56.             gamestate[1]=gamestate[0]; 
  57.         }
  58.         else{
  59.             gamestate[1]=gamestate[0];
  60.             gamestate[0]=pools[0];
  61.             pools[0]=0;
  62.         }
  63.         return;
  64.     }
  65.     if(cell==2&&gamestate[2]!=0){
  66.         if(pools[1]==0){
  67.             gamestate[1]=gamestate[2]; 
  68.         }
  69.         else{
  70.             gamestate[1]=gamestate[2];
  71.             gamestate[2]=pools[1];
  72.             pools[1]=0;
  73.         }
  74.         return;
  75.     }
  76.     if(cell==1&&gamestate[1]!=0){
  77.             pools[0]=gamestate[0];
  78.             pools[1]=gamestate[2];
  79.             gamestate[0]=gamestate[1];
  80.             gamestate[2]=gamestate[1];
  81.         if(gamestate[4]==0){
  82.             gamestate[3]=gamestate[1];
  83.         }
  84.     }
  85.     if(cell==3&&gamestate[3]!=0){
  86.         if(gamestate[4]==0){
  87.             gamestate[1]=gamestate[3];
  88.         }  
  89.     }
  90.     if(cell==4){
  91.         gamestate[4] = gamestate[4]-1;
  92.         if(gamestate[4] < 0){
  93.             gamestate[4] = gamestate[4] * -1;
  94.         }
  95.     }
  96. }
  97.  
  98. void resetState(){
  99.     gamestate[0] = 2;
  100.     gamestate[1] = 0;
  101.     gamestate[2] = 1;
  102.     gamestate[3] = 0;
  103.     gamestate[4] = 1; //1 = off, 0 = on
  104.     pools[0] = 0;
  105.     pools[1] = 0;
  106. }
  107.  
  108. void iterateList(){
  109.     moves[0] = moves[0] + 1;
  110.     int k=0;
  111.     while(k<PAR){
  112.         if(moves[k] == 6){
  113.             moves[k] = 1;
  114.             moves[k+1] = moves[k+1] + 1;   
  115.         }
  116.         k++;
  117.     }
  118. }
  119.  
  120. void randomizeList(){
  121.     int i=0;
  122.     while(i<PAR){
  123.         //moves[i]=1;
  124.         seed = (seed * 1103515245 + 12345) & 0x7FFFFFFF;
  125.         moves[i]=seed%5+1;
  126.         i++;
  127.     }
  128. }
  129.  
  130. void checkVictory(){
  131.     if(gamestate[0]==1 && gamestate[1]==2 && gamestate[2]==2 && gamestate[4]==1){
  132.         printSolution();
  133.         solution = true;
  134.     }
  135. }
  136.  
  137. void printSolution(){
  138.     int p = 0;
  139.     while(p<PAR){
  140.     cout<<moves[p];
  141.     p++;
  142.     }
  143. }
  144.  
  145. void printState(){
  146.     int q = 0;
  147.     while(q<5){
  148.     cout<<gamestate[q];
  149.     q++;
  150.     }
  151.     cout<<endl;
  152. //  q=0;
  153. //  while(q<PAR){
  154. //  cout<<moves[q]+1;
  155. //  q++;
  156. //  }
  157. //  cout<<endl;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement