daily pastebin goal
37%
SHARE
TWEET

Metukan

a guest Jan 19th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Chess {
  2.     private int rookRow, rookCol;
  3.     private int bishopRow, bishopCol;
  4.  
  5.     public Chess(int rookRow, int rookCol, int bishopRow, int bishopCol) {
  6.         this.rookRow = rookRow;
  7.         this.rookCol = rookCol;
  8.         this.bishopRow = bishopRow;
  9.         this.bishopCol = bishopCol;
  10.     }
  11.  
  12.     public void setRookRow(int rookRow) {
  13.         this.rookRow = rookRow;
  14.     }
  15.  
  16.     public void setRookCol(int rookCol) {
  17.         this.rookCol = rookCol;
  18.     }
  19.  
  20.     public void setBishopRow(int bishopRow) {
  21.         this.bishopRow = bishopRow;
  22.     }
  23.  
  24.     public void setBishopCol(int bishopCol) {
  25.         this.bishopCol = bishopCol;
  26.     }
  27.    
  28.  
  29.     // 2
  30.     public int getBiggerCol() {
  31.         // do not get afraid from the syntax, it means
  32.         /*
  33.         if(this.bishopRow > this.rookCol) {
  34.             return this.bishopCol;
  35.         } else {
  36.             return this.rookCol;
  37.         }
  38.         */
  39.         return (this.bishopCol > this.rookCol) ? this.bishopCol : this.rookCol;
  40.     }
  41.  
  42.     // 3
  43.     public String getRookColor() {
  44.         return getCellColor(this.rookRow, this.rookCol);
  45.     }
  46.  
  47.     // 4
  48.     public boolean isRookAndBishopSameCell() {
  49.         return getCellColor(this.bishopRow, this.bishopCol) == getCellColor(this.rookRow, this.rookCol);
  50.     }
  51.  
  52.     // helper for 3 and 4
  53.     public static String getCellColor(int row, int col) {
  54.     // "Black" or "White"
  55.         // logic - add row and col (assuming range 1-8 inclusive). if its even then white, otherwise black.
  56.         // again - do not get afraid from the syntax, its if(cond) ? return this one : (else) return thisone
  57.         return ((row + col) % 2) == 0 ? "White" : "Black";
  58.     }
  59.  
  60.     //5
  61.     public int colDistanceBetweenRookAndBishop(){
  62.         return Math.abs(this.rookCol - this.bishopCol);
  63.     }
  64.  
  65.     // 6
  66.     public boolean six() {
  67.         if(this.rookRow != 1) {
  68.             return false;
  69.         }
  70.  
  71.         return this.rookCol > 1 && this.rookCol < 8;
  72.     }
  73.  
  74.     // 7
  75.     public boolean rookThreatsBishop() {
  76.         // assuming they are not in the same position - in this case i dont know what to do
  77.         return this.rookRow == this.bishopRow || this.rookCol == this.bishopCol;
  78.     }
  79.  
  80.     public static boolean isLegalCell(int row, int col) {
  81.         return row >= 1 && row <= 8 && col >= 1 && col <= 8;
  82.     }
  83.  
  84.     // 8
  85.     public boolean bishopThreatsRook() {
  86.         int dRow = Math.abs(this.rookRow - this.bishopRow);
  87.         int dCol = Math.abs(this.rookCol - this.bishopCol);
  88.         return dRow == dCol;
  89.     }  
  90.  
  91.     @Override
  92.     public String toString() {
  93.         return "Rook: (" + rookRow + "," + rookCol + ") ,  Bishop: (" + bishopRow + "," + bishopCol + ")";
  94.     }
  95.  
  96.     public static void main(String[] args) {
  97.       System.out.println("hi");
  98.     }
  99. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top