feat: working castling
All checks were successful
Linux arm64 / Build (push) Successful in 47s

This commit is contained in:
2025-05-17 18:51:23 +02:00
parent 01f0caf672
commit 646eb6492e
11 changed files with 63 additions and 44 deletions

View File

@@ -44,6 +44,16 @@ public interface CommandSender {
return cmd.getCastlingResult();
}
default boolean canDoCastling() {
CastlingResult castlings = getAllowedCastlings();
return castlings == CastlingResult.Both || castlings == CastlingResult.Small;
}
default boolean canDoBigCastling() {
CastlingResult castlings = getAllowedCastlings();
return castlings == CastlingResult.Both || castlings == CastlingResult.Big;
}
default Piece getPieceAt(int x, int y) {
return getPieceAt(new Coordinate(x, y));
}
@@ -77,7 +87,7 @@ public interface CommandSender {
}
default CommandResult sendBigCastling() {
return sendCommand(new CastlingCommand(false));
return sendCommand(new CastlingCommand(true));
}
default CommandResult sendMove(Move move) {

View File

@@ -51,7 +51,7 @@ public class CastlingCommand extends PlayerCommand {
board.setLastMove(this.kingMove);
outputSystem.onCastling(this.bigCastling);
outputSystem.onCastling(this.bigCastling, kingMove, rookMove);
return CommandResult.Moved;
}

View File

@@ -96,8 +96,8 @@ public class AsyncGameDispatcher extends GameDispatcher {
}
@Override
public void onCastling(boolean bigCastling) {
asyncForEachCall((l) -> l.onCastling(bigCastling));
public void onCastling(boolean bigCastling, Move kingMove, Move rookMove) {
asyncForEachCall((l) -> l.onCastling(bigCastling, kingMove, rookMove));
}
@Override

View File

@@ -60,7 +60,7 @@ public class EmptyGameDispatcher extends GameDispatcher {
}
@Override
public void onCastling(boolean bigCastling) {
public void onCastling(boolean bigCastling, Move kingMove, Move rookMove) {
}
@Override

View File

@@ -47,7 +47,7 @@ public abstract class GameAdapter implements GameListener {
public void onDraw() {}
@Override
public void onCastling(boolean bigCastling) {}
public void onCastling(boolean bigCastling, Move kingMove, Move rookMove) {}
@Override
public void onPawnPromoted(PromoteType promotion) {}

View File

@@ -90,8 +90,10 @@ public interface GameListener {
* Invoked when a castling is done
*
* @param bigCastling if it's queen side castling
* @param kingMove the king's move
* @param rookMove the rook's move
*/
void onCastling(boolean bigCastling);
void onCastling(boolean bigCastling, Move kingMove, Move rookMove);
/**
* Invoked when a pawn is promoted