Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void makeMove(int cell);
- void checkVictory();
- void iterateList();
- void randomizeList();
- void printSolution();
- void printState();
- void resetState();
- int PAR = 12;
- //successful movelist of cells to select.
- int moves[12];
- //gamestate values are as follows: 0=empty, 1=red, 2=yellow
- //pools are similar, but 2 and 4 are null.
- int gamestate[5];
- int pools[2];
- bool solution = false;
- bool dupepass = true;
- bool stillchance = true;
- int tally=0;
- int seed = 0;
- int main(){
- int i = 0;
- while(i<PAR){
- moves[i]=1;
- i++;
- }
- while(solution != true){
- resetState();
- i=0;
- while(i<PAR){
- makeMove(moves[i]-1);
- checkVictory();
- i++;
- }
- // printState();
- iterateList();
- // randomizeList();
- tally++;
- if(tally%1000000==0){
- cout<<tally<<endl;
- }
- }
- }
- void makeMove(int cell){
- //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.
- if(cell==0&&gamestate[0]!=0){
- if(pools[0]==0){
- gamestate[1]=gamestate[0];
- }
- else{
- gamestate[1]=gamestate[0];
- gamestate[0]=pools[0];
- pools[0]=0;
- }
- return;
- }
- if(cell==2&&gamestate[2]!=0){
- if(pools[1]==0){
- gamestate[1]=gamestate[2];
- }
- else{
- gamestate[1]=gamestate[2];
- gamestate[2]=pools[1];
- pools[1]=0;
- }
- return;
- }
- if(cell==1&&gamestate[1]!=0){
- pools[0]=gamestate[0];
- pools[1]=gamestate[2];
- gamestate[0]=gamestate[1];
- gamestate[2]=gamestate[1];
- if(gamestate[4]==0){
- gamestate[3]=gamestate[1];
- }
- }
- if(cell==3&&gamestate[3]!=0){
- if(gamestate[4]==0){
- gamestate[1]=gamestate[3];
- }
- }
- if(cell==4){
- gamestate[4] = gamestate[4]-1;
- if(gamestate[4] < 0){
- gamestate[4] = gamestate[4] * -1;
- }
- }
- }
- void resetState(){
- gamestate[0] = 2;
- gamestate[1] = 0;
- gamestate[2] = 1;
- gamestate[3] = 0;
- gamestate[4] = 1; //1 = off, 0 = on
- pools[0] = 0;
- pools[1] = 0;
- }
- void iterateList(){
- moves[0] = moves[0] + 1;
- int k=0;
- while(k<PAR){
- if(moves[k] == 6){
- moves[k] = 1;
- moves[k+1] = moves[k+1] + 1;
- }
- k++;
- }
- }
- void randomizeList(){
- int i=0;
- while(i<PAR){
- //moves[i]=1;
- seed = (seed * 1103515245 + 12345) & 0x7FFFFFFF;
- moves[i]=seed%5+1;
- i++;
- }
- }
- void checkVictory(){
- if(gamestate[0]==1 && gamestate[1]==2 && gamestate[2]==2 && gamestate[4]==1){
- printSolution();
- solution = true;
- }
- }
- void printSolution(){
- int p = 0;
- while(p<PAR){
- cout<<moves[p];
- p++;
- }
- }
- void printState(){
- int q = 0;
- while(q<5){
- cout<<gamestate[q];
- q++;
- }
- cout<<endl;
- // q=0;
- // while(q<PAR){
- // cout<<moves[q]+1;
- // q++;
- // }
- // cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement