Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int moveIsPossible(int Row, int Col, int Destx, int Desty)
- {
- int dx, dy, dir, i, x, y;
- if (Destx>Col) dx=1; //
- else if(Destx<Col) dx=-1; //
- else dx=0; // Check where we should make the first move to achieve destination
- if (Desty>Row) dy=1; //
- else if(Desty<Row) dy=-1; //
- else dy=0; //
- if (Row%2==0) ///even
- {
- if (dx==-1 && dy==0) {dir = 1;}
- if (dx==1 && dy==0) {dir = 2;}
- if (dx==0 && dy==-1) {dir = 3;} //Check which direction takes the first move (for even rows)
- if (dx==0 && dy==1) {dir = 4;}
- if (dx==1 && dy==-1) {dir = 5;}
- if (dx==1 && dy==1) {dir = 6;}
- }
- else ///odd
- {
- if (dx==-1 && dy==0) {dir = 1;}
- if (dx==1 && dy==0) {dir = 2;}
- if (dx==-1 && dy==-1) {dir = 3;} //Check which direction takes the first move (for odd rows)
- if (dx==-1 && dy==1) {dir = 4;}
- if (dx==0 && dy==-1) {dir = 5;}
- if (dx==0 && dy==1) {dir = 6;}
- }
- x=Col;
- y=Row;
- for(i=0; i<40; i++) //checking every move between start position and destination by moving in one direction
- { //(if we can achieve destination by moving in one direction these two positions are in a straight line)
- if(y % 2 == 1)
- {
- switch(dir)
- {
- case 1:
- x--;
- break;
- case 2:
- x++;
- break;
- case 3:
- x--;
- y--;
- break;
- case 4:
- x--;
- y++;
- break;
- case 5:
- y--;
- break;
- case 6:
- y++;
- break;
- }
- } else {
- switch(dir)
- {
- case 1:
- x--;
- break;
- case 2:
- x++;
- break;
- case 3:
- y--;
- break;
- case 4:
- y++;
- break;
- case 5:
- x++;
- y--;
- break;
- case 6:
- x++;
- y++;
- break;
- }
- }
- if (x==Destx && y==Desty && (brdTab[y+1][x] >=1 && brdTab[y+1][x] <=3))
- return 1; //if computed x and y is equal to destination x and y
- //AND destination tile exists and there is no penguin - can move to this position
- }
- return 0; // if ^ not true - cannot move
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement