cg-core: make cg-shuffle optionally seeded and reproducible

cg-shuffle gains an optional SEED and a `cg-shuffle-seed' dynamic var.
With a seed the order is deterministic and identical on every platform,
so a deal can be replayed, shared between players, or pinned in a test;
the index comes from secure-hash (spec-defined output everywhere, 7 hex
digits stay a fixnum even on 32-bit Emacs), so no bignum/overflow
behaviour can vary it.  With no seed the shuffle is the byte-for-byte
old system-random path -- normal play is unchanged.

Test cgt-shuffle-seeded pins determinism, permutation, override and a
cross-platform golden prefix; fails on the prior one-arg cg-shuffle.
Suite 159/159.
This commit is contained in:
Corwin Brust 2026-08-03 22:18:02 -05:00
parent 1a59003b13
commit 6379127e17
8 changed files with 180 additions and 15 deletions

View file

@ -20,7 +20,7 @@ TEXI2PDF ?= texi2pdf
README = README.md
EXTRA = README.org $(README) $(PKGDESC) $(MANUAL) $(VERTEXI) $(IMAGES)
.PHONY: all compile test clean distclean checkdoc lint package tarball elpa release help \
.PHONY: all compile test clean distclean checkdoc lint check package tarball elpa release help \
info info-emacs html pdf docclean version readme hooks
help:
@ -29,6 +29,7 @@ help:
@echo " test run the ERT test suite"
@echo " checkdoc run checkdoc on all sources"
@echo " lint run package-lint (if installed)"
@echo " check compile + checkdoc + lint + test (the full gate)"
@echo " version regenerate $(VERTEXI) from VERSION"
@echo " readme export README.org -> README.md (Emacs batch)"
@echo " hooks install the git pre-commit hook"
@ -50,8 +51,13 @@ compile:
test:
$(BATCH) -L test -l test/$(PKG)-tests.el -f ert-run-tests-batch-and-exit
# One gate a contributor (or CI) can run: the same quality tools MELPA
# asks for -- byte-compile, checkdoc, package-lint -- plus the ERT suite.
check: compile checkdoc lint test
@echo "card-games $(VERSION): compile + checkdoc + lint + tests all green"
checkdoc:
$(BATCH) --eval "(progn (dolist (f '($(EL))) (checkdoc-file f)))"
$(BATCH) --eval "(progn (dolist (f '($(EL))) (checkdoc-file (symbol-name f))))"
lint:
-$(BATCH) --eval "(progn (require 'package) (package-initialize) \
@ -82,7 +88,7 @@ elpa: tarball
# (not ".") so the growing output tarball and editor lock files are never
# read mid-write -- which is what caused "tar: .: file changed as we read it".
SRCFILES = $(EL) $(EXTRA) build.el hooks Makefile .gitignore test
release: distclean version readme test tarball
release: distclean version readme check tarball
rm -f $(SRCTAR)
tar --transform 's,^,$(TARDIR)/,' \
--exclude='*.elc' --exclude='*.tar' --exclude='*.tar.gz' \