Apr 182014
 

I recently dug up my university dissertation and related code, and was surprised that it still runs and isn’t as bad as I feared. It was pretty interesting at the time so I thought I’d share. It was a good call to choose a project in the games/puzzle area, as I’m pretty sure that helped me get my job in the games industry a few months later!

Full report, and running the code

RollingBlock.pdf – this is the full dissertation I submitted, in case you’re interested in reading about this in more depth.

RollingBlock.zip – this is the full source and compiled code, written in Java. I’ve not recompiled it since 2002 and some of the formatting seems a bit messed up, but it still runs (please don’t judge the code quality, this was my first reasonable sized coding project!). There is the full editor program, plus a variant on the player for puzzles with multiple moveable blocks.

To run the Editor program you need the Java JRE installed. If java.exe is in your path then editor.bat should launch the program, otherwise you’ll need to put the full path in.

Rolling Block Puzzles

The idea of the ‘rolling block’ puzzle is to roll a non-cube block (2×1 in the simplest case) through a grid-based maze so it ends up exactly covering the goal. Because the block isn’t square it takes up more room in some orientations that others, and the puzzle involves shuffling the block into the right orientation to get to where you want to go.

Here is an example puzzle, where you need to roll the blue block so that it stands upright on the yellow goal square. So the only possible first move is up-left, because there isn’t enough room to roll in the other directions:

Example of a rolling block puzzleThis is a type of multi-state, or concealed path, maze. Underneath you’re navigating a state graph of moves from the start point to the end point, but the shape of the block, and the moves it allows, means that the actual path to the solution can’t easily be seen. There are only 53 empty squares on the grid but there are 125 reachable maze states, and the shortest solution requires 32 moves (solution at the bottom).

Automatic maze generation

These types of puzzles are very hard to design unassisted, because each block added or removed impacts the state graph in many different places. Some clever people design these things by hand, but us mere mortals can use a computer.

The first thing we need is a solver. This does an exhaustive breadth-first search of the maze and builds a graph of all states and the transitions between them. In each state there are at most four legal moves so it checks if each destination state is a duplicate, add a new node if it isn’t, and add an edge between the two nodes. Here is a very small 5×5 maze:

rb5x5And this is the state graph a solver will come up with:

rb5x5graph

The numbers are how many moves are required to reach each state, so zero is the start position and 18 is the goal position (the colour coding is based on branches and dead ends). So you can see that even a tiny 5×5 maze with three obstacle blocks has quite a complex state graph.

Measuring puzzle quality

To generate good new puzzles, we have to be able to tell the difference between a good puzzle and a bad one. What makes a puzzle ‘good’ is a hard thing to pin down, but we can pull out a few ideas such as it having a long solution, many dead ends, looking deceptively simple etc. For our purposes though we need to come up with a single score for the quality of a given puzzle, such that a higher score means the layout is ‘better’ in some sense.

One approach is to analyse the graph that the solver produced, and score it using a weighted set of criteria. The criteria I used are:

  • Number of nodes – more states means a more complex puzzle
  • Solution length – longer puzzles tend to be harder
  • Number of branches – choices and dead ends are what make the puzzle interesting
  • Number of blocks – give this a negative weight to prefer simpler looking puzzles with less obstacles
  • Number of turns – requiring more direction changes can be a more interesting solution
  • Average loop length – large loops in the graph make it less obvious when you’re on the right path

Different weights can be assigned here depending on what characteristics you want in your generated puzzle.

rb_8x8C

A more interesting block – 60 move solution

Genetic algorithms

So now we can give a score to a specific puzzle, but we need to use this to come up with the best puzzle possible. For this we can use a type of genetic algorithm.

Genetic algorithms are based on the same principles as evolution in the real world: using randomness to slowly evolve towards an optimal solution. The idea is to start with a solution (any solution), and then randomly modify it a bit. If the new solution is better than the old one, keep it, otherwise throw it away. Repeat this process many times, each time starting with the best solution you’ve found so far. To tell if a solution is better than the previous one we apply a fitness function to see if it survives to pass on its ‘genes’ (or instead gets eaten by bears). After a while, you can stop the process and take the best solution found so far as your result. Despite what creationists may tell you, order can result from randomness (plus a fitness function).

In the case of a rolling block puzzle we start with either an empty board, or one with a few random blocks, and a mutation rate (maybe 5%). Each iteration we check every grid square to see if it ‘mutates’ (toggles between obstacle and empty). The fitness function is the puzzle score described earlier. If the score is higher or equal we keep it. Then just keep going as long as you want.

And that’s pretty much all you need to generate new puzzles. The key is the fitness function – the better it fits our subjective opinion of “this is a good puzzle”, the better the generated results will be. I’m sure that there are much better fitness functions out there but this one works well enough.

Here’s a video of it in action.

References

Robert Abbott’s Logic Mazes page

My multi-level puzzle applet hosted on Logic Mazes (probably won’t run with today’s security settings)

Erich Friedman’s designs

A bunch of mobile games using a similar puzzle

 

Example solution (L is up-left): LURDRDRDDDLLLULDRRRRULDLLLUUULUU

Apr 012014
 

Time for an epic game roundup post.

LAN parties, for me, and the best way to play games. Getting a load of friends together in the same room for some quality gaming time is great. There is just one recurring problem: finding games that are enjoyable for everyone to play. Ideally we all play the same thing, and the preference is for something co-operative, or at least team-based, to smooth out skill differences. However I’ve found that multiplayer games fall into one of a few categories:

  1. AAA, easy to play, polished and enjoyable experiences. That generally cost £20-40, which is a lot of money for something that will likely only get played for a couple of hours.
  2. Free to play (in the sense of actually being a reasonably fun game to play without having to pay anything). Except they usually require 5-10 hours of playing/grinding to get going.
  3. Complex strategy games. Which have a massive learning curve and require tens of hours of play to get good at.
  4. Cheap, fun, indie games. Where tutorials were last on the ever growing list of features, making them inaccessible without substantial background reading.

I’ve tried a lot of games at LANs over the years, so here’s a summary of a few old favourites along with some recent attempts:

Dawn of War

Dawn of War is a Warhammer 40K RTS game, released in 2004. It’s the go-to game for one of my groups, who have been playing it (and the various expansions) since release. It’s a Category 3 (along with almost every RTS), but luckily we all had loads of free time back then are were fans of the licence, and it’s given us years of gaming in return.

Pros: Flexible player numbers, 2-4 co-op play versus AI (stretching to 5 vs 3 AI on the hardest difficulty). Runs on any system.

Cons: It’s showing its age. And frankly it’s getting a bit repetitive after nine years.

dow

Wolfenstein: Enemy Territory

I wrote about Enemy Territory a while back. It’s a team objective-based FPS from 2005, and is the other old favourite of the Dawn of War brigade. The game has always been available for free, and is great fun if you can get at least six players. I would put this in Category 4, as being an unfinished game there is no help for new players (each map requires learning by heart because there is no on-screen information about where to go and what to do).

Pros: Supports large numbers of players (6-20+). Free. Runs on any system.

Cons: Steep learning curve. And again, we’ve been playing it forever.

wolf_et

Left 4 Dead 1 & 2

I’m sure you all know this one, but the Left 4 Dead games are zombie survival shooters. They’re great co-op games if you have exactly four players and even better in versus mode if you have exactly eight players. This actually avoids all of the problem categories, so gets played most times (or at least is the backup game).

Pros: Frequently on sale for a couple of quid.

Cons: Best with exactly 4 or 8 players.

l4d2

Diablo 3

Diablo 3 is an isometric dungeon crawler where a bunch of you run around killing hordes of monsters and grabbing loot. This sounded like the perfect LAN game – highly polished, four-player co-op, easily accessible and a challenge requiring some interesting teamwork. It’s a Category 1 game, but four of use bought it at release and sat down one evening to play through. Unfortunately it wasn’t to be. The game was just too easy, unless you put in 50+ hours of repeated playthroughs to grind up through the difficulty levels. Even the bosses seemed to fall within seconds. I know it was meant to be accessible, and it certainly is, but some kind of configurable difficulty option could have saved this game.

I believe that the recently released Reaper of Souls expansion fixes most of these issues so it may be worth another look, but it’s not cheap.

Pros: Requires no thought or skill. Very accessible.

Cons: Requires no thought or skill. Far too easy when starting from scratch. Expensive.

diablo3

MechWarrior Online

Everyone loves giant hulking robots, and when we came across MechWarrior Online recently it sounded great: a team-based, slower paced, tactical game with lots of room for strategy and less reliance on twitch skills. Unfortunately everything about the game itself conspired to make this as difficult as possible. The frontend UI is possibly the worst in any game ever (may be a slight exaggeration, but it’s really terrible), it’s a definite Category 2 in that you need to put a few hours in before you can buy and customise your own Mech (which is when the game gets fun), and the community was pretty hostile to new players.

The worst part though was the team options – each match is a fixed 12v12, but the allowable team sizes are 2, 3, 4 and 12. We got around this with our group of seven by forming two groups and hitting Start at the same time, which mostly got us into the same game, but that may just be an indicator of the number of active players. I understand that the point of the team size restriction is to allow the matchmaker to make fairer games, but I’ll stick my neck out and say that actually being able to play with your friends is much more important than slightly fairer matches. Having said that I’ve played the game a fair bit solo, and I quite like it.

Pros: Free. Fun for small groups of experienced players.

Cons: Restrictive group sizes. Not at all friendly to completely new players.

mwo

Terraria

After failing with MechWarrior we found out that most of us had picked up Terraria in the Steam sales and never played it. Terraria is basically 2D Minecraft, where you dig, build things and fight monsters. It’s a Category 4 with no explanation of how to play, but luckily we had a couple of experienced players to show us. Exploring caves in a group is pretty fun for an hour or so, but it got samey quite quickly. It’s not a bad way to break up and evening though.

Pros: Freeform drop-in/drop-out gameplay. Cheap.

Cons: No real point to the game. Can quickly run out of things to do.

terraria

Various Call of Duty/Battlefield games

I’ll lump all the more recent Call of Duty and Battlefield games together, as they’re all the same from the point of view of a LAN. You can’t fault the technical quality of the multiplayer modes in any of these games – very polished, good fun, progression systems to keep you playing, definite Category 1 games. But it’s no secret that we’re getting older, and our 30+ year old reflexes just can’t keep up with the teenagers. Since the move to online-only multiplayer, these types of games have become more frustrating. The inclusion of the grinding aspects of free-to-play to unlock decent equipment further puts me off (I gave up on Battlefield 3 when it came out because I rarely got more than a couple of kills per match, although I hear the equipment is supposed to be more balanced in Battlefield 4).

Pros: High quality experiences. Flexible teams. They’re shooters so minimal learning required.

Cons: Frustrating if you don’t have pro-gamer skills. Even the old games still command high prices.

Battlefield 2

Taking a step backwards, Battlefield 2 was a great successes. It’s old, but still looks acceptable on modern PCs. The main bonus is that it’s from an era of local LAN play and bots, which caters perfectly to our preference for cooperative experiences for a range of skill levels. I think we settled on 8 humans vs 14 bots, tweaking the difficulty level until we got close matches. It’s got guns, tanks, comedy helicopters (“Who wants to be my gunner?” – “HELL NO I value my life”), and introduced Commander mode where wannabe-Eisenhowers can set objectives and airdrop vehicles and supplies.

Maybe I’m just not that into competitive gaming but local multiplayer against AI frequently gives the best experiences, where everyone succeeds or fails together. And when you fail you work out what went wrong and have another go. Very satisfying when you finally succeed.

Pros: Local multiplayer. Flexible numbers. Highly configurable difficulty level.

Cons: Starting to show its age.

battlefield2