Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. bool invalidMove(int row, int col, char direction) {
  2.  
  3.   bool invalidLine = true;
  4.  
  5.   if (!(0<=row && row <=2 )) {
  6.     return true;
  7.   }
  8.   else if (!(0<=col && col <=2 )) {
  9.     return true;
  10.   }
  11.   else if ((direction != 'u') && (direction != 'l') && (direction != 'd') && (direction != 'r')) {
  12.     return true;
  13.   }
  14.  
  15.   if (row == 0 && direction == 'u')
  16.   return true;
  17.   if (row == 2 && direction == 'd')
  18.   return true;
  19.   if (col == 0 && direction == 'l')
  20.   return true;
  21.   if (col == 2 && direction == 'r')
  22.   return true;
  23.  
  24.   if (direction == 'u' || direction == 'd') {
  25.     int linerow = row;
  26.    
  27.   if (direction == 'u')
  28.   --linerow;
  29.  
  30.   if (grid.vertical(linerow, col) == true)
  31.   invalidLine = false;
  32.  
  33.   }
  34.   else if (direction == 'l' || direction == 'r') {
  35.     int linecolumn = col;
  36.     if (direction == 'l')
  37.     --linecolumn;
  38.    
  39.     if(grid.horizontal(row,linecolumn) == true)
  40.     invalidLine = false;
  41.    
  42. return (!invalidLine);
  43.   }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement