Advertisement
Guest User

Untitled

a guest
Aug 19th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. package eecs285.proj2.holtad;
  2.  
  3. public class Pawn extends ChessPiece
  4. {
  5.  
  6. Pawn(String incolor,int inType)
  7. {
  8. super(incolor, inType);
  9. }
  10.  
  11. public String toString()
  12. {
  13. return color+"P";
  14. }
  15.  
  16.  
  17. public boolean isGood(int newRow, int newCol, ChessPiece inboard[][])
  18. {
  19. int moveforward = Math.abs(currentRow-newRow);
  20.  
  21. int rowdistance = Math.abs(currentRow-newRow);
  22. int coldistance = Math.abs(currentCol-newCol);
  23.  
  24.  
  25. if((0<=newCol)&&(newCol<8)&&(0<=newRow)&&(newRow<8)) //Check if within bounds
  26. {
  27.  
  28. if(this.color=="b")//black pawns
  29. {
  30. //System.out.println("BLACK");
  31. //if(inboard[6][currentCol]==null)
  32. //if(this==inboard[6][currentCol])
  33. if(currentCol==1)
  34. {
  35. System.out.println("BLACK");
  36. if((moveforward==1)&&(inboard[newRow][newCol].color==null))
  37. {
  38. return true;
  39. }
  40. else if((moveforward==2)&&(inboard[newRow][newCol].color==null)&&(inboard[(newRow+currentRow)/2][newCol].color==null))
  41. {
  42. return true;
  43. }
  44. }
  45. }
  46. else if(this.color=="w")
  47. {
  48. //System.out.println("WHITE");
  49. //if(inboard[1][currentCol]==null)
  50. //if(this==inboard[1][currentCol])
  51. if(currentRow==1)
  52. {
  53. System.out.println("WHITE");
  54.  
  55. if((moveforward==1)&&(inboard[newRow][newCol].color==null))
  56. {
  57. return true;
  58. }
  59. else if((moveforward==2)&&(inboard[newRow][newCol].color==null)&&(inboard[(newRow+currentRow)/2][newCol].color==null))
  60. {
  61. return true;
  62. }
  63. }
  64. }
  65. else if(this.color=="w"||this.color=="b")
  66. {
  67.  
  68. if(rowdistance==1 && coldistance==1 && inboard[newRow][newCol].color!=this.color)//diagonal attack
  69. {
  70. return true;
  71. }
  72. else if(moveforward==1 && inboard[newRow][newCol].color==null)
  73. {
  74. return true;
  75. }
  76. }
  77. }
  78. //END of isGood
  79.  
  80. return false;
  81.  
  82.  
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement