Files
lucidia-core/rpg.py
Alexa Louise 6afdb4b148 Initial extraction from blackroad-prism-console
Lucidia Core - AI reasoning engines for specialized domains:
- Physicist (867 lines) - energy modeling, force calculations
- Mathematician (760 lines) - symbolic computation, proofs
- Geologist (654 lines) - terrain modeling, stratigraphy
- Engineer (599 lines) - structural analysis, optimization
- Painter (583 lines) - visual generation, graphics
- Chemist (569 lines) - molecular analysis, reactions
- Analyst (505 lines) - pattern recognition, insights
- Plus: architect, researcher, mediator, speaker, poet, navigator

Features:
- FastAPI wrapper with REST endpoints for each agent
- CLI with `lucidia list`, `lucidia run`, `lucidia api`
- Codex YAML configurations for agent personalities
- Quantum engine extensions

12,512 lines of Python across 91 files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 08:00:53 -06:00

91 lines
2.7 KiB
Python

"""Tiny text-based RPG engine for Lucidia.
This module provides minimal classes to model a small turn-based battle game.
It can be imported as a library or executed directly for a quick demo.
"""
from __future__ import annotations
import random
from dataclasses import dataclass
from typing import Optional
@dataclass
class Character:
"""Basic combatant with hit points and attack range."""
name: str
hp: int
attack_min: int
attack_max: int
def is_alive(self) -> bool:
"""Return ``True`` if the character still has hit points."""
return self.hp > 0
def attack(self, other: "Character", rng: random.Random) -> int:
"""Attack ``other`` and return the damage dealt."""
damage = rng.randint(self.attack_min, self.attack_max)
other.hp = max(0, other.hp - damage)
return damage
class Game:
"""Manage a simple player-versus-enemy battle."""
def __init__(
self, player: Character, enemy: Character, rng: Optional[random.Random] = None
) -> None:
self.player = player
self.enemy = enemy
self.rng = rng or random.Random()
def player_turn(self) -> int:
"""Execute the player's attack."""
return self.player.attack(self.enemy, self.rng)
def enemy_turn(self) -> int:
"""Execute the enemy's attack."""
return self.enemy.attack(self.player, self.rng)
def run(self) -> str:
"""Run the battle until one character is defeated.
Returns
-------
str
The name of the winning character.
"""
while self.player.is_alive() and self.enemy.is_alive():
self.player_turn()
if not self.enemy.is_alive():
break
self.enemy_turn()
return self.player.name if self.player.is_alive() else self.enemy.name
def main() -> None:
"""Play a quick demo game in the console."""
rng = random.Random()
player = Character("Hero", hp=20, attack_min=2, attack_max=5)
enemy = Character("Goblin", hp=15, attack_min=1, attack_max=4)
game = Game(player, enemy, rng)
print("Welcome to Lucidia RPG! Type 'attack' to strike your foe.")
while player.is_alive() and enemy.is_alive():
cmd = input("> ").strip().lower()
if cmd != "attack":
print("Unknown command. Try 'attack'.")
continue
dmg = game.player_turn()
print(f"You hit {enemy.name} for {dmg} damage (hp={enemy.hp}).")
if not enemy.is_alive():
break
dmg = game.enemy_turn()
print(f"{enemy.name} hits you for {dmg} damage (hp={player.hp}).")
winner = game.player.name if player.is_alive() else enemy.name
print(f"{winner} wins!")
if __name__ == "__main__":
main()