diff options
| author | Aditya Naik | 2018-05-13 05:13:02 -0400 |
|---|---|---|
| committer | Aditya Naik | 2018-05-13 05:13:02 -0400 |
| commit | 55dfaa12b18df66269e968e1bc2065f0dca4d0bd (patch) | |
| tree | a5029ffff7616773c1415052c6d8c44f52f4846d /10284/fen2.cpp | |
| parent | 9f8bb63d075ca87da8716bea6b66e69a3523d800 (diff) | |
FEN done, 3 years later
Diffstat (limited to '10284/fen2.cpp')
| -rw-r--r-- | 10284/fen2.cpp | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/10284/fen2.cpp b/10284/fen2.cpp index 1f238b5..ae52fe5 100644 --- a/10284/fen2.cpp +++ b/10284/fen2.cpp @@ -4,7 +4,7 @@ using namespace std; void addattack(int, int, int[][8]); void addbishopattack(int, int, int[][8]); - +void addrookattack(int i, int j, int board[][8]); int main(){ string fen; @@ -49,13 +49,13 @@ void addattack(int i, int j, int board[][8]){ //PAWNS if(board[i][j]==112){ //p if(i+1<8 && j-1>=0 && board[i+1][j-1]==0) - board[i+1][i-1]=1; + board[i+1][j-1]=1; if(i+1<8 && j+1<=7 && board[i+1][j+1]==0) board[i+1][j+1]=1; } else if(board[i][j]==80){//P if(i-1>=0 && j+1<=7 && board[i-1][j+1]==0) - board[i-1][j+1]=0; + board[i-1][j+1]=1; if(i-1>=0 && j-1>=0 && board[i-1][j-1]==0) board[i-1][j-1]=1; } @@ -95,6 +95,16 @@ void addattack(int i, int j, int board[][8]){ addbishopattack(i, j, board); } + //ROOKS + else if(board[i][j]==114 || board[i][j]==82){ + addrookattack(i, j, board); + } + + //QUEEN + else if(board[i][j]==81 || board[i][j]==113){ + addrookattack(i, j, board); + addbishopattack(i, j, board); + } } @@ -103,7 +113,7 @@ void addbishopattack(int i, int j, int board[][8]){ int trow=i, tcol=j; while(!conf){ tcol++;trow++; - if(tcol>=8 || trow>=8 || (board[trow][tcol]!=0 && board[trow][tcol]!=1)) + if(tcol>=8 || trow>=8 || board[trow][tcol]>1) conf=true; else board[trow][tcol]=1; } @@ -112,7 +122,7 @@ void addbishopattack(int i, int j, int board[][8]){ trow=i;tcol=j; while(!conf){ tcol++;trow--; - if(tcol>=8 || trow<0 || (board[trow][tcol]!=0 && board[trow][tcol]!=1)) + if(tcol>=8 || trow<0 || board[trow][tcol]>1) conf=true; else board[trow][tcol]=1; } @@ -121,7 +131,7 @@ void addbishopattack(int i, int j, int board[][8]){ trow=i; tcol=j; while(!conf){ tcol--;trow--; - if(tcol<0 || trow<0 || (board[trow][tcol]!=0 && board[trow][tcol]!=1)) + if(tcol<0 || trow<0 || board[trow][tcol]>1) conf=true; else board[trow][tcol]=1; } @@ -130,7 +140,46 @@ void addbishopattack(int i, int j, int board[][8]){ trow=i; tcol=j; while(!conf){ tcol--;trow++; - if(tcol<0 || trow>=8 || (board[trow][tcol]!=0 && board[trow][tcol]!=1)) + if(tcol<0 || trow>=8 || board[trow][tcol]>1) + conf=true; + else board[trow][tcol]=1; + } +} + +void addrookattack(int i, int j, int board[][8]){ + bool conf=false; + + int trow=i, tcol=j; + while(!conf){ + trow++; + if(trow>=8 || board[trow][tcol]>1) + conf=true; + else board[trow][tcol]=1; + } + + conf=false; + trow=i; tcol=j; + while (!conf){ + trow--; + if(trow<0 || board[trow][tcol]>1) + conf=true; + else board[trow][tcol]=1; + } + + conf=false; + trow=i; tcol=j; + while (!conf){ + tcol++; + if(tcol>=8 || board[trow][tcol]>1) + conf=true; + else board[trow][tcol]=1; + } + + conf=false; + trow=i;tcol=j; + while (!conf){ + tcol--; + if(tcol<0 || board[trow][tcol]>1) conf=true; else board[trow][tcol]=1; } |
