Bug 234 - Lack of initializing of variables before a new while loop
Summary: Lack of initializing of variables before a new while loop
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:18 HKT by Andy
Modified: 2017-11-30 00:18 HKT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andy 2017-11-30 00:18:58 HKT
private boolean checkDiagonal(){//for bishop and queen 
		int x = king_x;
		int y = king_y;
		
		while(x<7 && y<7){//northEast
			x++;
			y++;
			Piece temp= board.getPiece(x, y);
			if(temp!=null){
				if(temp.getColor()==color)
					return false;
				else
					if(temp instanceof Bishop||temp instanceof Queen){
						return true;
					}
			}
			
		}
		
		while(x>0 && y>0){}
			...
		}
	}
X and y have not been initialized before the second while loop, which will result in getting the wrong position information of king.