Bug 225 - Incorrect return result caused by missing of "return false" in move function in ChessBoard class
Summary: Incorrect return result caused by missing of "return false" in move function ...
Status: RESOLVED FIXED
Alias: None
Product: CS3343 group25 chess game
Classification: Unclassified
Component: chess game (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- critical
Assignee: Andy
URL:
Depends on:
Blocks:
 
Reported: 2017-11-28 20:35 HKT by Andy
Modified: 2017-11-28 20:43 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-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;
}
...