Friday, February 13, 2026

controlled natural video game languages

 license: public domain CC0.


Designing a Controlled Natural Language (CNL) tailored specifically for defining games offers incredible advantages. As you pointed out, it gives us the ability to keep the LLM grounded, provides clarity for human developers, and ensures that we maintain a stable contract between game logic and the LLM engine.

Let's break it down into a concrete plan that incorporates all the elements you outlined — from vocabulary design to grammar rules, to the game loop using the CNL. I’ll also provide a parser design and how this CNL could work seamlessly in the architecture.


Controlled Natural Language (CNL) for Arcade-Style Games

1. Overview

The goal is to create a controlled language for defining arcade-style games like Space Invaders, so that:

  • Human developers can write clear, readable game specs.

  • The LLM engine interprets these rules unambiguously and reliably.

  • The CNL prevents unexpected or illogical behavior from the LLM by providing a well-defined vocabulary and grammar.

2. Key Design Principles for the CNL

  • Human Readability: The CNL should be simple and intuitive, while still being formal enough to avoid ambiguity.

  • Machine Parsability: The language needs to be easily parsed by the system to convert it into structured game logic.

  • LLM Friendliness: The CNL needs to be easy for the LLM to learn, adhere to, and output within the defined constraints.

Major Components of the CNL

  1. Entities: Defines the objects in the game (e.g., player, enemies, bullets).

  2. Behavior: Describes how entities move, interact, and change over time.

  3. Rules: Specifies constraints, such as boundaries, health, and win conditions.

  4. Variations: Allows for additional rules that add complexity or randomness (e.g., different types of enemies or power-ups).


3. CNL Vocabulary

Entity Vocabulary

  • Player: Defines the main character (e.g., ship).

  • Enemy: Describes the enemies, their type, and behaviors.

  • Bullet: Describes the projectiles fired by the player.

  • Power-up: Any temporary bonuses or effects (if applicable).

Example Entity Definitions:

There is a player ship at row 1 column 5.
There are 10 basic enemies in row 10.
A bullet is an object that moves upward.

Action Vocabulary

  • Move: Describes movement in various directions.

  • Fire: Describes shooting actions (usually by the player).

  • Destroy: Describes the destruction of an entity (e.g., when a bullet hits an enemy).

Example Action Definitions:

Each enemy moves horizontally by 1 cell every tick.
The player ship moves left or right by 1 cell when commanded.
The player ship fires a bullet when the action FIRE occurs.

Interaction Vocabulary

  • Collision: Describes interactions between entities, such as bullets hitting enemies.

  • Boundary: Describes the edges of the game grid.

Example Collision Rules:

If a bullet occupies the same cell as an enemy, then the enemy is destroyed.
If an enemy reaches row 1, then the game ends.

Variation Vocabulary

  • Speed: Describes movement speed.

  • Pattern: Describes movement patterns (e.g., zig-zag).

  • Types: Different classes of enemies, each with their own behavior.

Example Variations:

A fast enemy moves horizontally by 2 cells each tick.
A shield blocks bullets until it has taken 3 hits.

4. Grammar Rules

The grammar of the CNL will dictate the structure and flow of valid statements. Below are basic sentence patterns for defining game rules.

Entity Declarations

  • There is a [entity] at [position].

  • There are [number] [entity] in [position].

  • [Entity] is an object that [behavior].

Action Rules

  • [Entity] [action] when [condition].

  • Each [entity] [action] [frequency].

Collision and Interaction Rules

  • If [condition] then [outcome].

  • When [entity] reaches [boundary], [action].

Example Rules Syntax

There is a player ship at row 1 column 5.
Each enemy moves horizontally by 1 cell every tick.
If a bullet occupies the same cell as an enemy then the enemy is destroyed.

The grammar is designed to be as readable as possible while keeping a consistent, logical structure.


5. System Prompt for the LLM

The system prompt ensures that the LLM adheres to the vocabulary and grammar of the CNL. It also specifies that the LLM must follow the rules strictly, which prevents it from deviating into creative or nonsensical outputs.

System Prompt Example

You are a game engine that interprets a controlled natural language (CNL) specification for a 2D arcade shooter game. You must use the vocabulary and sentence structures specified below. Your task is to update the game state based on the actions taken, following the rules provided. If you encounter a concept not covered by the vocabulary, you must ask for clarification. Your output must be structured as JSON, representing the next state of the game.

The system prompt also includes a glossary of terms and sentence templates that the LLM can use.

Glossary Example (for the LLM)

Entities: player ship, enemy, bullet, power-up
Actions: move, fire, destroy, spawn
Conditions: occupies, reaches, moves, takes hits
Outcomes: destroyed, removed, ends game

6. Parser for the CNL

The CNL Parser converts human-written CNL game rules into a machine-readable format, such as JSON or a domain-specific language (DSL). The parser also validates the input to ensure that it adheres to the CNL syntax and grammar.

Steps for the Parser:

  1. Lexical Analysis: Breaks down the CNL text into tokens (keywords, actions, entities, etc.).

  2. Syntax Checking: Ensures the sentence structure follows the grammar rules.

  3. Rule Extraction: Converts the CNL sentence into structured game logic (e.g., a set of JSON rules).

Example Parsed Output:

{
  "entities": [
    { "type": "player", "position": { "row": 1, "column": 5 } },
    { "type": "enemy", "count": 10, "position": { "row": 10 } }
  ],
  "rules": [
    { "action": "move", "subject": "enemy", "direction": "horizontal", "speed": 1 },
    { "action": "fire", "subject": "player" },
    { "condition": "bullet occupies enemy", "effect": "enemy destroyed" }
  ]
}

This structured representation will be used by the LLM engine to update the game state.


7. Example: Space Invaders Defined in CNL

Game Specification (CNL)

The grid has 15 rows and 10 columns.

There is one player ship at row 1 column 5.
The player ship moves left or right by 1 cell when commanded.
The player ship fires a bullet when the action FIRE occurs.

A bullet moves upward by 1 cell each tick.
If a bullet reaches row 15, the bullet is removed.

There are 20 basic enemies in rows 10 to 12.
Each basic enemy moves horizontally by 1 cell every tick.
If any basic enemy reaches a boundary, then all basic enemies move down by 1 cell.

If a bullet occupies the same cell as a basic enemy, then the basic enemy is destroyed.
If any basic enemy reaches row 1, then the game ends.

Parsed Output (JSON):

{
  "grid": { "rows": 15, "columns": 10 },
  "entities": [
    { "type": "player", "position": { "row": 1, "column": 5 }, "actions": ["move left", "move right", "fire"] },
    { "type": "enemy", "count": 20, "position": { "row": 10 }, "movement": { "direction": "horizontal", "speed": 1 } },
    { "type": "bullet", "movement": { "direction": "upward", "speed": 1 }, "remove_condition": "reaches row 15" }
  ],
  "rules": [
    { "condition": "bullet occupies enemy", "effect": "enemy destroyed" },
    { "condition": "enemy reaches row 1", "effect": "game ends" }
  ]
}

8. Next Steps / Ideas

1. Grammar Refinement

  • Fine-tune the grammar to cover more complex actions, interactions, and game dynamics.

  • Consider expanding the CNL to include things like power-ups, complex AI behaviors, or player health.

2. Dynamic Rule Generation

  • Allow for dynamic generation of rules, enabling the game to change over time (e.g., evolving enemy behavior, power-ups that modify rules).

3. Game State Visualization

  • Use the structured output from the CNL parser to automatically generate visualizations of the game state (e.g., a grid representing the positions of the player, enemies, and bullets).

**4.

Enhanced LLM Training**

  • Train or fine-tune the LLM on a larger corpus of game rules to improve its ability to interpret the CNL.


9. Conclusion

Using a Controlled Natural Language (CNL) for defining video games in this way provides an elegant, precise way to control LLM behavior while enabling human-readable game design. This CNL approach balances creativity and structure, ensuring the game logic stays grounded while still allowing for unique, emergent gameplay experiences.

No comments:

Post a Comment