Bug 225

Summary: Incorrect return result caused by missing of "return false" in move function in ChessBoard class
Product: CS3343 group25 chess game Reporter: Andy <dotafterfootball>
Component: chess gameAssignee: Andy <dotafterfootball>
Status: RESOLVED FIXED    
Severity: critical    
Priority: ---    
Version: unspecified   
Hardware: PC   
OS: Mac OS   

Description Andy 2017-11-28 20:35:47 HKT
One of the bug code:

public boolean move(int x,int y,int target_x,int target_y){

...

if(p instanceof Bishop) {
			
	if(p.isValid(x,y,target_x,target_y)&&check.checkBishipBlock(x, y, target_x, target_y)){
	      theChessBoard.initialize(target_x, target_y,theChessBoard.getPiece(x, y));
	      theChessBoard.initialize(x, y, null);
	}
        else
              System.out.println("Invalid Move");
}

...

return true;
}

In the listing code, isValid() method is used to judge whether the move of this bishop is valid or not. If not, it should return false and print "Invalid Move". But actually, it only prints the message but does not return any value. In the end, the move function will return true. But in fact, it is an invalid move, so it should return false.

Modified code:

...
else{
              System.out.println("Invalid Move");
              return false;
}
...