Memory Game
Build a memory game: 16 cards (8 pairs) face down in a 4 by 4 grid. The starter shuffles a deck of { id, face } cards.
Requirements
- Clicking a face-down card turns it up. With two cards up, a matching pair stays up (and its cards are disabled); a mismatch turns both back after about 800 ms.
- While two cards are up, further clicks are ignored.
- Count moves (one move per pair turned) and announce the win with the move count.
- New game reshuffles and resets everything.
- Cards are buttons with labels that say whether they are face up and what they show.
Hints
Hint 1
Store the face-up cards as an array of ids (at most two) and matched pairs as a set of faces; a card is shown face up if either holds it.
Hint 2
Resolve a pair in an effect that runs when the face-up array reaches two: match → move to the set, mismatch → a timeout clears the array, with cleanup.
Hint 3
Fisher–Yates shuffles in place; wrap the deck creation in a function so New game can call it again.