Skip to content

Varadha9/Akinator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”ฎ Akinator AI - Character Guessing System

An AI-powered character guessing game that predicts who you're thinking of by asking intelligent yes/no questions using Bayesian probability and Information Gain algorithms.

Node.js React MongoDB License


๐ŸŽฏ What It Does

  • You think of any character (real or fictional)
  • The AI asks smart yes/no questions
  • It updates probabilities after every answer using Bayesian inference
  • It guesses your character with 85โ€“95% accuracy
  • If wrong, it learns from you and improves

๐Ÿ—๏ธ Architecture

React Frontend (port 3000)
        โ†“  HTTP/REST
Express Backend (port 5000)
        โ†“
   AI Engine
   โ”œโ”€โ”€ GameManager       โ†’ Session state
   โ”œโ”€โ”€ QuestionSelector  โ†’ Information Gain algorithm
   โ”œโ”€โ”€ ProbabilityEngine โ†’ Bayesian scoring
   โ””โ”€โ”€ GuessGenerator    โ†’ Prediction logic
        โ†“
MongoDB Database (port 27017)
   โ”œโ”€โ”€ Questions  (55)
   โ”œโ”€โ”€ Characters (100+)
   โ””โ”€โ”€ GameLogs

๐Ÿš€ Quick Start

Prerequisites

1. Clone the Repository

git clone https://github.com/Varadha9/Akinator.git
cd Akinator

2. Install Backend Dependencies

cd backend
npm install

3. Install Frontend Dependencies

cd ../frontend
npm install

4. Seed the Database

cd ../backend
node seed.js

You should see:

โœ… Connected to MongoDB
โœ… Inserted 55 questions
โœ… Inserted 101 characters
๐ŸŽ‰ Database seeding completed!

5. Start Backend

cd backend
node server.js

You should see:

โœ… Connected to MongoDB
๐Ÿš€ Server running on http://localhost:5000

6. Start Frontend

cd frontend
npm start

Browser opens at http://localhost:3000 ๐ŸŽ‰


๐Ÿ“ Project Structure

Akinator/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ ai-engine/
โ”‚   โ”‚   โ”œโ”€โ”€ GameManager.js        # Session management
โ”‚   โ”‚   โ”œโ”€โ”€ QuestionSelector.js   # Information gain algorithm
โ”‚   โ”‚   โ”œโ”€โ”€ ProbabilityEngine.js  # Bayesian probability
โ”‚   โ”‚   โ””โ”€โ”€ GuessGenerator.js     # Character prediction
โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”‚   โ””โ”€โ”€ gameController.js     # API request handlers
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ Character.js          # Character schema
โ”‚   โ”‚   โ”œโ”€โ”€ Question.js           # Question schema
โ”‚   โ”‚   โ””โ”€โ”€ GameLog.js            # Game history schema
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ””โ”€โ”€ gameRoutes.js         # API endpoints
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ””โ”€โ”€ databaseService.js    # DB operations
โ”‚   โ”œโ”€โ”€ seed.js                   # Database seeder
โ”‚   โ””โ”€โ”€ server.js                 # Express server
โ”œโ”€โ”€ frontend/
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ”œโ”€โ”€ components/
โ”‚       โ”‚   โ”œโ”€โ”€ StartScreen.js    # Home screen
โ”‚       โ”‚   โ”œโ”€โ”€ QuestionScreen.js # Question + answers
โ”‚       โ”‚   โ”œโ”€โ”€ GuessScreen.js    # AI guess display
โ”‚       โ”‚   โ””โ”€โ”€ LearningScreen.js # Teach AI new character
โ”‚       โ”œโ”€โ”€ pages/
โ”‚       โ”‚   โ””โ”€โ”€ Game.js           # Main game logic
โ”‚       โ”œโ”€โ”€ services/
โ”‚       โ”‚   โ””โ”€โ”€ api.js            # API client
โ”‚       โ””โ”€โ”€ App.js
โ”œโ”€โ”€ database/
โ”‚   โ””โ”€โ”€ seed-data/
โ”‚       โ”œโ”€โ”€ characters.json       # 101 characters
โ”‚       โ””โ”€โ”€ questions.json        # 55 questions
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ architecture.md
โ”‚   โ””โ”€โ”€ DEPLOYMENT.md
โ”œโ”€โ”€ docker-compose.yml
โ””โ”€โ”€ README.md

๐Ÿ”Œ API Endpoints

Method Endpoint Description
GET /health Server health check
GET /api API info
POST /api/start-game Start new game session
POST /api/answer-question Submit answer, get next question
POST /api/submit-feedback Tell AI if guess was correct
POST /api/submit-new-character Teach AI a new character
GET /api/stats Game statistics

Example: Start Game

POST /api/start-game
Content-Type: application/json

{ "category": "all" }
{
  "success": true,
  "sessionId": "uuid",
  "shouldGuess": false,
  "question": {
    "id": "...",
    "text": "Is your character real?"
  },
  "progress": 0
}

Example: Answer Question

POST /api/answer-question
Content-Type: application/json

{
  "sessionId": "uuid",
  "questionId": "...",
  "answer": "yes"
}
{
  "success": true,
  "shouldGuess": false,
  "question": {
    "id": "...",
    "text": "Is your character from a movie?"
  },
  "progress": 10
}

Valid answers: yes ยท no ยท probably ยท probably_not ยท dont_know


๐Ÿง  AI Algorithms

Information Gain โ€” Question Selection

Picks the question that reduces uncertainty the most:

IG(Q) = H(current) - ฮฃ P(answer) ร— H(answer)

H = entropy = -ฮฃ p(x) ร— logโ‚‚(p(x))
Best question = argmax(IG)

Bayesian Probability โ€” Character Scoring

Updates character probabilities after each answer:

Score(C) = ฮฃ compatibility(userAnswer, charAnswer)
P(C)     = exp(Score(C)) / ฮฃ exp(Score(all))

Answer Weights

Answer Weight
Yes +1.0
Probably +0.5
Don't Know 0.0
Probably Not -0.5
No -1.0

๐ŸŽฎ How to Play

  1. Open http://localhost:3000
  2. Click Start Game (or pick a category)
  3. Think of any character
  4. Answer the questions honestly
  5. The AI will guess your character!
  6. If wrong โ†’ teach it the correct character

๐Ÿ“Š Characters Database

101 characters across 8 categories:

Category Examples
๐ŸŽฌ Movies Iron Man, Batman, Harry Potter, Joker
๐ŸŽŒ Anime Naruto, Goku, Luffy, Light Yagami
โšฝ Sports Ronaldo, Messi, Virat Kohli, MS Dhoni
๐Ÿ’ป Tech Elon Musk, Steve Jobs, Bill Gates
๐Ÿ‡ฎ๐Ÿ‡ณ Indian Shah Rukh Khan, Amitabh Bachchan
๐ŸŽต Music Michael Jackson, Taylor Swift
๐Ÿ“œ Historical Gandhi, Einstein, Lincoln
๐ŸŽฎ Other Mario, Sonic, Kratos, Link

๐Ÿ”ง Environment Variables

Create backend/.env:

PORT=5000
MONGODB_URI=mongodb://localhost:27017/akinator
NODE_ENV=development
MAX_QUESTIONS=20
CONFIDENCE_THRESHOLD=0.8

Create frontend/.env:

REACT_APP_API_URL=http://localhost:5000/api

๐Ÿณ Docker Setup

# Start all services
docker-compose up --build

# Stop
docker-compose down

๐Ÿšข Deployment

Backend โ†’ AWS EC2

git clone https://github.com/Varadha9/Akinator.git
cd Akinator/backend
npm install --production
# Update .env with MongoDB Atlas URI
node server.js

Frontend โ†’ Vercel

cd frontend
# Set REACT_APP_API_URL to your EC2 URL in .env
npx vercel --prod

Database โ†’ MongoDB Atlas

  1. Create free cluster at https://cloud.mongodb.com
  2. Get connection string
  3. Update MONGODB_URI in .env
  4. Run node seed.js

๐Ÿ“ˆ Performance

Metric Value
Accuracy 85โ€“95%
Avg questions to guess 8โ€“12
API response time < 100ms
Characters 101
Questions 55

๐Ÿ”ฎ Future Improvements

  • LLM integration for dynamic questions
  • Voice interaction
  • Image-based character hints
  • Leaderboard system
  • Analytics dashboard
  • Mobile app (React Native)
  • Multi-language support
  • Neural network model

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Commit changes: git commit -m 'Add my feature'
  4. Push: git push origin feature/my-feature
  5. Open a Pull Request

๐Ÿ‘ค Author

Varadha9


๐Ÿ“ License

MIT License โ€” see LICENSE for details.


๐Ÿ™ Acknowledgments

  • Inspired by Akinator.com
  • Bayesian inference algorithms
  • Information theory principles

Made with โค๏ธ by Varadha9

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages