Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. public boolean checkifEmpty(int fromRow, int fromColumn, int toRow,
  2. int toColumn, Figure[][] ChessBoard) {
  3. int differenceInRows = Math.abs(fromRow - toRow);
  4. if (differenceInRows == 1 ) {
  5. return true;
  6. }
  7.  
  8. for (int j = 1; j < differenceInRows; j++) {
  9. if ((toRow < fromRow) && (toColumn > fromColumn)
  10. && ChessBoard[fromRow - j][fromColumn + j] == null) {
  11. return true;
  12. } else if ((toRow > fromRow) && (toColumn > fromColumn)
  13. && ChessBoard[fromRow + j][fromColumn + j] == null) {
  14. return true;
  15. } else if ((toRow > fromRow) && (toColumn < fromColumn)
  16. && ChessBoard[fromRow + j][fromColumn - j] == null) {
  17. return true;
  18. } else if ((toRow < fromRow) && (toColumn < fromColumn)
  19. && ChessBoard[fromRow - j][fromColumn - j] == null) {
  20. return true;
  21. }
  22.  
  23. }
  24. return false;
  25. }
  26.  
  27. public boolean checkifEmpty(int fromRow, int fromColumn, int toRow,
  28. int toColumn, Figure[][] ChessBoard) {
  29. int differenceInRows = Math.abs(fromRow - toRow);
  30.  
  31. for (int j = 1; j < differenceInRows; j++) {
  32. if ((toRow < fromRow) && (toColumn > fromColumn)
  33. && ChessBoard[fromRow - j][fromColumn + j] != null) {
  34. return false;
  35. } else if ((toRow > fromRow) && (toColumn > fromColumn)
  36. && ChessBoard[fromRow + j][fromColumn + j] != null) {
  37. return false;
  38. } else if ((toRow > fromRow) && (toColumn < fromColumn)
  39. && ChessBoard[fromRow + j][fromColumn - j] != null) {
  40. return false;
  41. } else if ((toRow < fromRow) && (toColumn < fromColumn)
  42. && ChessBoard[fromRow - j][fromColumn - j] != null) {
  43. return false;
  44. }
  45.  
  46. }
  47. return true;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement