Maze Generation Algorithms - Recursive Backtrack

11 May, 2017

I have recently been playing around with the idea of generating mazes. This is mostly due to the tower defence game I am working on and generating mazes is a very interesting topic. I have decided to start by implementing the Recursive Backtracker algorithm as it seemed both easy to implement and I like the mazes produced by it. By far the best resource I found while learning about mazes was a blog by Jamis Buck and his book “Mazes for Programmers”.


You can see my implementation of the Recursive Backtracker algorithm below.

Maze Seed:


The code is all on my Github

Find best solution to any maze

02 May, 2017

I am currently working on a Tower Defence game with Caleb and Natasha Op’tLand. As part of this game the player will be able to place down towers in such a way that it creates a maze for the enemies to traverse. The enemies should be able to find the best possible solution to any maze that the player creates. The game is based on a 2d grid, A map may look like the following with some towers and rocks blocking the enemy path.


The numbers represent the path the enemies will use to traverse this maze.


The method I have used to solve the maze is by no means the most efficient but it will however always find the best possible solution. This is done by assigning values to tiles beginning with the starting tile and finishing when the end tile has a value assigned. Firstly the starting tile is assigned the value of 1. Tiles adjacent to this are given a value of 2 and then 3 and so on until the end tile is assigned a value.


Values being assigned to tiles until the end tile is reached.

Once the end tile has a value assigned (In this case 12) we can use this information to backtrack from the end tile to find the solution. This is done by looking for tiles adjacent to the end tile with a value of one less (11). This is repeated until the starting tile is found.


The final solution being mapped out


Procedurally generating a solar system

27 April, 2017

Procedural generation has always been of interest to me, and solar systems are cool. So I decided to explore procedural generation by procedurally generating a solar system! Below is a solar system that has been generated based on a pseudo random seed. Below is an example of a generates Solar System. Refresh the page for a new randomly generated Solar System! click Here for a full screen version that is not scaled down and looks nicer!


To procedurally generate anything we first need a seed to base our generation on. We will seed the random number generation to our seed. Once we have a seed the rest of the generation will be based on this. This means that the same seed will always generate the exact same solar system, so if there is a solar system that is particularly nice the seed can be saved to re-generate the exact same solar system at any given time. I have written this in HTML5 using the phaser framework and thus my code to generate and set a random seed is as follows:

Math.seed = Math.floor(Math.random() * (89898989898989898989 - 29898989898989898989 + 1)) + 29898989898989898989;

Where Math.seed is the value that we will use as our unique seed.

Math.randomSeed = function(max, min) {
    max = max || 1;
    min = min || 0;
    Math.seed = (Math.seed * 9301 + 49297) % 233280;
    var rnd = Math.seed / 233280;
    return min + rnd * (max - min);

Math.randomSeed is the random function that we will use to generate pseudo random numbers based on the seed generated and stored in Math.seed. Of particular note is:

Math.seed = (Math.seed * 9301 + 49297) % 233280;

This is a general math equation to generate pseudo random numbers, more info on this is available at:

Once the seed is generate we can begin to generate our solar system. Our solar system consists of 4 elements: The sun, Planets, Moons and Stars. Each of these are generated based on the seed. Some things like the planets are affected by the sun that is generated. Due to this we must generate the solar system in the following order:
Stars – only affected by the seed
Sun – only affected by the seed
Planets – Affected by the heat of the sun and distance from sun. More on this later
Moons – Affected by the distance from the planet and the climate of the planet
We will look at how each element is generated.


Generating the stars

The stars are probably the easiest to generate as the stars are based on per-defined images. There are 9 possible images that will be used for the stars, they are all similar with a slightly different layout:


The image to be used is chosen at random based on the seed:

  this.type = parseInt(Math.randomSeed(1,10));
  this.sprite = game.add.sprite(960, 960, 'stars'+ this.type);

Once one of the 9 images is chosen we set a random rotation for it in 90 degree intervals.

  var rotation = parseInt(Math.randomSeed(1,5));
  this.sprite.angle = rotation*90;

In doing this we get a total of 36 different possibilities for the layout of the stars as each of the 9 images have 4 different possible rotations.


Generating the Sun

The Sun is the core of the solar system and will have an effect of every planet and moon that is generated. To generate the Sun the first thing we need to do is define all the properties that a sun has. For this project I decided a sun was determined by its Type, Size, Heat and Sprite. In this case Type is an arbitrary value to add some extra variation. Size is pseudo random and Heat is based on both the Type and Size of the sun. These 3 values are set using our random function defined earlier.

	this.type = parseInt(Math.randomSeed(1,6));
	this.size = parseInt(Math.randomSeed(1,9));
	this.heat = (this.size*this.type*5)+30;

The last thing we need to do is set a sprite for the sun. The sun much like the stars have a pre-defined set of images that can be used:


However the sprite that is chosen to represent the sun is based on the sun type and as a result also corresponds to the heat of the sun:

this.sprite = game.add.sprite(10, 10, 'sun'+this.type);


Generating the planets

Much like the sun to generate planets we must first determine all the properties that make up a planet. I decided each planet should have a Size, Distance, Water Level, Speed, Temperature, Climate, Name and Sprite. Each value is determined based on the Seed and also often the Sun that has been generated.

The Size, Distance and Water Level are based only on the Seed:

	this.size = parseInt(Math.randomSeed(1,4));
	this.distance = parseInt(Math.randomSeed(3,9));
	this.waterLevel = parseInt(Math.randomSeed(1,10));

The Speed is based on both the Seed and Distance:

	this.speed = (parseInt(Math.randomSeed(10,25)))-this.distance;

The planets temperature is base on the Seed, Heat of the Sun and Distance from the sun:

	this.temp = this.sunHeat – (this.distance*8);

The climate is based on both the Water Level and Temperature of the planet. I wrote a separate function to work out the climate of the planets based on these values.

planetClass.prototype.getClimate = function(water, temp){
	var climate;
	if(water < 4){
		if(temp < 1){climate = "plains"}
		else if(temp < 41){climate = "desert"}
		else{climate = "fire"}
	}else if(water < 7){
		if(temp < 1){climate = "earth"}
		else if(temp < 41){climate = "earth"}
		else{climate = "tropic"}
		if(temp < 1){climate = "ice"}
		else if(temp < 41){climate = "tropic"}
		else{climate = "gas"}
	return climate;

Each planet should have a name to make is more unique. Each name is based on the Seed and a pre-defined list of names that are available. Depending on the Seed a random name is chosen and a random number added to the name.

planetNames = ["Zeus","Hera","Poseidon","Demeter","Ares","Athena","Apollo","Artemis","Hephaestus","Aphrodite",
"Hermes","Dionysus","Hades","Hypnos","Nike","Janus","Nemesis","Iris","Hecate","Tyche"] = parseInt(Math.randomSeed(0,20)); = planetNames[] + parseInt(Math.randomSeed(0,200));

The last thing to do is set an appropriate sprite for the planets. Again this is chosen from a pre-defined selection of planet sprites.


The sprite that is chosen for the planet is a direct result of the climate of the planet:

this.sprite = game.add.sprite(10, 10, this.climate);


Generating the Moons

Again the generate the moons we need to define the properties that a moon has. I decided each moon needed a Size, Speed of Orbit, Type, Distance and Water Level.

The Size, Speed of Orbit and Type are directly related to the Seed:

	this.moonSize = parseInt(Math.randomSeed(1, 4));
	this.speed = parseInt(Math.randomSeed(5, 10));
	this.type = parseInt(Math.randomSeed(1,4));

The distance is based on the distance of the moon from the sun.
The Water Level is based on the Water Level of the planet

The Sprite for the moons is chosen from the same selection of sprites as the planets they are however scaled down. The sprite chosen for the moons directly corresponds to the Type of moon:

		case 1: this.sprite = game.add.sprite(10, 10, 'desert'); break;
		case 2: this.sprite = game.add.sprite(10, 10, 'fire'); break;
		case 3: this.sprite = game.add.sprite(10, 10, 'plains'); break;


Adding an AI to battle for control of the Solar System Generated

 For a little bit of extra fun I created a basic AI that will battle for control over the generated Solar system. This becomes Red vs Green where each AI is assigned a starting planet. Each planet is given a “ship production rate” to generate ships. The AI will send ships from planets it owns to try capture planets it does not own in an attempt to control the entire Solar System.


The full source for this project is available on my Github at:



SCCM PowerShell Task Sequence GUI

07 March, 2017

Playing around with our Task Sequences in SCCM I came to the realization that we have numerous post install tasks for optional software when an Imaged PC is for a particular department or entity. This is due to different departments having different software requirements. I started toying around with the idea of a software selection GUI as part of the Task Sequence that will allow customization of post install software in the aim to make all deployments ‘one touch’.

After some research and work I came up with a basic GUI with a few customization's:


However, this is still limited and does not cover all of our use cases, so we are still left with some post install tasks. After some more work I came up with the following ‘final’ GUI:


From this GUI we are able to choose all the combinations of required software for all departments and entities. No more post install tasks for any PC’s.

I had to do a few things to get this working as desired. But at the core of it, each of the tick boxes sets an MDT Task Sequence Variable. The variable weather ticked or not determines if the software installation step should proceed.

MDT Task Sequence Variables
The task sequence itself has some additional steps to create the variables. Each variable requires a separate step for the variable creation. I found the variables needed to be created in the task sequence before the PowerShell script that sets the variables values can be run.


All of the variable are set to False when created in the task sequence. The PowerShell script will later set the ones that are ticked to True.



Conditional Application Installations
We have the requirement that some applications are installed on every PC that we image, these applications are installed regardless of the options chosen. For the conditional application installations, I have created a separate step for each one.


Each of these steps simply installs a single application.


Under options I have set the condition that the Task Sequence Step only run if the corresponding variable is set to True.



The PowerShell Script
Creating GUI’s in PowerShell is tedious and annoying but there is plenty of information on how to do that so I will be glossing over the GUI creation part. The important part of the script is retrieving the value from the check box and injecting it into the Task Sequence variable. A minimal example how this works would be:

    #Get Variable from Form
    $installPDF = $pdfCheck.Checked #where $pdfCheck is the checkbox

    #set variable in the task sequence
    $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
    $TSEnv.Value("installPDFAnnotator") = "$($installPDF)"

The script needs to be made into an SCCM Package so that we can run the script from the Task Sequence. The source contents for the package should include the script to be run, ServiceUI.exe and any assets required by the script. In my case the company logo.


The package is nothing special, you only need to set the source files for it. And distribute it the required Distribution Points.


Incorporating the script into the task sequence requires adding a step ‘General > Run Command Line’. The command line step should look similar to the following:


The two main things to note here is the command line is pointing to the PowerShell script that is part of the package and that the package is selected. You just need to make sure that you declare all the MDT Task Sequence variables before running the PowerShell step “Prompt For Image Configuration”


And that should be it!

Office 365 Shared Mailbox Sent Items Folder

20 February, 2017

When creating a shared mailbox in Office 365 the default behaviour for items sent from this mailbox is odd. When a user who has access to the shared mailbox sends an item from or on behalf of the mailbox the item goes into the users ‘sent items’ folder. The sent item will not appear in the ‘sent items’ folder of the shared mailbox.

There is no obvious way to configure items sent from a shared mailbox to appear in the ‘sent items’ folder of the shared mailbox. This however can be configured quite easily from PowerShell. To do this you will first need to establish an Office 365 session in PowerShell. To establish a session:

Get Credentials

$cred = get-credential

Create a session with using the saved credentials

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $cred -Authentication Basic -AllowRedirection 

Import the session

Import-PSSession $session -AllowClobber 

Once you have established the connection to Office 365 you can configure the ‘sent items’ behaviour or shared mailboxes.
To configure emails that are Sent As:

set-mailbox <mailbox name> -MessageCopyForSentAsEnabled $True

To configure emails that are sent of behalf of:

set-mailbox <mailbox name> -MessageCopyForSendOnBehalfEnabled $True

If you later want to stop the shared mailbox’s from saving sent items into their own ‘sent items’ folder, you can simple set the values in the commands above to $false instead of $true.

Home ← Older posts