A multiplayer social deduction game where humans play against an AI player powered by Google Gemini. Can you identify the Undercover? Can you spot the AI?
Play Link (This link could be broken due to server outage)
UndercoverAI is a modern take on the classic "Undercover" party game, featuring an AI player that tries to blend in with humans.
- 4 Players: 3 human players + 1 AI player (with a random name - you don't know who it is!)
- Secret Words: 3 players are Civilians sharing one word (e.g., "Coffee"), 1 player is the Undercover with a similar word (e.g., "Tea")
- Hidden Roles: You only know your word, not whether you're a Civilian or Undercover!
- Description Phase (in-turn) — Players describe their word one at a time in a fixed order. When it's your turn, describe your word without saying it directly; the AI speaks when it's its turn.
- Discussion Phase — Free chat before voting. Everyone can message freely to share reads, suspicions, and debate who the Undercover might be.
- Voting Phase — Vote for who you think has the different word (the Undercover).
- Results — See who was eliminated and who voted for whom. Then:
- If Undercover is voted out → Civilians win! Game ends.
- If a Civilian is voted out → The game continues with the remaining players. A new round starts (Round 2, 3, …) back at the Description phase.
- If only 1 Civilian remains → Undercover wins! Game ends.
- Guess the AI — All human players (whether they won or lost the round) guess who the AI player was. The AI's identity is revealed only after everyone has submitted their guess. Correct guessers are credited as "AI Spotters."
Eliminated players are muted for the rest of the game and cannot describe, chat, or vote in later rounds.
| Role | Win Condition |
|---|---|
| Civilians | Vote out the Undercover |
| Undercover | Survive until only 1 Civilian remains (or tie) |
Everyone gets to guess who the AI is!
After the round ends (Civilians win or Undercover wins), all human players — not just the losing team — take part in the "Guess the AI" phase. Each player submits who they think the AI player is. The AI's identity is revealed only after everyone has guessed.
- Round outcome: Civilians win (Undercover voted out) or Undercover wins (survived). You see whether you won or lost the Undercover game.
- AI guess: All humans then gsuess who the AI was. Correct guessers are credited as "AI Spotters" regardless of whether they won or lost the round.
This adds an extra layer of strategy — pay attention to how everyone describes, discusses, and votes. The AI tries hard to blend in; can you spot it?
This game have been deployed in a server. Simply open this public URL for playing! Play Link
Node.js(v18 or higher recommended)- A Google Gemini API Key
git clone https://github.com/yangyinuo823/undercoverAI.git
cd undercoverAInpm installcd server
npm install
cd ..Create or edit the .env file in the server folder:
# server/.env
GEMINI_API_KEY=your_gemini_api_key_hereFor local development, you can leave these unset; defaults are used.
- Frontend (root
.envor.env.local):
VITE_SOCKET_URL— Socket.io server URL. Unset =http://localhost:3001. For production, set to your public backend URL (e.g.https://api.yourdomain.com) when building the frontend. - Backend (
server/.env):
CORS_ORIGIN— Allowed frontend origin(s), comma-separated. Unset =http://localhost:3000andhttp://localhost:5173. For production, set to your public app URL (e.g.https://yourdomain.com).
PORT— Server port (default3001).
See root .env.example and server/.env.example for templates.
You need to run both the backend server and the frontend app.
cd server
npm run devYou should see: Server running on port 3001
npm run devThe app will open at http://localhost:3000 (or similar port shown in terminal)
Assume one machine (your server) with a public URL — e.g. https://yourdomain.com or an IP like https://123.45.67.89. If you use a domain, point it to this server.
- Clone the repo and install:
cd server,npm install. - Create
server/.envwith:GEMINI_API_KEY— your Gemini API keyPORT— e.g.3001(or the port your host uses)CORS_ORIGIN— the URL where the frontend will be served (e.g.https://yourdomain.comorhttps://app.yourdomain.com)
- Run with
npm run devornpm start. Optionally use a process manager (e.g. PM2) to keep it running. - Expose the backend: either open port 3001 on the firewall, or put the server behind a reverse proxy (e.g. Nginx) so the backend is reachable at e.g.
https://yourdomain.comorhttps://api.yourdomain.com.
- In the repo root, set
VITE_SOCKET_URLto the public backend URL (same as where the backend is reachable, e.g.https://api.yourdomain.comorhttps://yourdomain.comif the backend is on the same host). - Run
npm run build. - Serve the
dist/folder from the same server (e.g. Nginx serving static files) or from a CDN, so the app is available at e.g.https://yourdomain.comorhttps://app.yourdomain.com.
The URL to share with players is the frontend URL (e.g. https://yourdomain.com or https://app.yourdomain.com). Anyone who opens this URL in their browser can play; the app will connect to the backend using the URL configured at build time (VITE_SOCKET_URL).
Quick share: For the Gemini hackathon, share this link: [your frontend URL]. Anyone with the link can play in their browser.
- Open the app in 3 different browser tabs (or have 3 friends open the URL)
- Enter your name and create a room (first player) or join with the room code (other players)
- Wait for all 3 human players to join (names are hidden in the lobby)
- Click "Start Game" when the room is full
- Description phase (in-turn) — Wait for your turn, then describe your word without saying it directly and press Enter. All 4 players speak in order.
- Discussion phase — Chat freely with others to share suspicions and debate who might be the Undercover.
- Voting phase — Vote for who you think has the different word. Only alive players can vote; vote targets are alive players only.
- See results — Who was eliminated? Who voted for whom? If a Civilian was voted out, a new round begins (Round 2, 3, …) with the remaining players.
- Guess the AI — All human players (winners and losers) guess who the AI was. The AI is revealed only after everyone has guessed. Correct guessers are shown as "AI Spotters."
- Frontend: React, TypeScript, Vite, Tailwind CSS
- Backend: Node.js, Express, Socket.io
- AI: Google Gemini API (gemini-2.0-flash)
undercoverAI/
├── App.tsx # Main React component
├── components/ # UI components
├── contexts/ # Socket.io context for real-time communication
├── server/ # Backend server
│ ├── src/
│ │ ├── index.ts # Express + Socket.io server
│ │ ├── gameManager.ts # Game logic and state
│ │ ├── roomManager.ts # Room/lobby management
│ │ └── geminiService.ts # AI player logic
│ └── .env # API key (not committed)
└── README.md
The AI player uses Google Gemini to:
- Generate human-like descriptions of its word (in turn, based on previous players' descriptions)
- Participate in free discussion (as Civilian: share suspicions; as Undercover: mislead)
- Analyze descriptions and discussion to vote strategically
The AI's name is randomized each game, so you never know who it is until the end!
Have fun playing UndercoverAI! Can you outsmart the AI? 🕵️♂️