Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // initialize px and py to 0
- int isSafe(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;
- }
- // Gets called on initial iteration. Finds number of queens in the way.
- if(px==0&&py==0){
- return isSafe(board[8][8],x-1,y-1,-1,-1) + isSafe(board[8][8],x,y-1,0,-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,0) + isSafe(board[8][8],x+1,y+1,1,1) + isSafe(board[8][8],x,y+1,0,1) + isSafe(board[8][8],x-1,y+1,-1,1);
- }
- //x-1,y-1
- if(px=-1&&py=-1){
- return isSafe(board[8][8],x-1,y-1,-1,-1);
- }
- // x,y-1
- if(px==0&&py==-1){
- return isSafe(board[8][8],x,y-1,0,-1);
- }
- // x+1,y-1
- if(px==1&&py==-1){
- return isSafe(board[8][8],x+1,y-1,1,-1);
- }
- // x+1,y
- if(px==1&&py==0){
- return isSafe(board[8][8],x+1,y,1,0);
- }
- // x-1,y
- if(px==-1&&py==0){
- return isSafe(board[8][8],x-1,y,-1,0);
- }
- // x+1,y+1
- if(px==1&&py==1){
- return isSafe(board[8][8],x+1,y+1,1,1);
- }
- // x, y+1
- if(px==0&&py==1){
- return isSafe(board[8][8],x,y+1,0,1);
- }
- // x-1, y+1
- if(px==-1&&py==1){
- return isSafe(board[8][8],x-1,y+1,-1,1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement