mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Reject out-of-range endgame FENs at entry (#25)
Add FEN.piece_count/1 and reject positions with more than 7 pieces in the Endgame changeset, so an 8+ piece FEN fails at entry instead of saving and then blocking at play. Accumulate all FEN issues rather than letting a later check overwrite an earlier one, and guard the seed FENs with a test (dropping the out-of-range seed that bypassed the changeset).
This commit is contained in:
@@ -66,27 +66,35 @@ defmodule Chesstrainer.Endgames.Endgame do
|
||||
defp fen_issues(fen) do
|
||||
case String.split(fen, " ") do
|
||||
[board, active, _castling, _en_passant, halfmove, fullmove] ->
|
||||
board_valid? = valid_board?(board)
|
||||
pieces = Chesstrainer.FEN.piece_count(fen)
|
||||
|
||||
issues = []
|
||||
|
||||
issues =
|
||||
if valid_board?(board),
|
||||
if board_valid?,
|
||||
do: issues,
|
||||
else: ["board must be 8 ranks of 8 squares each"]
|
||||
else: issues ++ ["board must be 8 ranks of 8 squares each"]
|
||||
|
||||
issues =
|
||||
if active in ["w", "b"],
|
||||
do: issues,
|
||||
else: ["active color must be 'w' or 'b'"]
|
||||
else: issues ++ ["active color must be 'w' or 'b'"]
|
||||
|
||||
issues =
|
||||
if non_negative_integer?(halfmove),
|
||||
do: issues,
|
||||
else: ["halfmove clock must be a non-negative integer"]
|
||||
else: issues ++ ["halfmove clock must be a non-negative integer"]
|
||||
|
||||
issues =
|
||||
if positive_integer?(fullmove),
|
||||
do: issues,
|
||||
else: ["fullmove number must be a positive integer"]
|
||||
else: issues ++ ["fullmove number must be a positive integer"]
|
||||
|
||||
issues =
|
||||
if board_valid? and is_integer(pieces) and pieces > 7,
|
||||
do: issues ++ ["positions with more than 7 pieces are not covered by tablebases"],
|
||||
else: issues
|
||||
|
||||
issues
|
||||
|
||||
|
||||
Reference in New Issue
Block a user