Inspiration

The idea for Midnight Casino was born from a simple question: Can an AI learn to bluff? Standard poker bots are built on $GTO$ (Game Theory Optimal) strategies—purely mathematical algorithms that play "perfect" poker but lack soul. I wanted to build an opponent that felt alive—one that could read the table, feel the pressure of a big pot, and talk trash when it wins. By merging a traditional game engine with Gemini 3, I shifted the focus from "beating a computer" to "outsmarting a mind."

What it does

It’s a digital casino where the opponent is as unpredictable and conversational as a human sitting across the felt

How we built it

The project is built on a modern React + TypeScript stack, designed to handle the complex state of a multi-round card game.

The Brain: I utilized the Gemini 3 Flash model to act as the "Dealer" and "Opponent." Unlike a static bot, Gemini receives the current game state as a JSON-structured prompt and returns a strategic decision along with a personality-driven commentary.

The Engine: The poker logic (shuffling, dealing, and hand evaluation) was built from scratch. For hand strength, I implemented an algorithm that scores hands based on rank and suit, where the probability $P$ of a specific hand is calculated against the remaining deck.

The Atmosphere: I used Tailwind CSS and Framer Motion to create a "Midnight" aesthetic—neon accents, glowing cards, and smooth transitions that mimic the tactile feel of a high-end casino.

The Logic of the GameAt the core of the project is the hand evaluation. Each hand is assigned a score based on the category (Pair, Flush, etc.) plus the high-card kicker. This can be simplified as:

$$Score = (Category \times 10^6) + (HighCardValue)$$

This ensures that a Three-of-a-Kind ($Category = 4$) always outranks a Pair ($Category = 2$), while still allowing the high card to break ties within the same category

Challenges we ran into

Asynchronous State Sync: One of the toughest hurdles was managing the "Turn-Based" flow in a React environment. Because the AI takes time to "think" (calling an external API), I had to implement a useRef based guard system to prevent the user from making moves while the AI was processing.

LLM Hallucinations: Early versions of the AI would occasionally try to bet chips it didn't have. I solved this by implementing a Validation Layer that sits between Gemini and the Game State, ensuring every AI move is legally possible within poker rules before it is executed.

The "Drama" Factor: Initially, the game felt too fast. I had to intentionally slow down the code—using setTimeout promises—to create the tension of the "Showdown," allowing the player to feel the weight of the moment.

Accomplishments that we're proud of

Seamless AI Integration: We successfully bridged the gap between a deterministic game engine (poker rules) and a probabilistic LLM (Gemini 3). Creating a system where an AI can "understand" its position at a table and respond with human-like strategic nuance—rather than just running a math script—was a major technical milestone.

The "Human" Feel: We are particularly proud of the Personality Engine. By prompt-engineering Gemini to act as a "Midnight Shark," the AI doesn't just play cards; it provides contextual commentary that reacts to the player's aggression. This transforms a solo game into a psychological battle.

Robust Game State Machine: Building a Texas Hold'em engine from scratch in React is no small feat. We successfully managed the complex state transitions between the Pre-flop, Flop, Turn, River, and Showdown, ensuring that pot calculations and side-bet logic remain 100% accurate throughout the session.

Immersive UX/UI: We achieved a "Midnight Casino" aesthetic that goes beyond standard web buttons. Using Framer Motion for card physics and a custom-tuned color palette, we created a high-fidelity interface that maintains 60fps performance while handling real-time API calls in the background.

The "Drama" Implementation: We successfully implemented a "Tension Logic" system. By orchestrating timed delays and state-driven animations, we replicated the "slow-roll" of a real casino, proving that sometimes the best feature in a fast-paced app is a well-placed pause.

What we learned

Building this taught me that the future of gaming isn't just better graphics; it's contextual intelligence. Integrating Gemini 3 taught me how to prompt-engineer for specific "personally" constraints and how to handle real-time API latency in a way that actually enhances the user experience rather than frustrating it.

What's next for The AI Bluff: Playing Poker against Gemini 3

While Midnight Casino is currently a high-stakes heads-up experience, the roadmap for the future involves pushing the boundaries of what Generative AI can do in the gaming space:

Multi-Model Personalities: We plan to introduce a "Table of Personalities." Using different system instructions, players could choose to play against a "Conservative Grandmaster," a "Chaotic Gambler," or a "Math-Heavy Analyst," each powered by a different fine-tuned version of Gemini 3.

Voice Integration: Using Gemini Live mode or Web Speech APIs to allow the AI to "talk" to the player. This would move the commentary from a text box to an immersive audio experience, allowing the AI to use tone and pacing to bluff more effectively.

Vision-Based Play: Implementing a feature where players can use their camera to show their "poker face." Gemini could analyze the player's expression via image frames to decide if they are bluffing—bringing true "physical" tells into a digital game.

Advanced Hand History & Analytics: Building a "Post-Game Analysis" suite where Gemini reviews your session. It would provide a strategic breakdown of your play, pointing out where you were too predictable or where your bluffs were most effective.

Multiplayer "AI-Assisted" Rooms: A 6-player mode where humans play against each other, but Gemini acts as the "Floor Manager," narrating the game, explaining the pot odds in real-time for beginners, and maintaining the "Midnight" atmosphere.

Built With

Share this project:

Updates

Submission history