Bug 743

Summary: Wrong pawn promotion logic
Product: Chess Game - Group 24 Reporter: gsalter2-c
Component: ChessAssignee: jtoromano2-c
Status: RESOLVED FIXED    
Severity: enhancement CC: gsalter2-c
Priority: ---    
Version: unspecified   
Hardware: PC   
OS: Mac OS   
Attachments: Wrong pawn promotion logic

Description gsalter2-c 2022-11-28 14:47:20 HKT
Created attachment 138 [details]
Wrong pawn promotion logic

Steps to reproduce:
1. Run App.java
2. Make the following moves:
   1. b4 g5 2. b5 g4 3. b6 g3 4. bxa7 gxh2 5. b8=Q g1=Q

On the last move two moves, we try to promote the pawns to a queens.

Expected results:
Pawn should turn into a queen.

Actual results:
Pawn remains a pawn.
Comment 1 jtoromano2-c 2022-11-28 16:02:25 HKT
Reason:
Control logic of pawn movement was incorrect. When testing if pawn can move, we have swapped directions of the move, and as such, valid move is not recognized. 

Resolution:

Changing condition
 start.getX() == endX + dir to
 start.getX() + dir == endX. 

dir is variable representing direction of the move (+1 for white, -1 for black), and move is valid if start position plus direction equals end position.