Castling Fix
parent
a06d971fcc
commit
b442d9227d
|
@ -54,11 +54,17 @@ public class King extends ChessPiece {
|
|||
|
||||
private void castleRight(){
|
||||
// casting has to move the rook on the right size of the king from white's perspective
|
||||
if (this.isWhite)
|
||||
b.movePiece(b.size() - 1, 0, b.size() - 3, 0);
|
||||
else
|
||||
b.movePiece(b.size()-1, b.size()-1, b.size()-3, b.size()-1)
|
||||
b.set(b.size()-3, b.size()-1, b.get(b.size()-1, b.size()-1));
|
||||
if (this.isWhite) {
|
||||
var p = b.get(b.size() - 1, 0);
|
||||
p.move(new Move(b.size() - 3, 0));
|
||||
b.set(b.size() - 3, 0, p);
|
||||
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){
|
||||
|
@ -67,9 +73,16 @@ public class King extends ChessPiece {
|
|||
|
||||
private void castleLeft(){
|
||||
// casting has to move the rook on the left size of the king from white's perspective
|
||||
if (this.isWhite)
|
||||
b.set(3, 0, b.get(0, 0));
|
||||
else
|
||||
b.set(3, b.size()-1, b.get(0, b.size()-1));
|
||||
if (this.isWhite) {
|
||||
var p = b.get(0, 0);
|
||||
p.move(new Move(3, 0));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue