Modern Apps git

← Modern-Apps.git

chess: add pseudo-legal move API to board model

Commit
dfbae0d8a582c44535375d887baaa32e0f8aec96
Author
Vayun Mathur <[email protected]>
When
2026-07-08 19:30 UTC (5 months ago)
Parents
03fcb3a

Diff

games/chess/src/main/java/com/vayunmathur/games/chess/data/ChessModel.kt
diff --git a/games/chess/src/main/java/com/vayunmathur/games/chess/data/ChessModel.kt b/games/chess/src/main/java/com/vayunmathur/games/chess/data/ChessModel.ktindex 55ebdc2f66..342f829eaf 100644--- a/games/chess/src/main/java/com/vayunmathur/games/chess/data/ChessModel.kt+++ b/games/chess/src/main/java/com/vayunmathur/games/chess/data/ChessModel.kt@@ -185,6 +185,17 @@ data class Board(         return !movePieceInternal(start, end).isKingInCheck(piece.color)     } +    /**+     * Legality of a move ignoring whether it leaves the mover's own king in check+     * (i.e. pseudo-legal). Used by the Learn feature to model Lichess's antichess-style+     * kingless lesson boards and its "offer illegal move" levels.+     */+    fun isPseudoLegalMove(start: Position, end: Position): Boolean =+        isValidMoveIgnoringCheck(start, end)++    /** Total number of kings on the board (both colors). */+    fun kingCount(): Int = pieces.sumOf { row -> row.count { it?.type == PieceType.KING } }+     private fun isValidMoveIgnoringCheck(start: Position, end: Position): Boolean {         val piece = pieces[start.row][start.col] ?: return false         val targetPiece = pieces[end.row][end.col]