Algorithm Module Breakdown for LLM-Integrated Game Design

Preface

This document outlines the clear boundaries between LLM-generated content and code-driven game mechanics. The core principle is straightforward: LLM handles narrative elements while game logic remains the responsibility of code implementation.

Section 1: LLM Responsibilities (Narrative Content)

Component Description LLM Required
Standard Scene Generation 20 scenarios per level, 200 total rounds; descriptions and multiple-choice options generated by LLM ✅ Yes
Inter-Level Event Generation Once per level; generates scenario, options, and designates trap choices ✅ Yes
Boss Personalization Based on moral alignment ratio to generate inner demon forms, opening dialogues, and dynamic battle commentary ✅ Yes (or config + variables)
Card Names and Descriptions Each regular card and wild card gets its name and flavor text from LLM ✅ Yes
Tutorial Text Can be stored in RAG database or static files, or generated by LLM ⚠️ Optional (static is more stable)
Help Documentation Static text, no LLM needed ❌ No

Section 2: Code-Driven Algorithm Modules (Game Mechanics)

2.1 Moral Alignment Tracking Algorithm

This is the core algorithm of the system:

  • Input: Player's choice per round (A/B/C/D)
  • Process:
    • Udpate good, evil, and neutral values based on choices (including base scores and consecutive choice multipliers)
    • Check after each round whether an extreme ending threshold has been reached
    • After 200 rounds, calculate the final ratio for standard endings
  • Output: Three moral values, ending trigger status

2.2 Card Acquisition Control

The current design grants exactly 1 regular card per round, plus 0 or 1 wild card from inter-level events. This is essentially a simple counter rather than complex logic:

On round completion:<br></br>  Grant 1 regular card, type determined by choice<br></br>  Increment total regular card count

Future adjustments (such as skipping card rewards on certain rounds) would only require modifying a configuration file.

2.3 Boss Battle Rules Engine

  • Input: Both parties' hands (type, quantity), player action (challenge/follow/fold)
  • Process:
    • Resolve challenge outcomes (flip verification, win/loss calculation)
    • Update hand (take back, discard, additional discards)
    • Switch first-move advantage
    • Check victory conditions (hand count reaches zero)
  • Output: Game state, battle result

2.4 Inter-Level Trap Detection

Trap options can be randomly assigned by code without LLM involvement in the logic. Alternatively, LLM can mark trap options during generation (e.g., JSON with trap: "C"), which code reads directly. The latter approach is recommended for narrative consistency.

2.5 Ending Resolution

  • Extreme Endings: Triggered in real-time by the moral alignment algorithm
  • Standard Endings: Determined by final ratio after 200 rounds
  • Boss Battle Endings: Combine boss battle outcome with moral alignment to generate final narrative (can be LLM-generated or pre-written)

2.6 Inventory Management

Pure data structure responsibilities:

  • Store cards acquired in current level (type, name, description, acquisition round)
  • Provide query interfaces (inventory, card commands)

2.7 Auxiliary Features

  • Status Display: Output vague descriptions based on moral ratio (e.g., "leans toward kindness")
  • Save/Load: Serialize current game state if implemented

Section 3: Potential Missing Algorithm Modules

3.1 Boss AI Strategy

If the boss isnt purely random, consider implementing decision logic:

  • Rule-based AI: Challenge when suspicion probability exceeds threshold
  • LLM-driven: Generate boss "thoughts" in real-time for decision-making (complex and slow—rule-based is recommended)

3.2 Companion System

Companions provide advice during gameplay:

  • Normal gameplay: Generate dialogue based on current moral values and scene type
  • Boss battles: Provide suggestions like "I think he's bluffing" (manage API call frequency carefully)

3.3 Reincarnation Rewards/Collection System

Track unlocked endings and card collections—pure data storage without complex algorithms.

Section 4: Technical Architecture Overview

┌─────────────────┐<br></br>│    User Input    │<br></br>└────────┬────────┘<br></br>         ▼<br></br>┌─────────────────────────────────────┐<br></br>│         Game Main Loop (Code)        │<br></br>│  - Parse commands                    │<br></br>│  - Execute moral algorithm updates   │<br></br>│  - Record card acquisition           │<br></br>│  - Check ending triggers             │<br></br>│  - Invoke LLM for scene generation   │<br></br>└─────────────────────────────────────┘<br></br>         │<br></br>         ▼<br></br>┌─────────────────────────────────────┐<br></br>│           LLM Service (Optional)     │<br></br>│  - Scene generation (normal/level)  │<br></br>│  - Card name and description         │<br></br>│  - Boss voice lines                   │<br></br>└─────────────────────────────────────┘<br></br>         │<br></br>         ▼<br></br>┌─────────────────────────────────────┐<br></br>│             Data Persistence         │<br></br>│  - Moral alignment values            │<br></br>│  - Current level card list           │<br></br>│  - Game progress (level, round)      │<br></br>└─────────────────────────────────────┘

Algorithm Count Summary

  • Core algorithms: 2 (Moral alignment tracking, Boss battle rules)
  • Auxiliary logic: Card counting, trap detection, ending resolution (simple logic, not complex algorithms)

Section 5: Key Takeaways

The LLM's role is primarily content generation:

  • Scene descriptions and options
  • Templates and boss configurations
  • Tutorial content (can be static or RAG-assisted)

Elements not requiring LLM:

  • Inventory management (handled by the application)
  • Game logic and state management

Important distinction: Even when LLM contributes to boss battle strategy, the core battle logic remains code-driven. Additionally, card names and descriptions should be LLM-generated to enhance collectibility and narrative coherence.

Tags: game-development llm-integration algorithm-design game-architecture moral-alignment

Posted on Wed, 09 Sep 2026 16:55:37 +0000 by codebuilder