Bug 233

Summary: Outofboundary error caused by checkPawn()
Product: CS3343 group25 chess game Reporter: Andy <dotafterfootball>
Component: chess gameAssignee: HUANG Xiaofeng <xhuang227-c>
Status: CONFIRMED ---    
Severity: enhancement    
Priority: ---    
Version: unspecified   
Hardware: PC   
OS: Mac OS   
Attachments: Bug

Description Andy 2017-11-30 00:14:36 HKT
Created attachment 11 [details]
Bug

private boolean checkPawn(){
		int x = king_x;
		int y = king_y;
		Piece temp1,temp2;
		if(color){
			temp1 = board.getPiece(x+1, y+1);
			temp2 = board.getPiece(x+1, y-1);
			if((temp1!=null && temp1 instanceof Pawn && temp1.getColor()!=color) ||
					(temp2!=null && temp2 instanceof Pawn && temp2.getColor()!=color))
				return true;
			else
				return false;
		}
			
		else{
			temp1 = board.getPiece(x-1, y+1);
			temp2 = board.getPiece(x-1, y-1);
			if((temp1!=null && temp1 instanceof Pawn && temp1.getColor()!=color) ||
					(temp2!=null && temp2 instanceof Pawn && temp2.getColor()!=color))
				return true;
			else
				return false;
		}
	}

temp1 = board.getPiece(x+1, y+1);
temp2 = board.getPiece(x+1, y-1);

These two lines may cause Outofboundary error if x=7 or y=7. There should be a boundary check before it.