Advertisement
TeslaCoilGirl

isSafe Switch Statement.c

Dec 9th, 2021
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.85 KB | None | 0 0
  1. int isSafe(int board[8][8], int x, int y, int px, int py) {
  2.  
  3.     if (x < 0 || y < 0 || x == 8 || y == 8)
  4.         return 0;
  5.     if (board[x][y] == 1)
  6.         return 1;
  7.  
  8.     switch (px) {
  9.     case 0:
  10.         switch (py) {
  11.         case 0:
  12.             // BASE CASE HIT ONLY ONCE
  13.             return isSafe(board[8][8], x, y + 1, 0, 1) +
  14.                 isSafe(board[8][8], x, y - 1, 0, -1) +
  15.                 isSafe(board[8][8], x + 1, y, 1, 0) +
  16.                 isSafe(board[8][8], x + 1, y + 1, 1, 1) +
  17.                 isSafe(board[8][8], x + 1, y - 1, 1, -1) +
  18.                 isSafe(board[8][8], x - 1, y, -1, 0) +
  19.                 isSafe(board[8][8], x - 1, y + 1, -1, 1) +
  20.                 isSafe(board[8][8], x - 1, y - 1, -1, -1);
  21.             break;
  22.  
  23.         case 1:
  24.             return isSafe(board[8][8], x, y + 1, 0, 1);
  25.             break;
  26.         case -1;
  27.         return isSafe(board[8][8], x, y - 1, 0, -1);
  28.         break;
  29.         default:
  30.             return 0;
  31.             break;
  32.  
  33.         }
  34.         break;
  35.     case 1:
  36.         switch (py) {
  37.         case 0:
  38.             isSafe(board[8][8], x + 1, y, 1, 0);
  39.             break;
  40.         case 1:
  41.             isSafe(board[8][8], x + 1, y + 1, 1, 1)
  42.             break;
  43.         case -1:
  44.             isSafe(board[8][8], x + 1, y - 1, 1, -1)
  45.             break;
  46.         default:
  47.             return 0;
  48.             break;
  49.         }
  50.         break;
  51.     case -1:
  52.         switch (py) {
  53.         case 0;
  54.         isSafe(board[8][8], x - 1, y, -1, 0);
  55.         break;
  56.         case 1:
  57.             isSafe(board[8][8], x - 1, y + 1, -1, 1);
  58.             break;
  59.         case -1:
  60.             isSafe(board[8][8], x - 1, y - 1, -1, -1);
  61.             break;
  62.         default:
  63.             return 0;
  64.             break;
  65.  
  66.         }
  67.         break;
  68.  
  69.     default:
  70.         return 0;
  71.         break;
  72.  
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement