ChatGPT-4 helps me design a new IF platform

I’ve been playing around with ChatGPT-4 after seeing Luke Bechtel’s article on using it to design a new programming language. The experiment will be to design a C# based IF platform using fluid syntax and a world model based on an in-memory data store.

It’s actually going okay so far, but I’m current time-blocked until tomorrow.

This is an earlier phase before clarifying more principles with GPT-4:

using IFPlatform.WorldModel;
using IFPlatform.WorldModel.Nodes;
using IFPlatform.WorldModel.Edges;
using IFPlatform.WorldModel.CloakOfDarkness;

class Program
{
    static void Main(string[] args)
    {
        // Initialize the World
        var world = new World();

        // Create Locations
        Foyer foyer = world.Create<Foyer>();
        Bar bar = world.Create<Bar>();
        Cloakroom cloakroom = world.Create<Cloakroom>();

        // Create Items
        DarkCloak cloak = world.Create<DarkCloak>();
        EmptyHook hookFoyer = world.Create<EmptyHook>();
        CloakHook hookCloakroom = world.Create<CloakHook>();

        // Add Relationships (Edges)
        world.Connect(foyer, bar, Direction.North);
        world.Connect(bar, foyer, Direction.South);
        world.Connect(bar, cloakroom, Direction.West);
        world.Connect(cloakroom, bar, Direction.East);

        world.AddTo(foyer, hookFoyer);
        world.AddTo(cloakroom, hookCloakroom);
        world.AddTo(cloakroom, cloak);

        // ... Initialize other components and start the game engine
    }
}

I’m just having a conversation with the AI to design and improve the code. It’ll be interesting to see where this goes and how long it takes to get Cloak of Darkness running.

I’ve already instructed GPT-4 to make everything mode fluid and strongly-typed and abstract the idea of Nodes and Edges away from the library author or the story author. It already knows there’s a parser with tokenized grammar, a grammar library that validates token lists with the world model, a game engine, and more.

It’s insane how much it can infer. The whole Cloak of Darkness thing was directed by this statement:

Code an example of building the world model for Cloak of Darkness.

To which it responded with:

Cloak of Darkness is a simple IF game that serves as an example for implementing an IF system. The game consists of three rooms: Foyer, Bar, and Cloakroom. There is a dark cloak in the Cloakroom, and the player needs to hang the cloak in the Bar to win the game.

Let's build the World Model for Cloak of Darkness using our defined classes.

and off it went. I did not have to describe Cloak of Darkness beyond that statement.

I’m mostly modeling the structure after Inform 6 to start, though I do plan to implement some alternate text emission scenarios. I’ll be able to save all of the instructions off and anyone could alter them to emit python or golang or TypeScript.

I have no estimate for completion because we’re currently limited to 25 queries in a 3-hour period, but I’d guess I’d have a workable Cloak of Darkness in a few days. A more robust platform in a few weeks and an extensible platform in a few months.

Light years faster than anything we’ve done in the past.

I also believe this changes the entire concept of Speed-IF. Given access to ChatGPT, a speed-if contest could allow an author to develop a much more detailed and working story in the alloted two hours. Almost zero coding and all story design.

I liken GPT-4 to the advent of the Internet, the PC, computers in general, the industrial revolution, and every major leap forward in human history.

5 Likes

Maybe a leap forward for machines?

3 Likes

(Excited, heavy breathing)

I’ve recently made an account for ChatGPT, because I feel like if this is going to change the world, then I might as well get good at it now.

It’s a weird experience, because the power is clearly there, but my brain is so stuck at “…I can’t decide what to use this for.”

2 Likes

Made some progress today, but the AI is struggling with the lines between parser, grammar, and standard library. I’ve been through a few iterations of this and still figuring out how to elicit the right balance from GPT-4. It’s getting close, but it’s not quite right.

And just so we’re clear. I’m trying to avoid “jumping in” and fixing the code. I’m trying to get the AI to do 98% of the coding.

One other challenge is how to organize the solution. I will have to back track and redo that since I don’t like the current structure. I let GPT infer a structure, but I think I need to be clear about that before generating code.

Here’s more code for your entertainment:

using IFPlatform.Grammar;

namespace IFPlatform.StandardLibrary
{
    public class StandardLibrary
    {
        private readonly Grammar _grammar;

        public StandardLibrary(Grammar grammar)
        {
            _grammar = grammar;
            DefineCommandStructures();
        }

        private void DefineCommandStructures()
        {
            _grammar.CreateCommand("take").WithPattern("verb noun");
            _grammar.CreateCommand("drop").WithPattern("verb noun");
            _grammar.CreateCommand("look").WithPattern("verb noun");
            // ... add other command structures

            // Complex command structures
            _grammar.CreateCommand("put")
                .WithPattern("verb noun on noun")
                .WithPattern("verb noun in noun");

            _grammar.CreateCommand("ask")
                .WithPattern("verb npc about topic");

            _grammar.CreateCommand("look up")
                .WithPattern("verb topic in noun");
            
            // ... add other complex command structures
        }
    }
}
3 Likes

I backtracked on my conversation with ChatGPT.

I think we need to backtrack on the overall design and discuss principles.

*** ChatGPT ***
Certainly! It’s important to have a clear understanding of the overall design principles and goals before diving into implementation details. Here are some key principles to consider when designing an interactive fiction (IF) platform:

Modularity: Design the platform in a way that allows different components (like the parser, grammar library, world model, and standard library) to work together seamlessly while being independent of one another. This makes it easier to maintain and extend the platform in the future.

Extensibility: Ensure that the platform can be easily extended with new features, custom libraries, and even alternative parser or world model implementations without requiring major changes to the core architecture.

Ease of use: Make it simple for authors to create interactive fiction stories with minimal boilerplate code and a clean, intuitive API. This includes providing a fluid syntax for defining the world model and command structures, as well as clear error messages and debugging tools.

Flexibility: Allow authors to define custom rules, commands, and behaviors that suit their specific story requirements. This might involve supporting complex command structures, conditional responses, or even procedural content generation.

Performance: Optimize the platform for fast execution and low memory overhead. This may involve implementing efficient data structures, caching, or other techniques to ensure that the platform can handle large, complex stories with many locations, objects, and interactions.

Portability: Design the platform to be easily adaptable to different platforms and environments, such as web browsers, mobile devices, or desktop applications.

Documentation and community: Provide comprehensive documentation, tutorials, and examples to help authors get started with the platform quickly. Encourage community involvement by making the platform open-source and fostering a supportive community of users and contributors.

These principles should help guide the design and development of your IF platform. They will ensure that your platform is both powerful and easy to use, making it a valuable tool for interactive fiction authors. With a solid foundation in place, you can then iterate on the platform’s features and capabilities to continually improve and expand its functionality.


Perfect. Regarding modularity, I would like to identify the core components and their responsibilities.

*** ChatGPT ***
Certainly! Here’s a breakdown of the core components of an interactive fiction
platform and their responsibilities:

  1. World Model: This component is responsible for maintaining the state of the story world, including locations, objects, characters, and relationships between them. It should provide a clean and fluid API for authors to define and interact with the world model, such as adding locations, setting up connections between locations, and adding items to locations.
  2. Parser: This component takes user input as plain text and tokenizes it into structured data. It is responsible for identifying verbs, nouns, and other elements of the user’s command. The parser should be flexible enough to handle a variety of input formats and recognize different synonyms or abbreviations for the same command.
  3. Grammar Library: This component is responsible for defining and validating command structures. It allows authors to define custom command patterns using a fluid syntax, such as “verb noun” or “verb adjective noun”. The grammar library should be able to work with the parser to validate user input against the defined command structures, ensuring that the input is both grammatically correct and contextually appropriate within the story world.
  4. Standard Library: This component provides a set of commonly used commands, objects, and behaviors for interactive fiction stories, such as “take”, “drop”, “examine”, and “go”. It leverages the grammar library to define the command structures for these standard commands and can also provide default implementations for their behavior. Authors should be able to easily extend or override the standard library to customize the behavior of their story.
  5. Game Engine: This component is responsible for managing the game loop and coordinating interactions between the other components. It processes user input, updates the world model based on the input and the current state of the story, and generates appropriate output to display to the user. The game engine should also handle saving and loading game state, as well as managing any timers or event-driven behavior within the story.

By clearly defining the responsibilities of each core component, you can ensure that your interactive fiction platform remains modular and easy to maintain. This separation of concerns will also make it simpler to extend the platform with new features or integrate it with other tools and libraries in the future.


Let's add one more component. We need a Text Service to accept emitted text
from the platform and organize it for output based on context and rules.

*** ChatGPT ***
Absolutely! A Text Service component can be a valuable addition to an interactive fiction platform. Here’s a brief overview of its responsibilities:

  1. Text Service: This component is responsible for managing and organizing text output generated by the platform, such as descriptions, messages, and responses to user commands. It should provide a consistent and customizable interface for formatting and displaying text, taking into account the context of the story and any rules or preferences defined by the author. Key responsibilities of the Text Service component include:
  • Text buffering: Collect and store text output generated during a single turn or interaction, allowing for later manipulation, formatting, or filtering before displaying it to the user.
  • Text formatting: Apply consistent formatting rules to the text output, such as capitalization, punctuation, and line breaks. This may also include support for text styling (e.g., bold, italic) or colorization, if desired.
  • Conditional output: Manage conditional text, allowing authors to define text that is only displayed under certain conditions or based on the current state of the story world. This can be useful for creating dynamic descriptions or responses that change based on the player’s actions or choices.
  • Output organization: Organize text output into logical sections or groups, such as room descriptions, object descriptions, character dialogue, and action responses. This can help improve the readability and flow of the text for the player.
  • Customization: Provide an easy way for authors to customize the Text Service’s behavior, such as defining their own formatting rules or output templates. This allows authors to create a unique look and feel for their story without having to modify the core platform code.

By incorporating a Text Service component into your interactive fiction platform, you can ensure that the text output is clean, consistent, and well-organized, enhancing the overall user experience and making it easier for authors to craft immersive and engaging stories.


2 Likes

And continuing…

Execution of all user input should be delegated to the Standard Library or overridden in the user's Story File.

*** ChatGPT ***
To achieve this, you can design the platform in such a way that the Game Engine delegates the execution of user commands to the Standard Library by default. The Standard Library should provide a set of standard command implementations, as well as a mechanism for authors to extend or override them in their Story Files.

Here’s a high-level approach to achieve this:

  1. Define command handlers: In the Standard Library, create command handler classes or methods for each standard command. These handlers will encapsulate the logic for executing the command and interacting with the World Model.
  2. Create a command registry: In the Standard Library, maintain a registry or dictionary that maps command patterns or verbs to their respective command handlers. This registry will be used by the Game Engine to look up and execute the appropriate handler for a given user input.
  3. Allow custom command handlers: Provide a way for authors to define their own command handlers in their Story Files. These custom handlers can either extend the functionality of a standard command or completely override its behavior.
  4. Register custom command handlers: When the author defines a custom command handler in their Story File, update the command registry in the Standard Library to map the corresponding command pattern or verb to the new handler. This will ensure that the custom handler is executed instead of the default handler when the command is invoked.
  5. Delegate command execution: In the Game Engine, when processing user input, look up the command handler for the given command pattern or verb in the Standard Library’s command registry. If a handler is found, delegate the execution of the command to that handler, passing any relevant context or arguments as needed.

By following this approach, you can ensure that the execution of user commands is delegated to the Standard Library by default, while also providing the flexibility for authors to customize or override command behavior in their Story Files as needed.


Of all of these components, which one should we dive deeper into to start?

*** ChatpGPT ***
Let’s start with the World Model component, as it serves as the foundation of the interactive fiction platform by representing the underlying story world, its objects, characters, and relationships. A well-designed World Model will make it easier to build the other components and ensure a smooth integration between them.

When building the World Model component, you’ll want to consider the following aspects:

  1. Data structures: Design the data structures that will represent the various elements in the story world, such as rooms, objects, characters, and connections between them. Consider using object-oriented concepts and design patterns, such as inheritance and composition, to make the structures flexible and extensible.
  2. Strongly-typed nodes and edges: Implement the nodes and edges in the in-memory graph as strongly-typed classes or structures. This will make it easier to work with the data and ensure that only valid relationships can be established between the elements in the story world.
  3. Fluid creation and modification: Provide a fluid API or domain-specific language for creating and modifying the elements in the World Model. This will allow authors to easily define their story world and interact with it during the development of their interactive fiction.
  4. Querying and traversal: Implement methods for querying and traversing the graph of nodes and edges in the World Model. This will enable other components, such as the Parser and Game Engine, to interact with the story world and determine valid actions or commands based on the current state.
  5. Serialization and deserialization: Implement mechanisms for saving and loading the state of the World Model to and from external storage, such as files or databases. This will allow authors to save their progress and resume their work on the story at a later time.

By focusing on the World Model component first, you’ll establish a strong foundation for the interactive fiction platform and gain a better understanding of how the other components will interact with and build upon the story world.


2 Likes