Big Fool
An online multiplayer card game for 3–8 players, with AI opponents and an authoritative real-time server. Dump your cards, keep your score low, and dodge the hat.
- TypeScript
- React
- Vite
- Node.js
- WebSockets
- Vitest
Big Fool is an online card game for 3–8 players. Get rid of your cards, keep your score low, and don't be the Big Fool.
How to play
- Suits are built outward from the 7♥. If you hold a playable 7, you must play it.
- When someone goes out, everyone else scores the sum of the ranks left in their hand (A = 1 … K = 13).
- Games are 3, 5 or 7 round tournaments. The lowest total wins, and the highest total is the Big Fool, who wears the hat until next time.
- Play against bots, invite friends with a room code, or quick-match with strangers online.
How it's built
A TypeScript monorepo with a clean split between rules, AI, networking and UI:
- Game engine: pure rules, scoring and tournament logic. It knows nothing about humans, bots or networking, which makes it easy to test.
- AI opponents: 4 difficulty levels × 5 personalities (balanced, conservative, aggressive, blocker, opportunist). Bots only ever see a hidden-information-safe view of the game, so they can't cheat by peeking at hands.
- Authoritative server (Node.js + WebSockets): clients only send intents like "play this card". The server validates every move and never sends a player anyone else's hand. It handles rooms, room codes, quick match, reconnects, and bots taking over for players who drop.
- React client: built with Vite, playable on desktop and phone.
Production hardening
Strict CSP and security headers, WebSocket origin checks, per-IP connection caps, per-player rate limits, heartbeats to clear dead connections, and graceful shutdown. CI type-checks, builds, runs the engine, AI and server test suites, and boots the production bundle on every push.
What I learned
Bots that play well without cheating. The hardest part was a strong bot that never sees other players' hands. Each bot keeps a probability model built only from public information: every pass, and every 7 a player could have played but didn't, proves which cards that player can't be holding. The Expert bot runs a Monte Carlo search on top of that. For each legal move it samples many possible deals that fit what it knows, plays them out, and picks the move most likely to win the whole tournament, not just the current round.
Treating disconnects as normal, not as errors. Phones drop connections all the time. When a player disconnects, their seat gets a 30-second grace period, then a bot takes over so the round keeps moving for everyone else. When the player reconnects, they get their seat and their hand back.
Security is about the details. A bare /% URL was enough to crash the whole server, until I hardened the static file handler. I rate-limited room-code guessing so that only failed lookups count, which throttles anyone brute-forcing codes without slowing down normal joins. The limiter is keyed by IP, so reconnecting doesn't reset it.
Rules are product decisions. Some deals made a round pointless, like one player holding all four kings or all four aces. So I added a redeal rule to the engine. Keeping the rules in a pure, well-tested engine made changes like that a small, safe edit.
Ship fast, then harden. I went from the first working build to a deployed, hardened game with CI in three days, adding features like a shareable results image (with a fallback for browsers missing newer canvas APIs) along the way.