AdventureGen: an experiment in AI generated games
In the most recent LDs, I created some very experimental entries, with the goal of doing and learning something really new, even though the result may be a little obnoxious as an actual game. This time round, my entry has no direct connection with the theme, but instead, this is in the hands of the player: you can choose your own theme to generate a game.
Lately I've been playing around with chatbot APIs, so I thought, let's use this to generate games. I decided on a point and click adventure format, which seems to me one of the simplest game mechanics to start with. There are a limited number of actions: go from A to B, pick up object, use object. ChatGPT readily came up with fairly structured descriptions of small adventure games, including location descriptions and walkthroughs, so I thought, let's give that a try.
The basic idea of my game generator is that the AI (GPT-4o) generates a definition for a complete game, given a description of the game mechanic (e.g. the game goal and allowed actions) and a theme. I used OpenAPI's function calling feature to force the AI to create structured output. With function calling, you provide function descriptions to the AI, and then ask it to perform actions in the prompt. The AI then tries to map the desired actions onto available functions, and call them with appropriate parameters. Also it can process function output and tries to correct errors returned by the functions.
For the adventure game I invented some functions:
create_room(self, roomname, description, exits_to)
create_item(self, roomname, itemname, description, can_be_picked_up)
use_item_to_add_exit(self, itemname, on_item_or_in_room,
source_roomname, target_roomname, description)
use_item_to_create_new_item(self, itemname, on_item_or_in_room, new_itemname,
new_item_description,new_item_can_be_picked_up,description)
set_start_room(self,roomname,start_description)
set_finish_room(self, roomname, finish_description)
I wanted to add some richness by having items that you can and cannot pick up, and actions can create new items as well as exits. To explain how the game mechanic works, check out the following text, which is taken literally from the GPT prompt:
The game consists of rooms and items. The game's goal is to go from the start room (the room in which the player starts) to the finish room (the room that completes the game when the player enters it). The player has to solve puzzles, which amounts to performing a number of actions to get to the finish room. The only available actions are: go to room, pick up item, and use an inventory item on another item. Using an item always has one of two effects: it creates a new item, or it adds an exit from one room to another.
My first prototype was very plain looking, with no graphics and only a few buttons to click, and a lot of errors, like missing rooms, missing or near duplicate items, and unsolvable puzzles. But the basic concept worked! I was very impressed that GPT could do this at all. I wanted to generate graphics to make the game look more interesting, and found a cheap AI image service that could create an image in less than a second (based on Flux Schnell). I asked GPT to also generate a graphical style that is appended to the image prompt, so as to get a sort of unified style throughout each generated game.
With some prompt tinkering and error correction (both on the AI and user interface side) I managed to generate games that are solvable about 60-70% of the time. The games are very simple and linear, and the puzzles often don't make sense. But at least the graphics are great! Sometimes it also comes up with interesting content. For example, I used "Dante's inferno" as a prompt, and it created Dante's nine circles as nine rooms in the game.
But anyway go judge for yourself! :smiley: I guess the real fun of my entry lies in seeing how the AI reacts to the player's prompts! I added a rating system postcompo, so it's possible to rate the games, to make it possible to find back the nicest games (or at least the ones that suck the least). Maybe each game could even be rated on the LD categories :wink:
I am thinking of what my next project will be. What about a shooter with AI generated enemy behaviour? In this case the AI would provide a piece of code that controls each enemy.
* >>> Play the game here <<< *

