Skip to content

Ralpharama/AIsAdventure

Repository files navigation

A python file that is run on the command line. A casual game that runs in a loop with a five minute pause until terminated. We mainly just read the story but there is some interaction.

Concept: you (an AI) are in a fantasy world having an adventure, you make your own decisions and communicate your progress to us via Slack/Teams/Messenger etc. Sometimes you ask for advice and wait for a reply before proceeding.

We will maintain three json files locally: events (a record of what has happened for the last several events, constantly updated and trimmed), self (personal info and inventory), world (important things about the world that need to be remembered).

Sometimes we will decide to take no action, and we just wait another 5 minutes. If we hit rate limits we just silently wait until we get reset.

We will generate all content for the game using AI API calls to Gemini.

Game start: ping a publicly accessible news site, use the first story as inspiration for the starting point in the world/game, if the news story had occurred in a fantasy setting https://feeds.bbci.co.uk/news/rss.xml we create the local files and then begin.

Example news: 'It's out of this world': Life-changing eye implant helps blind patients read again - The results are astounding and a major advance, say surgeons involved in international research using the pioneering technology. We could interpret this as a plague is blinding people in the realm but a wizard has found magic to cure it, but he is missing, maybe we'll try and find him.

Example game play:

I discover a hatch in the floor and open it. It is very dark. There is a ladder going down. I look around but there's no light source. (pause) I decided to go down the ladder to investigate but only a few feet down and I can smell goblins! I scurry back up. (pause) The goblins must have heard me, they burst through the hatch! I am running. Do you think I should stand and fight, keep running, or hide? (wait for answer, take that into account, but still make your own decision)


🎮 Setup Instructions

Prerequisites

Installation

  1. Install dependencies:
pip install -r requirements.txt
  1. First run:
python game.py

This will create a config.json file.

  1. Configure API key: Edit config.json and add your Gemini API key:
{
  "gemini_api_key": "YOUR_ACTUAL_API_KEY_HERE",
  "news_feed_url": "https://feeds.bbci.co.uk/news/rss.xml",
  "messaging": {
    "type": "console",
    "webhook_url": ""
  }
}
  1. Run the game:
python game.py

Features Implemented

Main Game Loop - Runs every 5 minutes automatically
JSON Storage - Three files: events.json, self.json, world.json
News Integration - Fetches BBC RSS feed for game inspiration
Gemini AI - Generates story and decisions
Rate Limit Handling - Continues silently if API limits hit
Messaging Ready - Console output (Slack/Teams webhook support ready)
Persistent State - Game continues from where it left off
Keep Active Mode - Toggles scroll lock to stay "active" in Teams/Slack! 🎮

Game Files

  • game_data/events.json - Last 10 events (auto-trimmed)
  • game_data/self.json - Character info, inventory (max 15 items), location, health
  • game_data/world.json - World knowledge (auto-trimmed to prevent bloat)
    • Key facts: Max 15 (keeps most recent)
    • Locations: Max 20 (keeps most recent)
    • NPCs: Max 10 (keeps most recent)
  • game_data/player_input.txt - Your responses to AI questions (auto-deleted after reading)
  • config.json - API keys and configuration (not tracked in git)

Token Management: All data files are automatically trimmed to prevent excessive token usage and API costs. Run python check_tokens.py to see current usage estimates.

Optional: Messaging Integration

To send updates to Slack or Teams, update your config.json:

For Slack:

{
  "messaging": {
    "type": "slack",
    "webhook_url": "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
  }
}

For Teams:

{
  "messaging": {
    "type": "teams",
    "webhook_url": "https://outlook.office.com/webhook/YOUR_WEBHOOK_URL"
  }
}

Usage

🚀 One-Click Launch (Windows)

Double-click: start_game.bat or start_game.ps1

This launches all three components in separate windows:

  1. Webhook Server (Flask)
  2. ngrok Tunnel
  3. Game Loop

To get your ngrok URL after starting:

  • Double-click: get_ngrok_url.ps1 (copies URL to clipboard!)

To stop everything:

  • Double-click: stop_game.bat

🎮 Manual Launch

  • Start the game: python game.py
  • Stop the game: Press Ctrl+C
  • Reset the game: Delete the game_data folder
  • Check game state: Open the JSON files in game_data/

The game will:

  1. Fetch a news story on first run
  2. Generate a fantasy world based on the news
  3. Take actions every 5 minutes
  4. Sometimes ask for your advice
  5. Continue until you stop it or the character dies

💬 Responding to Questions

When the AI asks for your advice, you have 30 minutes to respond. There are three ways to answer:

Option 1: Quick Response Script (Easiest)

python respond.py "Your answer here"

Or run it without arguments to be prompted:

python respond.py

Option 2: Manual File Edit

Create/edit the file game_data/player_input.txt with your response. The AI checks this file every 10 seconds when waiting for input.

Option 3: Slack/Teams Integration (Advanced)

Quick Start:

  1. Install Flask: pip install flask
  2. Start webhook server: python webhook_server.py (leave running)
  3. In a NEW terminal, expose it: ngrok http 5000
  4. Copy the HTTPS URL from ngrok (e.g., https://abc123.ngrok.io)
  5. Follow the detailed guide in SLACK_SETUP.md to configure Slack

Once configured, respond in Slack with:

/respond Your advice here

How it works:

  • AI asks a question and waits 30 minutes
  • You respond using one of the methods above
  • AI reads your response and considers it (but still makes its own decision!)
  • If timeout expires, AI decides on its own

🎮 Stay Active Feature (Windows)

Your AI adventure keeps you "active" in Teams/Slack!

Every time the game loop runs (every 5 minutes), it toggles the Scroll Lock key twice. This simulates activity and prevents Teams/Slack from showing you as "Away" or "Inactive".

Configuration

In config.json:

{
  "keep_active": true
}

Set to false to disable this feature.

How It Works

  • Toggles Scroll Lock twice (on/off/on/off)
  • Happens every game loop iteration (5 minutes)
  • Windows only (safely ignored on other platforms)
  • No visible effect on your screen
  • You'll see: 📍 Scroll lock toggled (keeping you active!)

Now you can go on adventures while "working"! 😉


🧙‍♂️ May the goblins be ever in your favor!

About

A Gemini AI Idle Adevnture Game

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published