Bug 233 - Outofboundary error caused by checkPawn()
Summary: Outofboundary error caused by checkPawn()
Status: CONFIRMED
Alias: None
Product: CS3343 group25 chess game
Classification: Unclassified
Component: chess game (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- enhancement
Assignee: HUANG Xiaofeng
URL:
Depends on:
Blocks:
 
Reported: 2017-11-30 00:14 HKT by Andy
Modified: 2017-11-30 00:14 HKT (History)
0 users

See Also:


Attachments
Bug (335.61 KB, image/png)
2017-11-30 00:14 HKT, Andy
Details

Note You need to log in before you can comment on or make changes to this 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.