mirror of
https://github.com/GoodStartLabs/AI_Diplomacy.git
synced 2026-04-27 17:23:21 +00:00
5.1 KiB
5.1 KiB
AI Diplomacy Animation Project
Key Information
- This is a TypeScript project using Three.js for 3D visualization of Diplomacy game states
- The application shows animated conversations between AI players and unit movements
- It's built with Vite for fast development
Common Commands
npm run dev- Start the development servernpm run build- Build for productionnpm run lint- Run TypeScript lintingnpm test- Run unit tests with Vitestnpm run test:ui- Run tests with UI interface
Project Structure
src/- Source codemain.ts- Main entry point, handles game loop and UI eventsgameState.ts- Central state management for the applicationconfig.ts- Global configuration settingsdomElements/- DOM manipulation and UI componentsmap/- Map rendering and manipulationunits/- Unit creation and animationtypes/- TypeScript type definitions
Game Flow
- Load game data from JSON
- Display initial phase
- When Play is clicked:
- Show messages sequentially, one word at a time
- When all messages are displayed, animate unit movements
- When animations complete, show phase summary (if available)
- Advance to next phase and repeat
Power Name Display System
The application now includes a dynamic power name display system:
- Model Names: If a
moments.jsonfile exists with apower_modelskey, the UI will display AI model names instead of generic power names (e.g., "o3" instead of "FRANCE") - Fallback: If no model names are available, the system falls back to standard power names (AUSTRIA, ENGLAND, etc.)
- Utility Function:
getPowerDisplayName(power)resolves the appropriate display name for any power - Game-Aware: The system automatically adapts based on the currently loaded game's data
Agent State Display
The game now includes agent state data that can be visualized:
- Goals and Relationships: Each power has strategic goals and relationships with other powers
- Journal Entries: Internal thoughts that help explain decision making
JSON Format Expectations:
- Agent state is stored in the game JSON with the following structure:
{ "powers": { "FRANCE": { "goals": ["Secure Belgium", "Form alliance with Italy"], "relationships": { "GERMANY": "Enemy", "ITALY": "Ally", "ENGLAND": "Neutral", "AUSTRIA": "Neutral", "RUSSIA": "Unfriendly", "TURKEY": "Neutral" }, "journal": ["Suspicious of England's fleet movements"] } } } - Relationship status must be one of: "Enemy", "Unfriendly", "Neutral", "Friendly", "Ally"
- The code handles case variations but the display should normalize to title case
Known Issues
- Text-to-speech requires an ElevenLabs API key in
.envfile - Unit animations sometimes don't fire properly after messages
- Debug mode may cause some animations to run too quickly
Data Format Notes
- The game data's "orders" field can be either an array or an object in the JSON
- The schema automatically converts object-format orders to array format for use in the code
- When debugging order issues, check the format in the original JSON
Debug Tools
The application includes a debug menu system (enabled when config.isDebugMode is true):
Debug Menu Structure
- Located in
src/debug/directory DebugMenuclass (debugMenu.ts) manages the collapsible menu system- Individual debug tools are implemented as separate modules and registered with the menu
- Menu does not close when clicking outside (for better UX during debugging)
Available Debug Tools
Province Highlighting (provinceHighlight.ts)
- Allows highlighting specific provinces on the map by name
- Input validation with visual feedback for invalid province names
- Supports Enter key and button click to trigger highlighting
Next Moment Display (nextMoment.ts)
- Shows the next chronological moment that will occur in the game
- Displays current phase, next phase, and next moment information
- Uses phase name parsing to determine chronological order
- Finds the next moment across all phases, not just the immediate next phase
- Shows moment category, phase name, and interest score
- Color-coded by importance (red for high scores ≥9, blue for others)
Phase Name Format
Phase names follow the format: [Season][Year][Phase]
- Seasons: Spring (S) → Fall (F) → Winter (W)
- Phases within each season: Move (M) → Retreat (R) → Adjustment (A)
- Example:
W1901R= Winter 1901 Retreat phase - Phase parsing logic is implemented in
types/moments.tswith Zod schemas
Adding New Debug Tools
- Create a new file in
src/debug/directory - Implement an init function that takes the DebugMenu instance
- Use
debugMenu.addDebugTool(title, htmlContent, beforeSection?)to add to menu - Register the tool in the DebugMenu's
initTools()method - Add any update functions to
updateTools()method if needed
Code Style Preferences
- Use descriptive function and variable names
- Add JSDoc comments for all exported functions
- Log important state transitions to console
- Use TypeScript types for all parameters and return values