Skip to content

Add sudoku chess variant#827

Open
yusitnikov wants to merge 1 commit intofairy-stockfish:masterfrom
yusitnikov:sudoku-chess
Open

Add sudoku chess variant#827
yusitnikov wants to merge 1 commit intofairy-stockfish:masterfrom
yusitnikov:sudoku-chess

Conversation

@yusitnikov
Copy link
Copy Markdown

The PR introduces a new chess variant - "sudoku chess".
In a few words, it's normal chess, but player is not allowed to capture opponent's pieces while player's pieces break 8x8 sudoku rules (i.e. there are repeating pieces of the same type in a file, rank or 4x2 box). Full rules reference: https://gist.github.com/yusitnikov/e81a5e4df2fce6a854db8a2950fa5cfc

Benchmark results:

  • "Nodes searched" value didn't change comparing to the official version (checked with NNUE enabled and disabled).
  • Total time is around 2-3% slower than the official version, and the reason for it is allocating more memory in the StateInfo struct. I guess that it could be solved by allocating the memory dynamically only when the variant is enabled, but it will add complexity to the codebase. Is it worth optimizations?

Compatibility:
I personally plan using the variant only with classic setup: 8x8 board, standard initial position, normal chess rules + sudoku.
But theoretically, there's nothing in the variant implementation that prevents using it with:

  • LARGEBOARDS compilation option.
  • Boards of different sizes.
  • Mixed with other chess variants.

Issues and potential improvements:

  • Variant doesn't detect stalemates (because of replacing king with commoner).
  • Position evaluation doesn't take variant specifics into account yet.
  • do_move re-calculates the sudoku conflicts map from the scratch. It should be possible to optimize.

Sorry for a large PR! It's the smallest possible chunk of changes that will have a value for the variant support.

@ianfab
Copy link
Copy Markdown
Member

ianfab commented Oct 1, 2024

Thanks for your PR. In view of the many open feature addition PRs and the huge backlog of maintenance tasks (e.g. releases, upstream merges) I unfortunately have to say though that I am currently fairly hesitant to add features that are quite specific to rare/exotic variants, so I will defer the decision on this PR for quite some time until maintainability is improved. I hope you understand.

inline int Position::sudoku_box_of(Square s) const {
assert(var != nullptr);
assert(sudoku_boxes());
return rank_of(s) / var->sudokuBoxHeight * (files() / var->sudokuBoxWidth) + file_of(s) / var->sudokuBoxWidth;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you can use precalculated array instead of this, like sudoku_box_of[to]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Right, but it's not a heavy calculation, and it depends on variant parameters, so I prefer not to over-complicate the code

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.

3 participants