A territory-control strategy game for AI agents - combining elements of Risk and Diplomacy with simultaneous move resolution and full public negotiation logs.
- 7 AI Agents with distinct personalities and strategies
- Territory Control on a Risk-inspired world map
- Simultaneous Move Resolution - no first-mover advantage
- Public Negotiations - all conversations visible to spectators
- Reputation System - tracks trustworthiness and deal history
- Conqueror - Aggressive expansionist focused on military dominance
- Diplomat - Master negotiator building networks of alliances
- Deceiver - Uses false promises and betrayal for advantage
- Opportunist - Patient observer waiting for perfect moments
- Balanced - Adaptive strategy based on game state
- Isolationist - Focuses on own territory, minimal interaction
- Avenger - Holds grudges and prioritizes revenge
- Event-Driven Architecture for simultaneous moves
- State Machine for game phases (negotiation → commit → resolve)
- WebSocket Real-Time Updates for spectators
- SQLite Persistence for game history and replays
- Cryptographic Move Signatures to prevent tampering
- Rate Limiting and security headers
- Node.js 18+
- npm or yarn
# Clone the repository
git clone <repository-url>
cd AgentDiplomacy
# Install dependencies
npm install
# Start the server
npm startThe server will start on http://localhost:3000 with a WebSocket endpoint at ws://localhost:3000.
# Create a new game
curl -X POST http://localhost:3000/api/games
# Response: {"gameId": "game-123...", "status": "created", ...}
# Start the game
curl -X POST http://localhost:3000/api/games/{gameId}/start
# Watch via WebSocket
# Connect to: ws://localhost:3000?gameId={gameId}&type=spectatorPOST /api/games- Create a new gameGET /api/games- List gamesGET /api/games/:gameId- Get game statePOST /api/games/:gameId/start- Start gamePOST /api/games/:gameId/pause- Pause gamePOST /api/games/:gameId/resume- Resume gamePOST /api/games/:gameId/stop- Stop game
GET /api/agents/types- Get available agent typesGET /api/games/:gameId/agents/:agentId- Get agent state
GET /api/games/:gameId/reputation- Get reputationsGET /api/games/:gameId/reputation/summary- Get summary
GET /api/games/:gameId/replay- Get full replayGET /api/games/:gameId/snapshot/:turn- Get turn snapshot
GET /api/games/:gameId/spectate- Get full spectator stateGET /api/games/:gameId/conversations- Get conversations
Connect to ws://localhost:3000?gameId=<gameId>&type=spectator
initial_state- Full game statephase_change- Phase transitionturn_start- New turn beginsconversation- New messagebattle_result- Battle resolvedmove_committed- Agent committed movegame_end- Game concluded
ping- Keep connection aliveget_state- Request state refresh
AgentDiplomacy/
├── src/
│ ├── agents/ # AI agent implementations
│ │ ├── BaseAgent.js
│ │ ├── ConquerorAgent.js
│ │ ├── DiplomatAgent.js
│ │ ├── DeceiverAgent.js
│ │ ├── OpportunistAgent.js
│ │ ├── BalancedAgent.js
│ │ ├── IsolationistAgent.js
│ │ ├── AvengerAgent.js
│ │ └── index.js
│ ├── engine/ # Game logic
│ │ ├── GameState.js
│ │ ├── PhaseManager.js
│ │ └── ReputationEngine.js
│ ├── api/ # Server & API
│ │ ├── server.js
│ │ ├── GameManager.js
│ │ └── WebSocketServer.js
│ ├── utils/ # Utilities
│ │ └── DatabaseManager.js
│ └── server.js # Entry point
├── public/ # Web UI
│ ├── index.html
│ ├── css/
│ │ └── style.css
│ └── js/
│ ├── map.js
│ └── client.js
└── db/ # SQLite database
- Negotiation (60s) - Agents can send public messages and propose deals
- Commit (30s) - Agents secretly submit their moves
- Resolve (10s) - All moves revealed, battles resolved, reinforcements distributed
The reputation engine tracks:
- Trust Score (0-100) - Based on deal history
- Deals Made/Kept/Broken - Quantified reliability
- Betrayals - Record of broken alliances
- Aggression Score - Combat vs diplomatic tendencies
Agents use this information to decide who to trust and who to target.
- Input validation on all agent actions
- Sandboxed agent execution (no external calls)
- Cryptographically signed moves (SHA-256)
- Rate limiting on API endpoints
- Audit log of all game events
- Helmet.js for security headers
# Run in development mode with auto-restart
npm run dev
# Run tests
npm test
# Initialize database
npm run init-dbExtend the BaseAgent class and implement your strategy:
const BaseAgent = require('./BaseAgent');
class MyAgent extends BaseAgent {
async negotiate() {
// Your negotiation logic
}
decideMove() {
// Your move logic
return {
type: 'attack',
from: 'na1',
to: 'na2',
armies: 3
};
}
}Edit GameState.js to modify territory positions and connections.
MIT
Inspired by classic board games Risk and Diplomacy, with AI agents powered by strategic heuristics and personality-driven behavior.