Bug 743 - Wrong pawn promotion logic
Summary: Wrong pawn promotion logic
Status: RESOLVED FIXED
Alias: None
Product: Chess Game - Group 24
Classification: Unclassified
Component: Chess (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- enhancement
Assignee: jtoromano2-c
URL:
Depends on:
Blocks:
 
Reported: 2022-11-28 14:47 HKT by gsalter2-c
Modified: 2022-11-28 16:03 HKT (History)
1 user (show)

See Also:


Attachments
Wrong pawn promotion logic (44.18 KB, image/png)
2022-11-28 14:47 HKT, gsalter2-c
Details

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