rbtying / shengji

An online version of shengji (a.k.a. tractor) and zhaopengyou (a.k.a. Finding Friends)
https://robertying.com/shengji/
MIT License
85 stars 44 forks source link

Fix bug where irregular adjacent tuples were not always forced to play #430

Closed rbtying closed 1 year ago

rbtying commented 1 year ago

This fixes a bug that is a rare edge case.

Specifically: if the first player leads a trick-format of a 3x2 tractor, a 2x3 tractor, five-of-a-kind or larger, and a subsequent player does not have the ability to meet that trick format, the play they are forced to make instead is dictated by the decomposition of the trick format. That decomposition would, for example, start a 5-tuple, then go to a 4-tuple and a card, and then an adjacent triple-and-pair, and then a separate triple and pair. However, the play legality logic is actually order-dependent; the play requirement [3, 2] requires a triple followed by a pair, and the play requirement [2, 3] requires a pair followed by a triple. This meant that the decomposition skipped the [2, 3] case (and similar cases in larger numbers of cards), though in practice the non-adjacent requirement immediately afterwards would likely require the same cards to be played.

Resolved by requiring the decomposition to enumerate all unique orderings of adjacent cards, when they exist.

In addition, update dependencies to latest versions and remove vergen, since we're just passing in the version via environment variable now.