-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Currently, the converter to Algebraic and Descriptive notation never render dblch or dis.ch in case of discovered or double checks.
Both support understanding input games that contain those modifiers, but don't output them back.
The underlying issue is that the mechanism for handling checks is boolean (e.g. isKingThreatened) rather than a count of checks.
The fix is relatively trivial if one knows where to change things:
ChessPiece calculates isThreatened using nonEmpty. There should be an extra method to count threatens. isThreatened is the biggest bottleneck in the library, so it shouldn't be made slower.
def isThreatened(board: ChessBoard)(implicit opts: ChessOptimisations =
ChessOptimisations.default): Boolean =
threatenedBy(board).nonEmpty
ChessBoard calculates if a ChessAction is a check or not:
val check = opts.checkForThreatens && m.fromPiece.enemy
.kingPiece(newBoard)
.exists(_.isThreatened(newBoard))
It should also calculate if it is a dblch or a dis.ch. In order to calculate dblch, it's enough to check if the "count of threatens" is >1. In order to calculate dis.ch, we need to know which piece is causing the threat to the King, and it will be true if the piece is not the fromPiece from the current ChessAction.