Skip to content

Auto draw king-pawn fortresses#733

Open
johndoknjas wants to merge 24 commits intolichess-org:masterfrom
johndoknjas:king-pawn-fortresses
Open

Auto draw king-pawn fortresses#733
johndoknjas wants to merge 24 commits intolichess-org:masterfrom
johndoknjas:king-pawn-fortresses

Conversation

@johndoknjas
Copy link
Copy Markdown
Contributor

Auto draw under these conditions:

  • Variant is Standard, From Position, or Chess960.
  • Only kings and pawns left.
  • All the pawns are blocked by pawns.
  • Both kings have no possible way to capture an enemy pawn, regardless of what the opponent does.

This kind of fortress isn't super common, but it does come up from time to time. E.g., I got it in two games from this month (rare):

@johndoknjas johndoknjas marked this pull request as draft August 15, 2025 08:04
@lenguyenthanh
Copy link
Copy Markdown
Member

lenguyenthanh commented Aug 15, 2025

hey, csv related notes:

if destinations.intersects(forbidden) || destinations.contains(startSquare) then
throw IllegalArgumentException(
"`destinations` contains either the start square or some forbidden square"
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't throw exceptions in scala. If the function cannot compute its response type for every combination of its arguments, then it returns a Try[], an Either[] or an Option[].

frontier = frontier.fold(Bitboard.empty) { (newFrontier, sq) =>
newFrontier | (sq.kingAttacks & ~skip)
}
end while
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We almost never do procedural programming in scala. We almost never use var, while or return.
The only rare exception is for extreme performance optimization, after production profiling and benchmark testing.

@johndoknjas
Copy link
Copy Markdown
Contributor Author

@lenguyenthanh Thanks for the feedback. I've addressed your first point, but for the second I've been having some trouble implementing it. If you'd be able to help here that would be appreciated.

@lenguyenthanh
Copy link
Copy Markdown
Member

@lenguyenthanh Thanks for the feedback. I've addressed your first point, but for the second I've been having some trouble implementing it. If you'd be able to help here that would be appreciated.

I'll take a look 👍

@johndoknjas johndoknjas marked this pull request as ready for review October 20, 2025 02:35
@johndoknjas
Copy link
Copy Markdown
Contributor Author

Hey @lenguyenthanh, just following up on this.

@lenguyenthanh
Copy link
Copy Markdown
Member

Hey @lenguyenthanh, just following up on this.

I'm vacationing atm, will look in early February

@SergioGlorias
Copy link
Copy Markdown
Member

I'm vacationing atm, will look in early February

@lenguyenthanh i think you forgot

@lenguyenthanh
Copy link
Copy Markdown
Member

I'm vacationing atm, will look in early February

@lenguyenthanh i think you forgot

No, but I'm procastinating 🙏

@SergioGlorias
Copy link
Copy Markdown
Member

SergioGlorias commented Mar 16, 2026

  • Only kings and pawns left.

maybe need include this
imagem
-- form https://lichess.org/forum/lichess-feedback/no-draw-3#2

@johndoknjas
Copy link
Copy Markdown
Contributor Author

@SergioGlorias Should be pretty straightforward to handle other pieces. The bfs algorithm in core/src/main/scala/InsufficientMatingMaterial.scala can be applied to other pieces, just with the set of 'forbidden' squares being only the squares that friendly pawns are on (unless I'm missing some edge case). But to keep things simple maybe that should be tackled after/if this PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants