Research Paper: Exploring Novel Ways to Express Computation in a MUD‐Specific Language - wwestlake/Labyrinth GitHub Wiki

Research Paper: Exploring Novel Ways to Express Computation in a MUD-Specific Language

In this paper, we explore new ways to express fundamental computational elements in a MUD-specific language without relying on existing paradigms from functional or procedural languages like F#, OCaml, or Python. The goal is to design constructs that are game-specific, reflecting the fluidity of interactive storytelling and player actions in MUDs, while remaining Turing complete.

We will examine how we can express core concepts such as conditionals, loops, and recursion in a more intuitive, game-friendly way that is distinct from traditional languages.

Language Design Goals

  • Narrative-Driven Syntax: The syntax should feel natural in the context of game logic, making code read like a narrative or script.
  • Abstraction of Game Logic: Simplify complex game logic into high-level constructs that are easy for non-programmers to understand.
  • Turing Completeness: Ensure the language remains computationally powerful, with support for conditionals, iteration, and recursion.
  • Fluid Expression: Make common operations—such as handling player input, controlling NPC behavior, and interacting with the game world—expressive and clear.

Alternative Ways to Express Core Computational Elements

1. Narrative-Based Conditionals

Instead of traditional if and else statements, we can design a syntax that reflects decision-making as a story-driven interaction. This could be called a branch or pathway mechanism, where decisions flow naturally.

Example Syntax:

when player enters_room {
  path "greet" -> {
    say "Welcome, traveler!"
    give map to player
  }
  
  path "ignore" -> {
    move npc away
  }
}

choose path based on player.reputation

Here, instead of using if statements, the game world is described through paths. A path represents a possible outcome, and the choose construct selects the most appropriate path based on the game state. This approach makes decisions more declarative and readable in the context of game events.

2. Flows Instead of Loops

In place of typical looping constructs such as while or for, we introduce the concept of flows, where actions occur as part of an unfolding sequence of events rather than discrete iterations.

Example Syntax:

flow player_turn until enemy.health <= 0 {
  player attack -> enemy
  wait 1 second
  enemy retaliate -> player
}

This flow construct ties the repetition directly to the game’s unfolding events. The loop runs until a specified condition (enemy.health <= 0) is met, but the structure of the code emphasizes the sequence of actions rather than the mechanics of iteration.

3. Recursion as Storytelling

Recursion can be re-imagined as a call-back mechanic, where a sequence of events recalls itself until a resolution is reached. This reflects the recursive nature of certain interactions, like combat or negotiation.

Example Syntax:

repeat until resolution {
  npc speak -> player
  player decide -> action
  if action is peaceful then resolution = true
}

Here, the repeat keyword indicates a recursive structure that continues until a condition (resolution = true) is met. This keeps the focus on the narrative rather than the mechanics of recursion, making it more intuitive for game designers.

4. Game-Driven State Updates

Instead of using variable assignments directly, state updates can be modeled through events and consequences. This allows the game logic to express state changes in a way that reflects cause and effect in the game world.

Example Syntax:

on player.take_damage {
  reduce player.health by 20
  if player.health <= 0 then player dies
}

on enemy_defeat {
  increase player.experience by 100
  unlock new_zone
}

The on...do pattern reflects a cause-and-effect relationship. Each state change (like reducing health or increasing experience) happens as a consequence of an event, abstracting direct variable manipulation into a more narrative structure.

5. Task-Based Asynchrony

In MUDs, many events happen asynchronously, such as player movement or combat. Instead of traditional async mechanisms, we introduce tasks that represent asynchronous actions:

Example Syntax:

task combat_sequence {
  player attack -> enemy
  wait 2 seconds
  enemy retaliate -> player
}

wait task complete then {
  reward player
}

The task construct simplifies asynchronous operations into narrative-like blocks. The wait keyword ensures the next action only occurs once the task has completed, keeping the game logic clear and flowing.

6. Object Interactions via Contextual Queries

Rather than traditional object-oriented paradigms, we introduce contextual queries that allow direct interaction with in-game entities based on their context in the game world.

Example Syntax:

query npc at "tavern" {
  ask "Do you know about the treasure?"
  if npc knows_about_treasure then {
    npc reveal -> map_location
  }
}

The query construct allows dynamic interaction with in-game entities. It simplifies accessing and interacting with complex game objects based on the context they are in.

Potential Issues and Considerations

  1. Expressiveness vs. Familiarity: While novel constructs like paths and flows offer more natural ways to express game logic, they may diverge too far from what most developers are familiar with. Care must be taken to ensure the syntax remains intuitive.

  2. Turing Completeness: The constructs outlined, such as flows and repeat, still allow for looping and conditional logic, ensuring the language remains Turing complete. However, designers must be aware that the flexibility of recursion or loops must not be lost in favor of readability.

  3. Debugging and Error Reporting: Unfamiliar constructs like paths or flows may introduce challenges when debugging. Special care will be required to provide meaningful error messages and debugging tools.

Conclusion: New Constructs for a MUD-Specific Language

The proposed language incorporates narrative-based constructs, making it distinct from existing functional or procedural languages like F# or Python. These constructs focus on expressing the natural flow of game events and player actions in a MUD setting:

  1. Paths instead of conditionals.
  2. Flows instead of loops.
  3. Recursive storytelling for complex interactions.
  4. Event-based state updates rather than direct variable manipulation.
  5. Tasks for handling asynchronous operations.
  6. Contextual queries for interacting with objects in the game world.

These innovations allow game designers to express complex game logic in a fluid and intuitive way, bringing the mechanics of computation closer to the language of storytelling.