Skip to content

#PROCJAM PuzzleScript + Tracery Rules

Fri 10th November 2017

In a previous post I spoke a little bit about the inspiration behind the thing I’m working on for #PROCJAM 2017. To summarise, I am taking a tool called Tracery, which lets you define grammars for text and generate random text from them, and attempting to use it to generate some code in a language called PuzzleScript, which makes 2D, Sokoban-style games.

PuzzleScript character definition

PuzzleScript has a nice little visual syntax for defining objects within the game, which could be a nice source of fun procedural content generation (PCG) using Tracery, but I feel like art and characters are quite commonly tackled problems in the PCG world. I am really intrigued by the idea of generating the rules that underpin a game or puzzle, to better understand the challenges of making those rules coherent and making levels suitable for those rules. So that’s what I’m going to attempt for #PROCJAM!

imag0031359827097.jpgOne of the things I asked my Masters student to do, when he was working on a similar sort of task, was to do a brief survey of existing PuzzleScript games to see the variety of rules that have been used by authors. From that work, he identified some categories, such as the basic push rule, position swapping, objects that slide, objects that attachgrow or chase the player. However, from reviewing this work and attempting a small survey myself, I realise the scale of the task! Not only are there over 90 games in the PuzzleScript gallery, but many have subverted the PuzzleScript form and created complex combinations of rules that have subtle and unique meanings in the context of that particular game. Whilst that is exciting, and perhaps a hint that making interesting PuzzleScript games requires more than just the basic types of rules, it also helps me scope what I want to do here. I am going to make this about exploring generation of rules for Sokoban-style, block-pushing puzzles and see where I get. After I have something working, it will hopefully give me some new questions regarding level-generation and how to combine rules that thematically fit together.

Rule Format

Screenshot 2017-11-09 15.42.24I spent a little time getting a boilerplate Tracery going. It’s here in this commit on Github. It took me a few minutes to realise there’s a Tracery2 branch, and that’s the right and stable version to use! The other trick I discovered was that to escape square brackets (which are pretty essential for PuzzleScript rules), you must use a double slash in Tracery: \\[ and \\].

For coming up with the range of possible rules I might try to generate, I brainstormed a little to come with potential variations. I also read the PuzzleScript documentation about rules and directions, which led me to realise that perhaps the right approach is to take the documented syntax and codify it in Tracery to generate a bunch of rules. This will certainly result in a set of rules that don’t interact in any sensible way, but let’s go with it and see what we get.

The generator at this commit generates 3 rules, mixed between the objects and handling different events in different ways for some randomly selected directions. For example:

(1) RIGHT [ Player | Crate ] -> [ DOWN Player | DOWN Crate ]
(2) LEFT [ UP Player | Badger ] -> [ LEFT Player | LEFT Badger ]
(3) UP [ RIGHT Player | Crate ] -> [ UP Player | UP Crate ]


I think the immediate lesson here is that whatever the player presses should be the direction the player moves in (but the collided block might do something different) (except maybe if the player is deflecting or bouncing off the block?) (yes that’s 3 bracketed thoughts in a row – where are my footnotes, WordPress?). I quite like that, once the system generates more rules, there can be a different rule  for each direction. Perhaps it should use Horizontal or Vertical, to have some consistency, but maybe not. I can imagine generating a rule where an object can be pushed in one direction, pulled in another, but nothing else. But of course we’re not here to think about specific instances 😉

Next I’m going to expand upon these rules a little bit, maybe come up with a few linked rules (i.e. if one rule does X, it’s combined with a rule that does Y), and have them as potential branches in the grammar. I would also quite like to integrate this into a fork of the PuzzleScript source, so that I can generate new rules from within the editor and not have to copy and paste them in!

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: