Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Scans the whole chess board to see if a piece can reach the king
- * of the specified color.
- * @param turn This is the color of the piece we are searching for with white=true, black=false
- * @return the Piece that is causing a check or null if there is no check
- */
- public static Piece check(boolean turn) {
- for(int i=0; i < 8;i++) {
- for(int j =0; j < 8; j++) {
- if(turn && board[i][j] != null && board[i][j].color ) {
- if(board[i][j].validMove(board, j, i, bKing.position[1], bKing.position[0], true)) return board[i][j];
- }
- if(!turn && board[i][j] != null && !board[i][j].color) {
- if(board[i][j].validMove(board, j, i, wKing.position[1], wKing.position[0], true)) return board[i][j];
- }
- }
- }
- return null;
- }
Add Comment
Please, Sign In to add comment