Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int isSafe(int board[8][8], int x, int y, int px, int py) {
- if (x < 0 || y < 0 || x == 8 || y == 8)
- return 0;
- if (board[x][y] == 1)
- return 1;
- switch (px) {
- case 0:
- switch (py) {
- case 0:
- // BASE CASE HIT ONLY ONCE
- return isSafe(board[8][8], x, y + 1, 0, 1) +
- isSafe(board[8][8], x, y - 1, 0, -1) +
- isSafe(board[8][8], x + 1, y, 1, 0) +
- isSafe(board[8][8], x + 1, y + 1, 1, 1) +
- isSafe(board[8][8], x + 1, y - 1, 1, -1) +
- isSafe(board[8][8], x - 1, y, -1, 0) +
- isSafe(board[8][8], x - 1, y + 1, -1, 1) +
- isSafe(board[8][8], x - 1, y - 1, -1, -1);
- break;
- case 1:
- return isSafe(board[8][8], x, y + 1, 0, 1);
- break;
- case -1;
- return isSafe(board[8][8], x, y - 1, 0, -1);
- break;
- default:
- return 0;
- break;
- }
- break;
- case 1:
- switch (py) {
- case 0:
- isSafe(board[8][8], x + 1, y, 1, 0);
- break;
- case 1:
- isSafe(board[8][8], x + 1, y + 1, 1, 1)
- break;
- case -1:
- isSafe(board[8][8], x + 1, y - 1, 1, -1)
- break;
- default:
- return 0;
- break;
- }
- break;
- case -1:
- switch (py) {
- case 0;
- isSafe(board[8][8], x - 1, y, -1, 0);
- break;
- case 1:
- isSafe(board[8][8], x - 1, y + 1, -1, 1);
- break;
- case -1:
- isSafe(board[8][8], x - 1, y - 1, -1, -1);
- break;
- default:
- return 0;
- break;
- }
- break;
- default:
- return 0;
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement