Skip to content

Commit f4b68c1

Browse files
committed
feat(chess): Complete chess engine implementation with terminal UI
- Add full chess engine with chess.js foundation - Implement alpha-beta search with modern enhancements (TT, LMR, null move, PVS) - Add comprehensive position evaluation (material, PST, pawn structure, mobility, king safety) - Include opening book with 20+ named openings - Add Gemini AI integration for move explanation - Create Chess.tsx terminal UI with chalk-based rendering - Add cursor-based and SAN notation input modes - Integrate chess into main game menu - Add WebSocket support for chess actions - Include AI battle script for AI-vs-AI matches - Update README.md with comprehensive documentation - Update TODO.md and todo-chess.md with completion status
1 parent 5b263b9 commit f4b68c1

19 files changed

+7095
-121
lines changed

README.md

Lines changed: 159 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,205 @@
1-
# 🤖 Liku-AI
1+
# Liku-AI 🎮🤖
22

33
**AI-Enhanced Terminal Game Platform with Real-Time WebSocket Communication**
44

5-
Liku-AI is a fork of [LikuBuddy](https://github.com/TayDa64/LikuBuddy) focused on providing superior AI agent tools for game interaction. While LikuBuddy uses file-based state polling, Liku-AI introduces **WebSocket-based real-time communication** for sub-5ms latency.
5+
A real-time AI agent platform and terminal game companion featuring a grandmaster-level chess engine, WebSocket API, and comprehensive training tools.
6+
7+
[![Node.js](https://img.shields.io/badge/Node.js-20.x-green.svg)](https://nodejs.org/)
8+
[![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue.svg)](https://www.typescriptlang.org/)
9+
[![Tests](https://img.shields.io/badge/Tests-476%20passing-brightgreen.svg)]()
10+
11+
## ✨ Features
12+
13+
### 🎯 Terminal Games
14+
- **♟️ Chess** - Full chess engine with AI opponent (beginner to grandmaster)
15+
- **🐍 Snake** - Classic snake game with AI-friendly state
16+
- **🦖 Dino Run** - Chrome dinosaur game clone
17+
- **⭕ Tic-Tac-Toe** - With minimax AI and multiplayer support
18+
- **📝 Hangman** - Word guessing game
19+
- **🔢 Sudoku** - Number puzzle game
20+
21+
### 🔌 WebSocket API
22+
Real-time bidirectional communication for AI agents:
23+
- Game state streaming (<1ms latency)
24+
- Command execution (keys, actions)
25+
- Query system (stats, leaderboards)
26+
- Multi-agent coordination
27+
- AI-vs-AI game sessions
28+
29+
### ♟️ Chess Engine
30+
Production-ready chess system:
31+
- **chess.js** foundation for move generation
32+
- Alpha-beta search with modern enhancements (TT, LMR, null move, PVS)
33+
- Comprehensive evaluation (material, PST, pawn structure, mobility, king safety)
34+
- Opening book with 20+ named openings
35+
- Gemini AI integration for move explanation
36+
- Unicode board display with chalk-based rendering
37+
38+
### 📊 Training & Analytics
39+
- Session recording and replay
40+
- Multi-format export (JSON, CSV, TFRecord)
41+
- Elo rating system
42+
- A/B testing framework for AI strategies
43+
44+
## 🚀 Quick Start
45+
46+
### Prerequisites
47+
- Node.js 20.x or higher
48+
- npm 10.x or higher
49+
50+
### Installation
651

7-
## 🚀 What's Different from LikuBuddy?
52+
```bash
53+
# Clone the repository
54+
git clone https://github.com/TayDa64/LikuBuddy.git
55+
cd LikuBuddy
56+
57+
# Install dependencies
58+
npm install
59+
60+
# Build
61+
npm run build
862

9-
| Feature | LikuBuddy | Liku-AI |
10-
|---------|-----------|---------|
11-
| AI Communication | File polling (50-100ms) | WebSocket push (<5ms) |
12-
| State Updates | Pull-based (agent polls) | Push-based (server notifies) |
13-
| Command Latency | ~80ms (file + activation) | ~3ms (direct socket) |
14-
| Multiple AI Agents | ❌ One at a time | ✅ Concurrent connections |
15-
| Event-Driven | ❌ Polling loops | ✅ Async event handlers |
16-
| Backward Compatible | N/A | ✅ File polling still works |
63+
# Run
64+
npm start
65+
```
1766

18-
## 📦 Installation
67+
### As Gemini CLI Extension
1968

2069
```bash
21-
git clone https://github.com/TayDa64/Liku-AI.git
22-
cd Liku-AI
23-
npm install
24-
npm run build
70+
# Install as Gemini extension
71+
gemini extensions install .
72+
73+
# Launch via Gemini CLI
74+
/liku
2575
```
2676

27-
## 🔌 WebSocket API
77+
## 🎮 Usage
2878

29-
### Server (Port 3847)
79+
### Terminal UI
80+
Navigate with arrow keys, select with Enter, escape to go back.
3081

31-
Liku-AI automatically starts a WebSocket server when the game launches:
82+
### Chess vs AI
83+
```bash
84+
# Start the app and select "Let's Play" → "Chess vs AI"
3285

33-
```typescript
34-
// Server broadcasts state on every game tick
35-
{
36-
"type": "state",
37-
"timestamp": 1701234567890,
38-
"data": {
39-
"pid": 12345,
40-
"screen": "Playing DinoRun",
41-
"status": "Score: 42 | State: PLAYING",
42-
"game": {
43-
"type": "dino",
44-
"data": {
45-
"dinoY": 0,
46-
"velocity": 0,
47-
"nextObstacle": { "distance": 15, "type": "CACTUS" }
48-
}
49-
}
50-
}
51-
}
86+
# Or run AI battle script:
87+
node scripts/chess-ai-battle.js --white=minimax --black=gemini --depth=6
5288
```
5389

54-
### Client Commands
55-
56-
Send commands to control the game:
90+
### WebSocket Client (for AI agents)
5791

5892
```typescript
59-
// Key press
60-
{ "type": "key", "payload": { "key": "space" }, "requestId": "req_1" }
93+
import { LikuAIClient } from 'liku-ai';
94+
95+
const client = new LikuAIClient('ws://localhost:3847');
96+
97+
// Connect and receive state
98+
client.on('state', (state) => {
99+
console.log('Game state:', state);
100+
});
61101

62-
// Action (high-level)
63-
{ "type": "action", "payload": { "action": "jump" }, "requestId": "req_2" }
102+
// Send commands
103+
client.sendKey('ArrowUp');
104+
client.sendAction('chess_move', { move: 'e2e4' });
64105

65-
// Query
66-
{ "type": "query", "payload": { "query": "gameState" }, "requestId": "req_3" }
106+
// Query data
107+
const stats = await client.query('stats');
67108
```
68109

69-
### Using the Client Library
110+
## 📁 Project Structure
70111

71-
```typescript
72-
import { LikuAIClient } from 'liku-ai/websocket';
73-
74-
const client = new LikuAIClient({
75-
onState: (state) => {
76-
console.log('Game state:', state);
77-
78-
// React to game state
79-
if (state.game?.data?.nextObstacle?.distance < 5) {
80-
client.sendKey('space');
81-
}
82-
}
83-
});
112+
```
113+
src/
114+
├── chess/ # Chess engine (ChessEngine, Evaluator, Search, AI, Openings)
115+
├── websocket/ # WebSocket server, client, router, sessions
116+
├── training/ # Recording, replay, analytics, A/B testing
117+
├── ui/ # Ink/React terminal UI components
118+
│ ├── games/ # Game components (Chess, Snake, Dino, TicTacToe...)
119+
│ └── components/ # Shared UI components
120+
├── core/ # Game state logging, database tools
121+
├── services/ # Database service (SQLite)
122+
└── index.tsx # Entry point
123+
```
84124

85-
await client.connect();
125+
## 🔧 Configuration
86126

87-
// Send commands
88-
await client.sendKey('enter'); // Start game
89-
await client.sendAction('jump'); // High-level action
127+
### WebSocket Server
128+
Default port: `3847`
129+
130+
```bash
131+
# Disable WebSocket server
132+
npm start -- --no-websocket
90133
```
91134

92-
## 🎮 Running the Game
135+
### Chess AI Difficulty
136+
| Level | Search Depth | Description |
137+
|-------|--------------|-------------|
138+
| Beginner | 2 | Makes mistakes, good for learning |
139+
| Intermediate | 4 | Casual player strength |
140+
| Advanced | 6 | Strong club player |
141+
| Grandmaster | 8+ | Near-optimal play |
142+
143+
## 📊 Performance
144+
145+
| Metric | Value |
146+
|--------|-------|
147+
| State Latency | ~1ms |
148+
| Command Latency | ~2ms |
149+
| Concurrent Clients | 1000+ tested |
150+
| Memory per Client | ~10KB |
151+
| Test Coverage | ~95% (476 tests) |
152+
153+
## 🧪 Testing
93154

94155
```bash
95-
# Standard mode (with WebSocket server)
96-
npm start
156+
# Run all tests
157+
npm test
97158

98-
# WebSocket server starts automatically on port 3847
99-
# Connect AI agents to ws://localhost:3847
159+
# Run with coverage
160+
npm run test:coverage
100161
```
101162

102-
## 🔄 Backward Compatibility
163+
## 🐳 Docker
103164

104-
Liku-AI maintains full compatibility with LikuBuddy:
105-
- File-based state logging still works (`likubuddy-state.txt`)
106-
- All existing PowerShell/Bash scripts function normally
107-
- Existing AutoPlayer module works unchanged
108-
- Same CLI commands and options
165+
```bash
166+
# Build image
167+
docker build -t liku-ai .
109168

110-
## 🛠️ Architecture
169+
# Run container
170+
docker run -p 3847:3847 liku-ai
111171

112-
```
113-
┌─────────────────┐ WebSocket ┌─────────────────┐
114-
│ AI Agent 1 │◄──────────────────►│ │
115-
└─────────────────┘ (push) │ │
116-
│ Liku-AI │
117-
┌─────────────────┐ WebSocket │ Game Server │
118-
│ AI Agent 2 │◄──────────────────►│ │
119-
└─────────────────┘ │ Port 3847 │
120-
│ │
121-
┌─────────────────┐ File (legacy) │ │
122-
│ Legacy Script │◄───────────────────│ │
123-
└─────────────────┘ └─────────────────┘
172+
# Docker Compose (with Redis)
173+
docker-compose up
124174
```
125175

126-
## 📊 Performance Comparison
176+
## 📚 Documentation
127177

128-
| Metric | File Polling | WebSocket |
129-
|--------|-------------|-----------|
130-
| State Read Latency | 50-100ms | <1ms |
131-
| Command-to-Effect | ~80ms | ~5ms |
132-
| CPU Usage (idle) | Higher (continuous reads) | Lower (event-driven) |
133-
| Supports Streaming |||
178+
- [WebSocket Protocol](docs/WEBSOCKET_PROTOCOL.md)
179+
- [Chess Implementation](todo-chess.md)
180+
- [Development Roadmap](TODO.md)
181+
- [Performance Benchmarks](docs/PERFORMANCE.md)
134182

135-
## 🗺️ Roadmap
183+
## 🤝 Contributing
136184

137-
- [x] WebSocket server infrastructure
138-
- [x] Type-safe client library
139-
- [ ] Integrate WebSocket into game state logger
140-
- [ ] Add streaming game replay
141-
- [ ] Multi-agent coordination protocol
142-
- [ ] AI training data export
143-
- [ ] Remote play support
185+
1. Fork the repository
186+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
187+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
188+
4. Push to the branch (`git push origin feature/amazing-feature`)
189+
5. Open a Pull Request
144190

145-
## 📝 Version
191+
## 📜 License
146192

147-
- **Liku-AI**: 2.0.0-alpha.1
148-
- **Based on LikuBuddy**: 1.3.0
193+
MIT License - see [LICENSE](LICENSE) for details.
149194

150-
## 🔗 Links
195+
## 🙏 Acknowledgments
151196

152-
- [LikuBuddy (upstream)](https://github.com/TayDa64/LikuBuddy)
153-
- [WebSocket Protocol Spec](./docs/WEBSOCKET_PROTOCOL.md) (coming soon)
197+
- [chess.js](https://github.com/jhlywa/chess.js) - Chess move generation
198+
- [Ink](https://github.com/vadimdemedes/ink) - React for CLI
199+
- [chalk](https://github.com/chalk/chalk) - Terminal string styling
200+
- [Chess Programming Wiki](https://www.chessprogramming.org/) - Chess engine algorithms
154201

155202
---
156203

157-
*Liku-AI - Real-time AI for Terminal Games* 🎮⚡
204+
**Version**: 2.0.0-alpha.1
205+
**Last Updated**: December 2025

0 commit comments

Comments
 (0)