Waxing Lyrical on Pathfinding

I’ve been attending and giving talks at the Software Craftmanship conference at Bletchley Park for a couple of years now. I’ve always found the crowd there engaging and great to hang out with, and I’d encourage you to come along if you’re not doing much on June 14th. There are still a few tickets left if you’re quick.

My talk proposal: Pathfinding Peril

This year my talk proposal is about pathfinding, a subject rather close to my heart since I started building a game. Finding the shortest path through a connected graph is a complex problem, and one which has a number of very useful applications, not just in the game sector.

Thankfully there are some efficient algorithms out there which solve it well. The aim of my session will be to teach the popular A-Star pathfinding algorithm, along with the factors to consider when choosing appropriate algorithm weights to make the implementation efficient.

A-star can be written in any language, but a simple (untested, probably buggy) version might look like this:

    def find(goal)
      closed_set = []
      open_set = [ start_node ]
      came_from = {}
      while(!open_set.empty)
        current = open_set.sort{|node| node.estimated_score }.first
        return reconstruct_path(came_from, goal) if (current == goal)

        open_set -= [current]
        closed_set += [current]
        current.neighbours.each do |neighbour|
          next if closed_set.include?(neighbour)
          possible_score = best_score[current] + current.cost_to(neighbour)
          if !open_set.include?(neighbour) || possible_score < node.running_score
            open_set += [neighbour]
            came_from[neighbour] = current
            neighbour.running_score = possible_score
            neighbour.estimated_score = neighbour.running_score + neighbour.cost_to(goal)
          end
        end
      end
      return 'failed'
    end

The session will last a couple of hours. I’ll take you through the basic A-Star implementation in the first 30 minutes of the session, and we’ll spend some time getting that coded up in the second 30 minutes. After a break, we’ll be running a tournament for an hour using Matt Wynne’s Robot Tournament engine. Your robot will be one of two characters in a maze, and the idea is to find the exit as soon as possible without being eaten by the minotaur that roams randomly around it.

You’ll get points for exiting the maze within a certain timeframe, exiting first, and simply avoiding being eaten! If I get time, I’ll write a basic ruby gem which allows you to parse the maze presented on stdin into nodes with connections.

We’ll run around 20 minute iterations, but probably reset the score every time so that the final score is the one that matters. It should be lots of fun!

What do you think of the session idea? How could I improve it?

Share this article

More on: code

Your Code Is A Liability
The Sol Trader Christmas Eve update: moddable missions
New Sol Trader beta: the science of blame and unforgiveness
Modelling opinions and prejudices in Sol Trader
Sol Trader combat preview
How to add live code reload to your game
Why I wrote Sol Trader's GUI code from scratch
The difference review and planning makes to indie development
How to quickly add bloom to your game engine
The huge difference a good Entity System could make to your game
How tone of voice works in Sol Trader's dialogue system
How dialogue works in Sol Trader
How face generation works in Sol Trader
How I'm using Proxemics in Sol Trader's game design
Why I ditched all the build tools in favour of a simple script
Your abstractions are a liability
How I doubled the speed of my game by giving up on C++
Why video game coders don't use TDD, and why it matters
7 things I've learnt in 3 years coding my first indie game
How not to check in temporary code
The toolchain of dreams
Extreme isolation part 3: coding a CRUD app (with full example)
Extreme isolation part 2: separate the domain from the changes
Rack::Usermanual - Cucumber features as in-app user manual
Extreme isolation in web apps: part 1
BDD without tools: testing shell script
Dependency injection != Inversion of Control
Cucumber: keeping the build passing
Your framework is a liability
Never leave a failing test
The power of good naming
Kickstart your team on BDD
A fresh take on DCI with C++ (with example)
On coding defensively
Sol Trader: on lighting
Effective bloom in OpenGL for Sol Trader
Switching Sol Trader from Ruby to C++: one week on
Why I switched from Ruby back to C++
Introducing Sol Trader
A cache-busting http server script in ruby
Feature writing: multiple actors
How I'm testing iPhone apps: part 2
How I'm testing iPhone apps: part 1
Your tests are lying to you
Kanogo: vapourware to beta in 24 hours
Pin in the map: customisable pin icons
e-petitions: handling traffic
Work with me
e-petitions: deconstructed
Lean code: slides and feedback
Pomodoros help you refactor
Call for coders: Children's Future International
How to test your node.js app
Every Ash Cloud Has A Silver Lining
Five things I learnt from Corey Haines
Archivey the Robot
Introducing Pushy - github notifications to google wave

More on: conference

Sol Trader will be at EGX in September!
Slides for "Leading software teams well"
Leancamp Report

More on: fun

Introducing Card Pirates
Snakes and Ladders Kata