Guest User

Untitled

a guest
Mar 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. /**
  2. * Scans the whole chess board to see if a piece can reach the king
  3. * of the specified color.
  4. * @param turn This is the color of the piece we are searching for with white=true, black=false
  5. * @return the Piece that is causing a check or null if there is no check
  6. */
  7. public static Piece check(boolean turn) {
  8. for(int i=0; i < 8;i++) {
  9. for(int j =0; j < 8; j++) {
  10. if(turn && board[i][j] != null && board[i][j].color ) {
  11. if(board[i][j].validMove(board, j, i, bKing.position[1], bKing.position[0], true)) return board[i][j];
  12. }
  13. if(!turn && board[i][j] != null && !board[i][j].color) {
  14. if(board[i][j].validMove(board, j, i, wKing.position[1], wKing.position[0], true)) return board[i][j];
  15. }
  16. }
  17. }
  18. return null;
  19. }
Add Comment
Please, Sign In to add comment