Skip to content

77 game-dev skills for AI coding agents — Godot, Unity, Unreal, Phaser, PixiJS, three.js, Bevy, pygame, LÖVE, Roblox. Portable SKILL.md Agent Skills (the format Anthropic launched as Claude Skills), with a router that loads the right skill for your engine and task. Runs in Claude Code, Cursor, Kiro, Codex, Copilot, Gemini CLI and more.

fix(card-game): validate targets before paying, correct shuffle bias notes and per-engine RNG ranges

Kiro Crew9bd027b8b369
diff --git a/skills/genres/card-game/SKILL.md b/skills/genres/card-game/SKILL.md
index d029d22..0567666 100644
--- a/skills/genres/card-game/SKILL.md
+++ b/skills/genres/card-game/SKILL.md
@@ -77,12 +77,14 @@ card = {
"id": "fireball", "cost": 3, "type": "spell",
"effects": [ {"op": "damage", "amount": 6, "target": "chosen_enemy"} ],
}
-def play(card, caster):
- if resources[caster] < card.cost: return False # can't afford
- resources[caster] -= card.cost
+def play(card, caster, chosen_targets):
+ # Validate everything first; a failed check must leave zones and resources untouched.
+ if resources[caster] < card.cost: return False # can't afford
+ if not targets_legal(card, chosen_targets): return False
+ resources[caster] -= card.cost # commit: pay, then move, then resolve
move(card, from_zone=hand, to_zone=play_or_discard(card))
for fx in card.effects:
- resolve_effect(fx, caster) # one interpreter handles every card
+ resolve_effect(fx, caster, chosen_targets) # one interpreter handles every card
return True
```
@@ -110,7 +112,12 @@ def take_turn(player):
by a small set of operations (Pattern 2).
- **Ambiguous effect order / simultaneous triggers** → nondeterministic outcomes. Resolve in a
defined order (a queue or stack); document LIFO vs. FIFO (refs).
-- **Unseeded shuffle in a game that needs replays/undo** → can't reproduce. Use a seeded RNG.
+- **Unseeded shuffle in a game that needs replays/undo** → can't reproduce. Use a seeded RNG
+ instance (not the engine's global one) and save its state with the run; see refs §6 for the
+ per-engine calls.
+- **Off-by-one in the shuffle's random index** → some orders never occur (a biased deck). Engine
+ ranges differ: Godot `randi_range(a, b)` and Phaser `RND.between(a, b)` include `b`; Unity
+ `Random.Range(int, int)` excludes it.
- **No hand limit / no answers** → degenerate hoarding or unbeatable threats. Add a hand cap and
ensure removal exists for every threat archetype.
- **Targeting state leaks** → a cancelled play leaves the board mid-targeting. Make play
diff --git a/skills/genres/card-game/references/effect-resolution.md b/skills/genres/card-game/references/effect-resolution.md
index 1dc45ad..5d1a643 100644
--- a/skills/genres/card-game/references/effect-resolution.md
+++ b/skills/genres/card-game/references/effect-resolution.md
@@ -78,8 +78,16 @@ progression. Keep run state separate from any meta-collection (see `save-systems
## 6. Shuffle fairness and consistency
-- Use a correct **Fisher–Yates** shuffle (engine RNG); naive "sort by random" is biased.
-- Seed the RNG if you want reproducible runs, replays, or deterministic undo.
+- Use a correct **Fisher–Yates** shuffle. Two common hand-rolled versions are biased: sorting
+ with a random *comparator* (`sort(cmp=random)`), and swapping each index with any index
+ `0..n-1` instead of `0..i`. Both make some deck orders more likely than others.
+- Watch the range convention of the RNG call you use (table below). Picking `j` from `0..i-1`
+ instead of `0..i` gives Sattolo's algorithm, which never leaves a card in place: also biased.
+- Seed the RNG if you want reproducible runs, replays, or deterministic undo, and save the
+ generator's **state** (not just the seed) with the run so a reload continues the same sequence.
+- A small-state PRNG cannot reach every order of a large deck (52 cards have about 2^226
+ orderings; a 64-bit state reaches at most 2^64). That is fine for games; it only matters if you
+ promise "every shuffle equally likely" for money or tournaments.
- For digital games, players perceive true-random as "streaky". Some games use a *pity* /
smoothing system (e.g. bound how long before a needed resource appears). Decide intentionally;
document it so balance math accounts for it.
@@ -87,10 +95,19 @@ progression. Keep run state separate from any meta-collection (see `save-systems
```python
def shuffle(cards, rng): # Fisher–Yates
for i in range(len(cards) - 1, 0, -1):
- j = rng.range(0, i + 1) # 0..i inclusive
+ j = rng.int_inclusive(0, i) # j in 0..i, both ends included
cards[i], cards[j] = cards[j], cards[i]
```
+| Engine | Seedable generator | Integer in `0..i` inclusive | Built-in shuffle |
+|--------|--------------------|-----------------------------|------------------|
+| Godot 4.7 | `RandomNumberGenerator` (`seed`, `state`) | `rng.randi_range(0, i)` | `Array.shuffle()` uses the **global** seed, not your instance |
+| Unity 6.3 | `System.Random` or `Unity.Mathematics.Random` per run | `rnd.Next(0, i + 1)` / `UnityEngine.Random.Range(0, i + 1)` (max exclusive) | none |
+| Phaser 4 | `new Phaser.Math.RandomDataGenerator([seed])` (`state()`) | `rnd.between(0, i)` | `rnd.shuffle(array)` (uses that generator) |
+
+`UnityEngine.Random` is one global generator; anything else that calls it (particles, AI)
+consumes values and breaks replay. Give the deck its own generator instance.
+
## 7. Mana / resource curves
- The **resource curve** (how much you can spend by turn N) paces power. Cheap cards early,