Advertisement
ToxicTroelsen

Untitled

May 1st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1. bool IllegalRookMove(int fromCol, int fromRow, int toCol, int toRow, int piece) {
  2.     int moveX = abs(fromCol - toCol);
  3.     int moveY = abs(fromRow - toRow);
  4.  
  5.     if(toCol != fromCol && toRow != fromRow) {
  6.         return true;
  7.     }
  8.  
  9.     if(fromCol == toCol) {
  10.         if(fromRow > toRow) {
  11.             for(int i = moveY; i > 0; i--) {
  12.                 if(IsOccupiedByTeam(piece, fromCol, fromRow - i)) {
  13.                     return true;
  14.                 }
  15.             }
  16.             for(int i = moveY; i > 1; i--) {
  17.                 if(IsOccupiedByEnemy(piece, fromCol, fromRow - i)) {
  18.                     return true;
  19.                 }
  20.             }
  21.            
  22.         }
  23.         if(toRow > fromRow) {
  24.             for(int i = 0; i < moveY; i++) {
  25.                 if(IsOccupiedByTeam(piece, fromCol, fromRow + i)) {
  26.                     return true;
  27.                 }
  28.             }
  29.             for(int i = 0; i < moveY - 1; i++) {
  30.                 if(IsOccupiedByEnemy(piece, fromCol, fromRow + i)) {
  31.                     return true;
  32.                 }
  33.             }
  34.         }
  35.     }
  36.     if(fromRow == toRow) {
  37.         if(fromCol > toCol) {
  38.             for(int i = moveX; i > 0; i--) {
  39.                 if(IsOccupiedByTeam(piece, fromCol - i, fromRow)) {
  40.                     return true;
  41.                 }
  42.             }
  43.             for(int i = moveX; i > 1; i--) {
  44.                 if(IsOccupiedByEnemy(piece, fromCol - i, fromRow)) {
  45.                     return true;
  46.                 }
  47.             }
  48.         }
  49.         if(toCol > fromCol) {
  50.             for(int i = 0; i < moveX; i++) {
  51.                 if(IsOccupiedByTeam(piece, fromCol + i, fromRow)) {
  52.                     return true;
  53.                 }
  54.             }
  55.             for(int i = 0; i < moveX - 1; i++) {
  56.                 if(IsOccupiedByEnemy(piece, fromCol + i, fromRow)) {
  57.                     return true;
  58.                 }
  59.             }
  60.         }
  61.     }
  62.     return false;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement