we need to make this

Started fromโ€œwe need to make this. make it better and good. ๐Ÿ•ต๏ธ AI Impostor: 30-Minute Build Guide An interactive, multiplayer social deduction game where players try to identify the AI secretly disguised as a human. --- ๐Ÿ› ๏ธ Tech Stack & Setup Frontend: Next.js (App Router), React, Tailwind CSS Backend / API: Next.js Route Handlers AI Provider: OpenRouter API (Access models like `meta-llama/llama-3.3-70b-instruct` or `openai/gpt-4o-mini`) Realtime State / Sync: Firebase Realtime Database (or Supabase Realtime) --- ๐Ÿ—๏ธ Architecture & Game Flow ``` [ Player 1 (Human) ] ---> Writes response --->\ [ Player 2 (Human) ] ---> Writes response ----> [ Firebase Realtime DB ] [ AI Bot (OpenRouter)]---> Generates response ->/ โ”‚ โ–ผ [ Combined Shuffled Deck ] โ”‚ โ–ผ [ All Players Vote ] ``` Game Loop: Host Starts Game: A room is created with a prompt (e.g., "What's your worst excuse for being late to work?"). Human Responses: Real players submit their short answers. AI Response: A server endpoint calls OpenRouter to generate a response disguised as a human with subtle typos and informal tone. Voting Phase: Responses are shuffled. Everyone votes on which submission belongs to the AI. Reveal Phase: Scores are updated based on whether the AI successfully fooled the players or got caught. --- ๐Ÿ”‘ 1. OpenRouter Integration (`app/api/generate-ai/route.ts`) Create a Next.js API route that fetches the AI's response via OpenRouter. ```typescript import { NextResponse } from 'next/server'; export async function POST(req: Request) { try { const { prompt } = await req.json(); const response = await fetch("https://openrouter.ai/api/v1/chat/completions", { method: "POST", headers: { "Authorization": `Bearer ${process.env.OPENROUTER_API_KEY}`, "Content-Type": "application/json", "HTTP-Referer": "http://localhost:3000", // Required by OpenRouter "X-Title": "AI Impostor Game" }, body: JSON.stringify({ model: "meta-llama/llama-3.3-70b-instruct", // or "openai/gpt-4o-mini" messages: [ { role: "system", content: `You are playing a game called 'AI Impostor'. Your goal is to pass as a real human responding casually to a prompt. Rules: - Keep it short (1-2 sentences max). - Sound like a regular person typing on a phone or chat. - Include subtle human flaws (e.g., lowercase letters, minor slang, or slight typos). - DO NOT sound like an AI assistant. - NEVER mention that you are an AI or language model.` }, { role: "user", content: `Topic/Prompt: "${prompt}"\nGive your short casual human answer:` } ], temperature: 0.9, max_tokens: 100 }) }); const data = await response.json(); const aiText = data.choices[0]?.message?.content?.trim() || "my alarm just didnt go off lol"; return NextResponse.json({ text: aiText }); } catch (error) { console.error("OpenRouter API Error:", error); return NextResponse.json({ error: "Failed to generate AI response" }, { status: 500 }); } } ``` --- ๐ŸŽฎ 2. Shared Game Data Schema (Firebase/Supabase) Store room state in a single document/path: ```json { "room_code": "GAME123", "status": "VOTING", // "WAITING" | "SUBMITTING" | "VOTING" | "REVEAL" "prompt": "What's the weirdest thing you've ever eaten?", "submissions": [ { "id": "sub_1", "playerId": "user_a", "text": "expired yogurt from 2021", "isAI": false }, { "id": "sub_2", "playerId": "user_b", "text": "a deep fried bug in thailand", "isAI": false }, { "id": "sub_3", "playerId": "ai_bot", "text": "probably raw pineapple on a taco bad mistake", "isAI": true } ], "votes": { "user_a": "sub_3", "user_b": "sub_1" } } ``` --- ๐Ÿ’ป 3. Client UI Component Example (`app/page.tsx`) A single-page layout handling submission and voting UI: ```tsx 'use client'; import { useState } from 'react'; export default function ImpostorGame() { const [prompt] = useState("What's your worst excuse for being late?"); const [userSubmission, setUserSubmission] = useState(""); const [submissions, setSubmissions] = useState<any[]>([]); const [gameState, setGameState] = useState<'SUBMIT' | 'VOTE' | 'RESULTS'>('SUBMIT'); const [selectedVote, setSelectedVote] = useState<string | null>(null); // Trigger submission phase including AI generation const handleSubmit = async () => { if (!userSubmission.trim()) return; // 1. Fetch AI response from backend (OpenRouter) const res = await fetch('/api/generate-ai', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt }) }); const data = await res.json(); // 2. Combine inputs (In full production, sync this via Firebase) const pool = [ { id: '1', text: userSubmission, isAI: false }, { id: '2', text: data.text, isAI: true }, { id: '3', text: "my dog literally ate my car keys no joke", isAI: false } ].sort(() => Math.random() - 0.5); // Shuffle array setSubmissions(pool); setGameState('VOTE'); }; return ( <main className="min-h-screen bg-slate-950 text-white p-8 flex flex-col items-center justify-center font-sans"> <div className="max-w-xl w-full bg-slate-900 border border-slate-800 rounded-xl p-6 shadow-2xl"> <h1 className="text-3xl font-extrabold text-indigo-400 mb-2">๐Ÿ•ต๏ธ AI Impostor</h1> <p className="text-slate-400 mb-6">Find the AI hidden among the human responses!</p> {/* PROMPT BANNER */} <div className="bg-slate-800 p-4 rounded-lg border border-slate-700 mb-6"> <span className="text-xs font-semibold text-indigo-400 uppercase tracking-wider">Current Prompt</span> <p className="text-lg font-medium text-slate-100 mt-1">"{prompt}"</p> </div> {/* PHASE 1: SUBMISSION */} {gameState === 'SUBMIT' && ( <div className="space-y-4"> <textarea value={userSubmission} onChange={(e) => setUserSubmission(e.target.value)} placeholder="Type your answer naturally..." className="w-full bg-slate-950 border border-slate-800 rounded-lg p-3 text-white focus:outline-none focus:border-indigo-500" rows={3} /> <button onClick={handleSubmit} className="w-full py-3 bg-indigo-600 hover:bg-indigo-500 font-semibold rounded-lg transition" > Submit Answer </button> </div> )} {/* PHASE 2: VOTING */} {gameState === 'VOTE' && ( <div className="space-y-4"> <h2 className="text-sm font-semibold text-slate-300">Who is the AI? Vote below:</h2> <div className="space-y-2"> {submissions.map((sub) => ( <button key={sub.id} onClick={() => setSelectedVote(sub.id)} className={`w-full p-4 text-left rounded-lg border transition ${ selectedVote === sub.id ? 'bg-indigo-950 border-indigo-500 text-white' : 'bg-slate-950 border-slate-800 text-slate-300 hover:border-slate-700' }`} > "{sub.text}" </button> ))} </div> <button disabled={!selectedVote} onClick={() => setGameState('RESULTS')} className="w-full py-3 bg-emerald-600 hover:bg-emerald-500 disabled:opacity-50 font-semibold rounded-lg transition mt-4" > Confirm Vote </button> </div> )} {/* PHASE 3: RESULTS */} {gameState === 'RESULTS' && ( <div className="space-y-4 text-center"> <h2 className="text-2xl font-bold mb-4">Results Unveiled!</h2> <div className="space-y-3"> {submissions.map((sub) => ( <div key={sub.id} className={`p-4 rounded-lg border text-left ${ sub.isAI ? 'bg-red-950/40 border-red-500' : 'bg-slate-950 border-slate-800' }`} > <p className="text-slate-200">"{sub.text}"</p> <span className={`text-xs font-bold mt-2 inline-block ${sub.isAI ? 'text-red-400' : 'text-emerald-400'}`}> {sub.isAI ? '๐Ÿค– AI Impostor' : '๐Ÿ‘ค Real Human'} </span> </div> ))} </div> <button onClick={() => { setGameState('SUBMIT'); setUserSubmission(''); setSelectedVote(null); }} className="w-full py-3 bg-indigo-600 hover:bg-indigo-500 font-semibold rounded-lg transition mt-4" > Play Again </button> </div> )} </div> </main> ); } ``` --- ๐Ÿš€ Rapid 30-Minute Step-by-Step Checklist Environment Setup (5 mins): Run `npx create-next-app@latest ai-impostor` Get an API Key from OpenRouter and add it to `.env.local`: ```env OPENROUTER_API_KEY=your_key_here ``` API Route (10 mins): Paste the OpenRouter endpoint code into `app/api/generate-ai/route.ts`. UI & State Logic (10 mins): Paste the client React component code into `app/page.tsx`. Testing (5 mins): Run `npm run dev` and test submitting responses to see if the AI successfully mimics human typing behavior.โ€