Advertisement
A0D1MQ

pengiuns_checkMovement

Jan 5th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | None | 0 0
  1. int moveIsPossible(int Row, int Col, int Destx, int Desty)
  2. {
  3.  
  4.  
  5.     int i, canMove = 0;
  6.     int dx,dy,dir;
  7.     dx=Destx-Row;
  8.     dy=Desty-Col;
  9.  
  10.     if (Row%2==0)
  11.     {
  12.         if (dx== -1&& dy== 0 ) {dir = 1;}
  13.         if (dx==  1&& dy== 0) {dir = 2;}
  14.         if (dx==  0&& dy== -1) {dir = 3;}
  15.         if (dx==  0&& dy== 1) {dir = 4;}
  16.         if (dx==  1&& dy== -1) {dir = 5;}
  17.         if (dx==  1&& dy== 1) {dir = 6;}
  18.     }
  19.     else
  20.     {
  21.         if (dx== -1&& dy== 0 ) {dir = 1;}
  22.         if (dx==  1&& dy== 0) {dir = 2;}
  23.         if (dx== -1&& dy== -1) {dir = 3;}
  24.         if (dx== -1&& dy== 1) {dir = 4;}
  25.         if (dx==  0&& dy== -1) {dir = 5;}
  26.         if (dx==  0&& dy== 1) {dir = 6;}
  27.     }
  28.  
  29.     for(i = 0; i < 20; i++) {
  30.         if(Row % 2 == 1) {
  31.             switch(dir) { //Default the switch to what?
  32.                 case 1:
  33.                     Row--;
  34.                     break;
  35.                 case 2:
  36.                     Row++;
  37.                     break;
  38.                 case 3:
  39.                     Row--;
  40.                     Col--;
  41.                     break;
  42.                 case 4:
  43.                     Row--;
  44.                     Col++;
  45.                     break;
  46.                 case 5:  
  47.                     Col--;
  48.                     break;
  49.                 case 6:  
  50.                     Col++;
  51.                     break;
  52.             }
  53.             if (Destx==Row && Desty==Col)
  54.                 return 1;
  55.             if(brdTab[Col][Row]>=1 && brdTab[Col][Row]<=3)
  56.                 canMove = 1;
  57.             else
  58.                 return 0;
  59.         } else {
  60.             switch(dir) {
  61.                 case 1:
  62.                     Row--;
  63.                     break;
  64.                 case 2:
  65.                     Row++;
  66.                     break;
  67.                 case 3:
  68.                     Col--;
  69.                     break;
  70.                 case 4:
  71.                     Col++;
  72.                     break;
  73.                 case 5:  
  74.                     Row++;
  75.                     Col--;
  76.                     break;
  77.                 case 6:  
  78.                     Row++;
  79.                     Col++;
  80.                     break;
  81.             }
  82.             if (Destx==Row && Desty==Col)
  83.                 return 1;
  84.             if(brdTab[Col][Row]>=1 && brdTab[Col][Row]<=3)
  85.                 canMove = 1;
  86.             else
  87.                 return 0;
  88.         }
  89.     }
  90.     if (Destx==Row && Desty==Col)
  91.         return 1;
  92.     else
  93.         return 0;
  94.     return canMove;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement