Smallwood studio notes

Browser work and card-game programs

Vol. 1 · 2026
Public lab notebook

NB-11 · 4 Nov 2026 · Card game

Lab note

Building a Durak AI: legal moves first

This entry records the first week of work on a Durak-playing program. The goal for the week was not a strong player. It was a representation that can list every legal attack and every legal defence from a given position, so later search code has a trustworthy move generator.

Durak is an attacking card game. A standard table often uses a 36-card deck, ranks six through ace, with a trump suit turned up from the remaining stock. One player attacks, another defends. If the defender cannot (or does not) beat every attacking card, those cards are taken into the defender's hand. The last player left holding cards is the fool. Those basics, including what may be played on what, should be written down as the rule set the program will treat as legal, rather than a remembered house rule.

The state I settled on is a simple structure: each card is a rank and a suit; each hand is an ordered list; the table is a list of attack-defence pairs (the defence may be empty); the trump suit and the stock are stored explicitly; so is whose turn it is and whether the current action is an attack, a throw-in, or a defence. Nothing in that structure is clever. It does make it obvious when a test fixture is wrong, because you can print the whole position on one screen.

Legal-move generation is a set of filters over that structure. An opening attack may play any card from the attacker's hand. A throw-in, once a defence is under way, may add a card only of a rank already on the table, and only up to the number of cards the defender can still face. A defence must beat a given attacking card with a higher card of the same suit, or with a trump. The code returns those options as a list. The first tests were handwritten positions from the rules examples, then a loop that dealt random hands and checked that every generated move still satisfied the same filters when applied in reverse.

I have not added search yet. A later entry will try a shallow look-ahead that prefers discarding low off-suit cards and saving trump. Until the generator is stable, any score the program prints is noise.