Skip to content

Add support for Op1 tablebase positions#1192

Merged
MarkZH merged 4 commits into
lichess-bot-devs:masterfrom
AttackingOrDefending:op1
Mar 24, 2026
Merged

Add support for Op1 tablebase positions#1192
MarkZH merged 4 commits into
lichess-bot-devs:masterfrom
AttackingOrDefending:op1

Conversation

@AttackingOrDefending

Copy link
Copy Markdown
Member

Type of pull request:

  • Bug fix
  • Feature
  • Other

Description:

Adds support for querying op1 tablebase positions. Details about op1 are here.

Related Issues:

None

Checklist:

  • I have read and followed the contribution guidelines.
  • I have added necessary documentation (if applicable).
  • The changes pass all existing tests.

Screenshots/logs (if applicable):

Comment thread lib/engine_wrapper.py Outdated
Comment on lines +1060 to +1067
for file_idx in range(8):
wp_ranks = [chess.square_rank(sq) for sq in white_pawns if chess.square_file(sq) == file_idx]
bp_ranks = [chess.square_rank(sq) for sq in black_pawns if chess.square_file(sq) == file_idx]

if wp_ranks and bp_ranks and min(wp_ranks) < max(bp_ranks):
return True

return False

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.

Instead of this searching, you can directly query which squares the pawns are on. Something like

if white_pawns.popcount() != 1 or black_pawns.popcount() != 1:
    return False

wp = white_pawns.pop()
bp = black_pawns.pop()

return square_file(wp) == square_file(bp) and square_rank(wp) < square_rank(bp)

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.

There are mistakes in my code. I thought op1 meant exactly one white pawn and one black pawn, not at least one of each. So, I'm probably wrong about searching not being necessary.

Also, white_pawns.popcount() should be len(white_pawns).

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.

This actually works, I'll leave it to you to decide if it's easier to read.

    if not white_pawns or not black_pawns:
        return False

    for wp in white_pawns:
        for bp in black_pawns:
            if chess.square_file(wp) == chess.square_file(bp) and chess.square_rank(wp) < chess.square_rank(bp):
                return True

    return False

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Switched as it seems cleaner.

@MarkZH MarkZH merged commit 3b1c84a into lichess-bot-devs:master Mar 24, 2026
23 checks passed
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.

2 participants