A Japanese Mahjong game where you play against 3 AI players powered by InsForge AI models. Features a beautiful Japanese manga-style UI and full game history tracking.
- 🎮 Full Japanese Mahjong Gameplay: Complete implementation of Japanese Mahjong rules
- 🤖 AI Opponents: Play against 3 AI players using different AI models (GPT-4o, Claude Sonnet 4.5, Gemini 3 Flash)
- 🎨 Japanese Manga-Style UI: Beautiful, clean interface with manga-inspired design
- 📊 Game History: Track all your games, scores, and statistics
- 🔐 Authentication: Secure login with email/password or OAuth (Google, GitHub)
- 💾 Persistent Storage: All game data saved to InsForge backend
- Frontend: React + TypeScript + Vite
- Backend: InsForge (BaaS platform)
- Database: PostgreSQL (via InsForge)
- AI: InsForge AI Integration (OpenAI, Anthropic, Google models)
- Styling: Tailwind CSS 3.4
- Authentication: InsForge Auth
- Node.js 18+
- npm or yarn
- InsForge account and backend
-
Clone the repository
git clone <repository-url> cd mahjong-hero
-
Install dependencies
npm install
-
Set up environment variables
Create a
.envfile in the root directory:VITE_INSFORGE_BASE_URL=https://your-backend.region.insforge.app VITE_INSFORGE_ANON_KEY=your_anon_key_here
Get these values from your InsForge dashboard.
-
Run the development server
npm run dev
-
Open your browser
Navigate to
http://localhost:5173
The app uses the following tables:
- games: Tracks game sessions
- game_players: Tracks players in each game
- game_turns: Records every action in the game
All tables have Row Level Security (RLS) enabled, so users can only see their own games.
This implementation follows Japanese Mahjong (Riichi Mahjong) rules:
- 4 players (1 human + 3 AI)
- 136 tiles (Man, Pin, Sou, Honors)
- Standard win conditions (4 melds + 1 pair, seven pairs, thirteen orphans)
- Chi, Pon, Kan calls
- Ron and Tsumo wins
- Riichi declaration
- Dora indicators
The game uses three different AI models for variety:
- Player 1: OpenAI GPT-4o
- Player 2: Anthropic Claude Sonnet 4.5
- Player 3: Google Gemini 3 Flash Preview
Each AI player receives the current game state and makes strategic decisions about their next move.
mahjong-hero/
├── src/
│ ├── components/ # React components
│ │ ├── Tile.tsx
│ │ ├── PlayerHand.tsx
│ │ ├── GameBoard.tsx
│ │ └── GameHistory.tsx
│ ├── hooks/ # Custom React hooks
│ │ └── useMahjongGame.ts
│ ├── lib/ # Library setup
│ │ └── insforge.ts
│ ├── types/ # TypeScript types
│ │ └── mahjong.ts
│ ├── utils/ # Utility functions
│ │ ├── mahjongLogic.ts
│ │ └── aiPlayer.ts
│ ├── App.tsx
│ └── main.tsx
├── .env # Environment variables (create this)
└── package.json
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production buildnpm run lint- Run ESLint
MIT
- InsForge for the backend platform
- Japanese Mahjong community for the rules and terminology