Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package eecs285.proj2.holtad;
- public class Pawn extends ChessPiece
- {
- Pawn(String incolor,int inType)
- {
- super(incolor, inType);
- }
- public String toString()
- {
- return color+"P";
- }
- public boolean isGood(int newRow, int newCol, ChessPiece inboard[][])
- {
- int moveforward = Math.abs(currentRow-newRow);
- int rowdistance = Math.abs(currentRow-newRow);
- int coldistance = Math.abs(currentCol-newCol);
- if((0<=newCol)&&(newCol<8)&&(0<=newRow)&&(newRow<8)) //Check if within bounds
- {
- if(this.color=="b")//black pawns
- {
- //System.out.println("BLACK");
- //if(inboard[6][currentCol]==null)
- //if(this==inboard[6][currentCol])
- if(currentCol==1)
- {
- System.out.println("BLACK");
- if((moveforward==1)&&(inboard[newRow][newCol].color==null))
- {
- return true;
- }
- else if((moveforward==2)&&(inboard[newRow][newCol].color==null)&&(inboard[(newRow+currentRow)/2][newCol].color==null))
- {
- return true;
- }
- }
- }
- else if(this.color=="w")
- {
- //System.out.println("WHITE");
- //if(inboard[1][currentCol]==null)
- //if(this==inboard[1][currentCol])
- if(currentRow==1)
- {
- System.out.println("WHITE");
- if((moveforward==1)&&(inboard[newRow][newCol].color==null))
- {
- return true;
- }
- else if((moveforward==2)&&(inboard[newRow][newCol].color==null)&&(inboard[(newRow+currentRow)/2][newCol].color==null))
- {
- return true;
- }
- }
- }
- else if(this.color=="w"||this.color=="b")
- {
- if(rowdistance==1 && coldistance==1 && inboard[newRow][newCol].color!=this.color)//diagonal attack
- {
- return true;
- }
- else if(moveforward==1 && inboard[newRow][newCol].color==null)
- {
- return true;
- }
- }
- }
- //END of isGood
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement