Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <stdio.h>
- #include <math.h>
- #include <windows.h>
- #include <vector>
- using namespace std;
- #define COL 4
- #define LASTROUND 14
- //Last round should be 14 according to this code?
- class Round
- {
- public:
- std::vector<int> Map;
- std::vector<int> Hist;
- std::vector<Round *> Poss;
- int RoundNum;
- Round *RoundPrev;
- //int LastChecked;
- /*Round *GetRound()
- {
- Round *temp = this;
- return temp;
- } */
- };
- void CopyHist(Round &round1, Round &round2)
- {
- //memcpy(&round1.Hist, &round2.Hist, sizeof(&round1.Hist) );
- }
- void CopyMap(Round &round1, Round &round2)
- {
- //printf("SIZEOFROUND %d\n", sizeof(round2.Map));
- //printf("SIZEOFROUND %d\n", sizeof(round2.Map));
- //memcpy(&round1.Map, &round2.Map, sizeof(&round1.Map) );
- }
- //0 1 2 3
- //4 5 6 7
- //8 9 10 11
- //12 13 14 15
- int MapDefault[] = {1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1}; //Start
- int UpArray[] = {8,9,10,11,12,13,14,15}; //Can be kicked up
- int DownArray[] = {0,1,2,3,4,5,6,7};
- int LeftArray[] = {2,3,6,7,10,11,14,15};
- int RightArray[] = {0,1,4,5,8,9,12,13};
- #define UP 1
- #define DOWN 2
- #define LEFT 3
- #define RIGHT 4
- int Possibilities;
- void PrintMapArray(int *MapArray)
- {
- int i = 0;
- int j = 0;
- for(i=0;i<4;i++)
- {
- for(j=0;j<4;j++)
- {
- printf("%d", MapArray[i*4+j]);
- }
- printf("\n");
- }
- printf("\n");
- }
- void PrintMap(Round &round)
- {
- int i = 0;
- int j = 0;
- printf("\n");
- printf("\n");
- for(i=0;i<4;i++)
- {
- for(j=0;j<4;j++)
- {
- printf("%d", round.Map[i*4+j]);
- }
- printf("\n");
- }
- printf("\n");
- }
- void InitRound(Round &round)
- {
- int i;
- //round.LastChecked = -1;
- round.RoundNum = 1;
- round.Map.resize (16, 1);
- round.RoundPrev = NULL;
- //for(i=0;i<16;i++)
- //{
- // printf("%d", round.Map[i]);
- //}
- round.Hist.resize (32, 0);
- round.Poss.resize (32, NULL);
- //printf("\n\n");
- }
- void CopyArray(int *Array1, int *Array2)
- {
- int Size = sizeof(*Array2);///sizeof(int);
- printf("size = %d\n", Size);
- }
- void CheckKicks(Round &round)
- {
- int i;
- int ball;
- Round *roundtemp;
- //UP
- for(i=0;i<8;i++)
- {
- ball = UpArray[i];
- //Check ball = 1
- //Check ball above = 1
- //Check ball above that = 0
- if( (round.Map[ball]==1) && (round.Map[ball-COL]==1) && (round.Map[ball-2*COL]==0) )
- {
- //printf("Can kick ball %d UP\n", ball);
- roundtemp = new Round;
- InitRound(*roundtemp);
- //Adjust the kick for the next map here
- (*roundtemp).Map = round.Map;
- (*roundtemp).Map[ball] = 0;
- (*roundtemp).Map[ball-COL]=0;
- (*roundtemp).Map[ball-2*COL]=1;
- //Record the kick in hist.
- round.Hist[2*(round.RoundNum-1)]=ball;
- round.Hist[(2*round.RoundNum)-1]=UP;
- (*roundtemp).Hist = round.Hist;
- (*roundtemp).RoundNum = round.RoundNum + 1;
- //NEED TO COPY THE STATS FROM THE LAST ARRAY!!!!!!!!!!!!!
- //LASTLY, GO SOLVE THAT NODE, 14 deep.
- CheckKicks(*roundtemp);
- }
- }
- //DOWN
- for(i=0;i<8;i++)
- {
- ball = DownArray[i];
- //Check ball = 1
- //Check ball below = 1
- //Check ball below that = 0
- if( (round.Map[ball]==1) && (round.Map[ball+COL]==1) && (round.Map[ball+2*COL]==0) )
- {
- //printf("Can kick ball %d DOWN\n", ball);
- roundtemp = new Round;
- InitRound(*roundtemp);
- //Adjust the kick for the next map here
- (*roundtemp).Map = round.Map;
- (*roundtemp).Map[ball] = 0;
- (*roundtemp).Map[ball+COL]=0;
- (*roundtemp).Map[ball+2*COL]=1;
- //Record the kick in hist.
- round.Hist[2*(round.RoundNum-1)]=ball;
- round.Hist[(2*round.RoundNum)-1]=DOWN;
- (*roundtemp).Hist = round.Hist;
- (*roundtemp).RoundNum = round.RoundNum + 1;
- //NEED TO COPY THE STATS FROM THE LAST ARRAY!!!!!!!!!!!!!
- //LASTLY, GO SOLVE THAT NODE, 14 deep.
- CheckKicks(*roundtemp);
- }
- }
- //LEFT
- for(i=0;i<8;i++)
- {
- ball = LeftArray[i];
- //Check ball = 1
- //Check ball left = 1
- //Check ball left of that = 0
- if( (round.Map[ball]==1) && (round.Map[ball-1]==1) && (round.Map[ball-2*1]==0) )
- {
- //printf("Can kick ball %d LEFT\n", ball);
- roundtemp = new Round;
- InitRound(*roundtemp);
- //Adjust the kick for the next map here
- (*roundtemp).Map = round.Map;
- (*roundtemp).Map[ball] = 0;
- (*roundtemp).Map[ball-1]=0;
- (*roundtemp).Map[ball-2*1]=1;
- //Record the kick in hist.
- round.Hist[2*(round.RoundNum-1)]=ball;
- round.Hist[(2*round.RoundNum)-1]=LEFT;
- (*roundtemp).Hist = round.Hist;
- (*roundtemp).RoundNum = round.RoundNum + 1;
- //NEED TO COPY THE STATS FROM THE LAST ARRAY!!!!!!!!!!!!!
- //LASTLY, GO SOLVE THAT NODE, 14 deep.
- CheckKicks(*roundtemp);
- }
- }
- //RIGHT
- for(i=0;i<8;i++)
- {
- ball = RightArray[i];
- //Check ball = 1
- //Check ball right = 1
- //Check ball right of that = 0
- if( (round.Map[ball]==1) && (round.Map[ball+1]==1) && (round.Map[ball+2*1]==0) )
- {
- //printf("Can kick ball %d RIGHT\n", ball);
- roundtemp = new Round;
- InitRound(*roundtemp);
- //Adjust the kick for the next map here
- (*roundtemp).Map = round.Map;
- (*roundtemp).Map[ball] = 0;
- (*roundtemp).Map[ball+1]=0;
- (*roundtemp).Map[ball+2*1]=1;
- //Record the kick in hist.
- round.Hist[2*(round.RoundNum-1)]=ball;
- round.Hist[(2*round.RoundNum)-1]=RIGHT;
- (*roundtemp).Hist = round.Hist;
- (*roundtemp).RoundNum = round.RoundNum + 1;
- //NEED TO COPY THE STATS FROM THE LAST ARRAY!!!!!!!!!!!!!
- //LASTLY, GO SOLVE THAT NODE, 14 deep.
- CheckKicks(*roundtemp);
- }
- }
- //for(i=0;i<32;i++)
- //{
- // printf("%d", round.Hist[i]);
- //}
- //printf("\n\n");
- if(round.RoundNum > LASTROUND)
- {
- Possibilities++;
- //printf("Got close\n");
- //DUMP EVERYTHING
- //for(i=0;i<32;i++)
- //{
- // if(round.Hist[i]<10)
- // {
- // printf(" ");
- // }
- // printf("%d", round.Hist[i]);
- // }
- // printf("\n\n");
- }
- delete (&round);
- //DELETE THIS NODE HERE.
- }
- void CopyArrayToRoundMap(int *MapDefault, Round &round)
- {
- int i;
- printf("Sizeof Map = %d", round.Map.size());
- for(i=0;i<16;i++)
- {
- round.Map[i] = MapDefault[i];
- }
- }
- /*
- void InitMap(vector<int> &Map)
- {
- int i;
- Map.resize (16, 1);
- for(i=0;i<16;i++)
- {
- printf("%d", Map[i]);
- }
- printf("\n\n");
- }
- */
- int main ()
- {
- int i = 0;
- Possibilities = 0;
- PrintMapArray(MapDefault);
- Round *roundstart = new Round;
- printf("%d \n", sizeof(MapDefault));
- InitRound(*roundstart);
- CopyArrayToRoundMap(MapDefault, *roundstart);
- PrintMap(*roundstart);
- CheckKicks(*roundstart);
- printf("Possibilities: %d", Possibilities);
- //210422 SOLUTIONS
- cout << "To close type something and hit enter: ";
- cin >> i;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement