Inspiration
When tasked with creating a "simple poker video game" using the Devvit Phaser template, I was immediately drawn to the challenge. Poker isn't just a card game—it's a complex system of probability, psychology, and strategy. The idea of building an AI opponent that could make intelligent decisions based on hand strength and pot odds fascinated me.
The Reddit platform constraint made it even more interesting. How do you create an engaging, responsive game that works seamlessly within Reddit's ecosystem? This became my north star.
What it does
How we built it
Architecture Design // Shared type system for consistency interface GameState { phase: GamePhase; players: Player[]; communityCards: Card[]; pot: number; } I structured the project with three main layers:
Shared Logic (/src/shared): Poker rules, AI logic, type definitions Server (/src/server): Express API endpoints with Redis persistence Client (/src/client): Phaser game with responsive UI Poker Engine Implementation The core challenge was implementing proper Texas Hold'em rules. I built:
Card Evaluation System: A scoring algorithm that ranks poker hands from high card (score < 1M) to royal flush (score > 9M).
AI Decision Making: The AI evaluates hand strength and makes strategic decisions:
const handStrength = evaluateHandStrength(playerHand, communityCards); const potOdds = callAmount / (pot + callAmount); const decision = getBasicStrategy(handStrength, potOdds, gamePhase); Responsive UI: Built with Phaser's resize system to work on mobile and desktop:
const isMobile = width < 768; const cardWidth = isMobile ? 50 : 60; const buttonWidth = isMobile ? 80 : 120;
Challenges we ran into
Initially, the game looked terrible on mobile—buttons were cut off, the interface was stuck in a corner, and there was an ugly blue background. I had to completely rewrite the UI system to:
Use viewport-relative positioning instead of fixed coordinates Implement dynamic font and element sizing Create a proper full-screen poker table background
- Poker Logic Complexity Texas Hold'em has subtle rules that are easy to get wrong:
Proper betting round management (when can players check vs. call?) Side pot calculations for all-in scenarios Accurate hand evaluation with shared community cards The hand evaluation algorithm alone required careful consideration of edge cases like wheel straights (A-2-3-4-5).
- TypeScript Strict Mode Working with exactOptionalPropertyTypes: true taught me the importance of precise type definitions. Every optional property needed explicit | undefined handling:
interface GameAction { type: PlayerAction; amount?: number | undefined; // Required for strict mode }
- AI Strategy Balance Creating an AI that's challenging but not frustrating required multiple iterations. Too aggressive, and players would fold constantly. Too passive, and the game became boring. I settled on a hand-strength-based approach with pot odds consideration. ## Accomplishments that we're proud of
What we learned
Poker Mathematics Building the hand evaluation system taught me the mathematical beauty of poker. The probability calculations for different hands follow elegant patterns:
$$P(\text{Royal Flush}) = \frac{4}{\binom{52}{5}} = \frac{4}{2,598,960} \approx 0.000154%$$
But more importantly, I learned that poker AI isn't just about calculating hand strength—it's about modeling expected value:
$$EV = P(\text{win}) \times \text{pot size} - P(\text{lose}) \times \text{call amount}$$
Modern Web Architecture The Devvit framework introduced me to serverless Reddit app development. I discovered how to:
Structure shared TypeScript types across client/server boundaries Implement real-time game state management with Redis Build responsive Phaser games that scale across devices Game Development Patterns Creating the poker logic taught me about state machines and game flow management. Each phase (preflop, flop, turn, river) required careful state transitions and validation.
Log in or sign up for Devpost to join the conversation.