Bug fixes and undo bulk-count modifications
This commit is contained in:
parent
c989b297cb
commit
6f024ec38d
|
@ -154,6 +154,7 @@ proc getPinnedDirections(self: ChessBoard, loc: Location): seq[Location]
|
||||||
proc getAttacks*(self: ChessBoard, loc: Location): Attacked
|
proc getAttacks*(self: ChessBoard, loc: Location): Attacked
|
||||||
proc getSlidingAttacks(self: ChessBoard, loc: Location): tuple[attacks: Attacked, pins: Attacked]
|
proc getSlidingAttacks(self: ChessBoard, loc: Location): tuple[attacks: Attacked, pins: Attacked]
|
||||||
func invalidateCache(self: ChessBoard) {.inline.}
|
func invalidateCache(self: ChessBoard) {.inline.}
|
||||||
|
proc inCheck*(self: ChessBoard, color: PieceColor = None): bool
|
||||||
|
|
||||||
|
|
||||||
proc extend[T](self: var seq[T], other: openarray[T]) {.inline.} =
|
proc extend[T](self: var seq[T], other: openarray[T]) {.inline.} =
|
||||||
|
@ -458,7 +459,9 @@ proc newChessboardFromFEN*(state: string): ChessBoard =
|
||||||
raise newException(ValueError, "too many fields in FEN string")
|
raise newException(ValueError, "too many fields in FEN string")
|
||||||
inc(index)
|
inc(index)
|
||||||
result.updateAttackedSquares()
|
result.updateAttackedSquares()
|
||||||
|
if result.inCheck(result.getActiveColor().opposite):
|
||||||
|
# Opponent king cannot be captured!
|
||||||
|
raise newException(ValueError, "invalid position: opponent king can be captured")
|
||||||
|
|
||||||
|
|
||||||
proc newDefaultChessboard*: ChessBoard {.inline.} =
|
proc newDefaultChessboard*: ChessBoard {.inline.} =
|
||||||
|
@ -1187,7 +1190,8 @@ proc getSlidingAttacks(self: ChessBoard, loc: Location): tuple[attacks: Attacked
|
||||||
# Empty square, keep going
|
# Empty square, keep going
|
||||||
if otherPiece.color == None:
|
if otherPiece.color == None:
|
||||||
continue
|
continue
|
||||||
if otherPiece.color == piece.color.opposite and otherPiece.kind != King:
|
if otherPiece.color == piece.color.opposite():
|
||||||
|
if otherPiece.kind != King:
|
||||||
# We found an enemy piece that is not
|
# We found an enemy piece that is not
|
||||||
# the enemy king. We don't break out
|
# the enemy king. We don't break out
|
||||||
# immediately because we first want
|
# immediately because we first want
|
||||||
|
@ -1209,6 +1213,13 @@ proc getSlidingAttacks(self: ChessBoard, loc: Location): tuple[attacks: Attacked
|
||||||
result.pins.add((loc, square, -direction))
|
result.pins.add((loc, square, -direction))
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
# Enemy king is here: ensure it cannot move backwards by
|
||||||
|
# attacking the square behind it (if one exists and is
|
||||||
|
# valid)
|
||||||
|
let target = square + direction
|
||||||
|
if target.isValid():
|
||||||
|
result.attacks.add((square, target, direction))
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -102,10 +102,7 @@ def main(args: Namespace) -> int:
|
||||||
r"(?:\s\s-\sPromotions:\s(?P<promotions>[0-9]+))",
|
r"(?:\s\s-\sPromotions:\s(?P<promotions>[0-9]+))",
|
||||||
re.MULTILINE)
|
re.MULTILINE)
|
||||||
extra: re.Match | None = None
|
extra: re.Match | None = None
|
||||||
if args.bulk:
|
if not args.bulk:
|
||||||
print("Note: Nimfish was run in bulk-counting mode, so a detailed breakdown of each move type is not available. "
|
|
||||||
"To fix this, re-run the program without the --bulk option")
|
|
||||||
else:
|
|
||||||
extra = pattern.search(nimfish_output)
|
extra = pattern.search(nimfish_output)
|
||||||
if missing["stockfish"] or missing["nimfish"] or mistakes:
|
if missing["stockfish"] or missing["nimfish"] or mistakes:
|
||||||
print(f"Found {len(missing['stockfish']) + len(missing['nimfish'])} missed moves and {len(mistakes)} counting mistakes, more info below: ")
|
print(f"Found {len(missing['stockfish']) + len(missing['nimfish'])} missed moves and {len(mistakes)} counting mistakes, more info below: ")
|
||||||
|
|
Loading…
Reference in New Issue