Bug 740 - When you try to castle, King disappears, and Rook moves to King's position
Summary: When you try to castle, King disappears, and Rook moves to King's position
Status: RESOLVED FIXED
Alias: None
Product: Chess Game - Group 24
Classification: Unclassified
Component: Pieces (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- major
Assignee: gsalter2-c
URL:
Depends on:
Blocks:
 
Reported: 2022-11-28 01:57 HKT by gsalter2-c
Modified: 2022-11-28 14:34 HKT (History)
1 user (show)

See Also:


Attachments
When you try to castle, King disappears, and Rook moves to King's position (51.59 KB, image/png)
2022-11-28 01:57 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 01:57:15 HKT
Created attachment 136 [details]
When you try to castle, King disappears, and Rook moves to King's position

Steps to reproduce:
Make the following moves:
1. e4 e5 2. Nc3 nf6 3. d4 d5 4. Be4 bd6 5. Qd3 Qd6 6. O-O-O

On the last move, when we try to do Queen's side castle, on the GUI the King disappears, and the Rook occupies the King's place.

Expected results:
  ABCDEFGH
0  R   BNR
1 PPP  PPP
2   NQ    
3    PPB  
4   bpp   
5    q n  
6 ppp  ppp
7 rnb  rk

Actual results:
But on the console shows that the king and didn't move.
  ABCDEFGH
0  R   BNR
1 PPP  PPP
2   NQ    
3    PPB  
4   bpp   
5    q n  
6 ppp  ppp
7 rnb k  r
Comment 1 gsalter2-c 2022-11-28 02:12:53 HKT
Reason:
GUI class stores its own chess board in a linked lits, separate from the Game class' chess board. Castle move is identified as invalid by Game class, but GUI class still updates anyway. Game status in the GUI and Game are not synchronized.

Resolution:
Modify GUI logic to copy the chess board stored in Game to GUI everytime there is an update. This ensures GUI and Game chess boards are synchronized.

https://github.com/glennsalter/cs3343-chess/commit/0ccccfc9879166374c4d3d944ed0f25981f58d7c
Comment 2 gsalter2-c 2022-11-28 02:35:10 HKT
Resolution:
Implement checking for castle by deep copying the board, and checking if a move results in a valid castle instead of moving the pieces in the current board, which will triger rook/ king to update its already moved status.

https://github.com/glennsalter/cs3343-chess/commit/83331989258063560bb3c97f31e81ac5bdc2aee1