Work in Progress – AS3 Settler’s of Catan Board Generator

July 21st, 2009

Every once in a while, a few friends come round to the flat to play board games, the standard game being Settler’s of Catan. Most of us being geeks, at some point in the evening someone usually mentions an idea for a way to integrate some sort of technology into the proceedings, such as a glass topped board game table with LED strips for roads. This is what prompted the following project.

As an exercise in OOP in AS3, I decided to try and recreate the game in flash. This is the first step, the random board generation.

This project randomly generates a Settler’s of Catan board of a set size – complete with number tiles – using AS3 to distribute and position the tiles. The standard board size is 3 along the sides, but the modular nature of the code made it easy to create different sizes, which will be useful when adapting it for expansions.

This project called for a way to randomise an array, something that was a bit simpler in AS2. This is the function I ended up using:

public function randomiseArray(array:Array):Array {
  var num:int=array.length;
  var store:Number;
  while (num--) {
    var randomiser:int=Math.floor(Math.random()*num);
    store=array[num];
    array[num]=array[randomiser];
    array[randomiser]=store;
  }
  return array;
}

The function basically goes through each item in the provided array, and swaps it with another one at random.

Next on the list is adding random ports to the edges of the board!

Leave a Reply