AIGamer is a C# application that enables AI to play the game Warsim automatically. It uses computer vision and AI to analyze the game screen, make decisions, and execute commands by simulating keyboard input.
Watch AIGamer in action:
-
AI Integration: Support for multiple AI providers:
- Anthropic (Claude)
- Ollama (local models)
- Extensible architecture with placeholders for OpenAI and Gemini
-
Game Control:
- Automatically finds and focuses the Warsim game window
- Captures the game screen and analyzes it using AI vision models
- Generates appropriate game actions based on the current state
- Executes commands through simulated keyboard input
-
User Controls:
- Pause/Resume the AI's actions
- Step mode for granular control (execute one action at a time)
- Adjustable speed controls
- Session logging for review
-
Configuration:
- Easy setup through configuration file
- Customizable AI providers and models
-
Extensibility:
- While currently configured for Warsim, the architecture can theoretically work with any game that is:
- Slow-paced
- Turn-based
- Preferably CLI-based
- With modifications to the core prompt, it could also work with graphical games like poker
- While currently configured for Warsim, the architecture can theoretically work with any game that is:
- Clone this repository
- Copy
appsettings.example.json
toappsettings.json
- Add your API keys and configure your preferred AI provider in
appsettings.json
- Build and run the project
Before running the application, you must:
-
Create configuration file: Copy the example configuration file and rename it:
appsettings.json
-
Configure AI provider: Edit
appsettings.json
to set your preferred AI provider and add your API key (if applicable). The configuration supports:
- Anthropic (Claude)
- Ollama (local models)
- OpenAI (placeholder)
- Gemini (placeholder)
- Start the Warsim game
- Launch AIGamer
- Enter an optional session name (for logging purposes)
- Press any key to begin when ready
The following keyboard controls are available while the AI is playing:
- ESC - Exit program
- P - Pause/Resume AI actions
- S - Toggle step mode (pause after each action)
- N - Execute next action (when paused/in step mode)
- + - Increase speed (reduce delay between actions)
- - - Decrease speed (increase delay between actions)
- R - Reset speed to default (5 seconds)
- H - Display controls help
- Visual Studio 2022
- .NET 8.0
- Warsim game installed and runnable
- (optional) API keys for cloud-based AI providers (if not using Ollama)
- Ollama and either a multi-modal model (Gemma3 > 14B) or both a language model (the brains) and a vision model (the eyes -- llama3.2-vision)
The application logs all AI actions and system events /logs/ in your running directory. The log file path is displayed when the application starts. All images captured are also stored in the application directory and named for the model and date of capture.
There is a module for processing OCR via Tesseract instead of AI. It would require a slight change to flow but was left in the codebase. It is no longer used since it was generating poor results for larger screens full of options. I also realized that having vision models process the images would allow for more than just CLI based games in the future.
In order to compete with Claude, the Ollama code path makes a few optimizations. First, conversation history is retained. Second, game state and ai choices are summarized over time and stored. Lastly, system prompt is reloaded to ensure the models "understand the point" even after playing for a long while.
Feel free to play around!