Castling Fix

main
Brett 2022-12-19 22:36:27 -05:00
parent a06d971fcc
commit b442d9227d
1 changed files with 22 additions and 9 deletions

View File

@ -54,11 +54,17 @@ public class King extends ChessPiece {
private void castleRight(){ private void castleRight(){
// casting has to move the rook on the right size of the king from white's perspective // casting has to move the rook on the right size of the king from white's perspective
if (this.isWhite) if (this.isWhite) {
b.movePiece(b.size() - 1, 0, b.size() - 3, 0); var p = b.get(b.size() - 1, 0);
else p.move(new Move(b.size() - 3, 0));
b.movePiece(b.size()-1, b.size()-1, b.size()-3, b.size()-1) b.set(b.size() - 3, 0, p);
b.set(b.size()-3, b.size()-1, b.get(b.size()-1, b.size()-1)); b.set(b.size() - 1, 0, null);
} else {
var p = b.get(b.size() - 1, b.size() - 1);
p.move(new Move(b.size() - 3, b.size() - 1));
b.set(b.size() - 3, b.size() - 1, p);
b.set(b.size() - 1, b.size() - 1, null);
}
} }
private boolean checkIfRookValid(ChessPiece piece){ private boolean checkIfRookValid(ChessPiece piece){
@ -67,9 +73,16 @@ public class King extends ChessPiece {
private void castleLeft(){ private void castleLeft(){
// casting has to move the rook on the left size of the king from white's perspective // casting has to move the rook on the left size of the king from white's perspective
if (this.isWhite) if (this.isWhite) {
b.set(3, 0, b.get(0, 0)); var p = b.get(0, 0);
else p.move(new Move(3, 0));
b.set(3, b.size()-1, b.get(0, b.size()-1)); b.set(3, 0, p);
b.set(0, 0, null);
} else {
var p = b.get(0, b.size() - 1);
p.move(new Move(3, b.size() - 1));
b.set(3, b.size() - 1, p);
b.set(0, b.size() - 1, null);
}
} }
} }