Jan 05

I thought I’d start off the new year with something a little different and explore artificial life simulators (ALS) from a software perspective. The whole “artificial life” field is a bit difficult to define and classify and can range from modelling biological systems (“real” artificial life research) to computer game AI (which may not be terribly realistic and relevant to the academic community, but is definitely more fun). There’s plenty of information about this field and I’m not going to try to approach it from a rigorous scientific perspective, but rather take an ab initio approach and build on a simple platform. If you have a professional interest in artificial life then you’re probably not going to get much out of this because I’m going to take a fun, hands on approach and concentrate more on creating a platform for observing emergent behaviour, rather than simulating a realistic biological system. I’m not a big fan of diving into the deep end of a topic and prefer an iterative approach so that you don’t get lost in the detail.

This first post will just cover the groundwork of the approach I’m going to take and introduce the basic concepts. Obviously, the simulator will be realized as software and I’ll be using C#/.NET to develop the simulator and MATLAB to model concepts, if required. I’m not going to cover every step of developing the simulator software (that’s boring), but I’ll make the source code available each step of the way.

So, what exactly is an artificial life simulator? In a nutshell, it’s a time dependant closed system to observe the interaction of simulated organisms with a simulated environment and each other. The main thing to take from this is that you can’t study the “organisms” independently of their environment (you can study a simulated environment independently , but that’s just physics and chemistry). The organisms and their environment both have properties or characteristics that govern their interaction and determines the “fitness” of an organism within it’s environment. This “fitness” determines the survivability of the organism and its reproductive success, with the result being that the more fit individuals survive longer and are more likely to reproduce. Organisms can also adapt (or evolve) by mutating their properties to increase their environmental fitness (a change may also decrease their fitness, as well). In most cases, you’ll also want to simulate a non-homogeneous environment that changes over time to see how a colony of organisms evolves spatially over time. A static environment will result in an organism evolving towards a steady state, which is kind of boring (but it’s a good starting point).

Now that we have that behind us, let’s be a little bit more specific about what exactly the environments and organisms consist of.


We normally think of our environment as whatever makes up our immediate surroundings (what we can see), but this is far too complicated for a simulations because of the huge number of interacting environmental variables and the fact that our environment is open (unbounded). The simplest useful artificial environment is a 2D box with a single property (such as ambient temperature) that will determine the survivability of the contained organisms (which can only tolerate a certain temperature range). We can improve the realism of this environment by allowing the property to vary with time and location within the environment. We can also up the environment to 3D, but this isn’t a fundamental change and a 2D environment is perfectly good (and easier to visualize). You can easily add other environmental properties to simulate oxygen levels, toxin levels, pressure levels, obstacles etc., all of which have some effect on the survivability of the organisms. We’ll keep revisiting the environment to add new features as we develop the simulator.


The organisms are a little more complicated than the environment, but are still conceptually simple. They simply consist of a set of properties or characteristics that determine their survivability within their environment. In the simple case above, our organisms just have a temperature range that they can tolerate. Any temperature outside of that range will kill the organism. For an organism to adapt or do anything interesting it will need to reproduce and pass on it’s genome (properties) to its offspring. The simplest case is simple cloning, with the occasional change in property values (mutation) to allow the organism to possibly better adapt to the environment. For now we’ll just consider point organisms (that have no “size”), but later we’ll add physical boundaries to the organisms so that we can model population densities and the effects of overcrowding and minimum viable population sizes.

If this all sounds like a gross oversimplification to you then you’d be very right; it is a gross oversimplification of everything, but that’s the whole point of a simulation. What we’re trying to do is strip away all “unnecessary” features of the environment and organisms and just focus on those of interest. Even the features that we do retain are greatly simplified. No real organism has a single gene that encodes for “survivable temperature range”, but rather a whole host of physical characteristics determine the temperature range that an organism can withstand. Some animals have fat, others have fur, some have “antifreeze” compounds in their body fluids, humans have evolved to be able to change their environment, most mobile multicellular organisms can move to more hospitable environments etc.

So far we’ve covered the basic concepts behind an artificial life simulator but it’s not clear how things play out from here. What we’ll do now is walk through a few simple thought-experiments (with charts and tables) to explore this simple environment/organism interaction that we’ve created. We’ll get to the actual software simulator later, once we’ve thought through this a bit more.

Thought-Experiment 1

For this simple thought-experiment we’ll consider a box environment of arbitrary size (all the environments in this part will be of arbitrary size, so I won’t specify it each time) that has an ambient temperature that falls with the range 0 to 100 (arbitrary units, that will usually be represented in software as real numbers in the range 0.0 to 1.0). The organism will have a survivable temperature range of 20 to 35 temperature units. Based on this, we can come up with the following three scenarios:

Environmental Temperature Organism Fitness (%)
< 20 0
20 – 35 100
> 35 0


We can see from the above table that the organisms have complete fitness/survivability within the specified survival temperature range and will die immediately outside of that range. The fact that the organism will die immediately is a bit of a problem and we’ll revisit it in a later thought-experiment. It is also implied that the fitness of the organism is 100% for all temperatures within the survivable range.

Thought-Experiment 2

In this thought-experiment we’ll keep the environment the same but we’ll play a bit with the whole concept of fitness as a function of temperature. I didn’t spell it out previously, but here’s a plot of fitness as a function of temperature for our organism:


It’s obvious from this that the function isn’t continuous, which is generally a bad thing when it comes to artificial life simulators. The reason it’s bad (apart from a mathematical perspective) is that it doesn’t model real life scenarios very well. Living organisms don’t happily go about their activities within their preferred temperature range and suddenly keel over and die immediately when the critical temperature boundaries are crossed. In reality, their fitness decreases to zero as the temperature limits are approached and various other properties are dependent on the temperature related fitness (such as motility and reproductive success. i.e. the organism might survive at a higher temperature but not be able to reproduce).

This little though-experiment has given us a lot more insight into the nature of our simple ALS and we can make the following observations:

  • Each organism property contributes to the overall fitness of the organism (not necessarily an equal contribution).
  • The “survivability” of the organism is directly proportional to the overall fitness.
  • We need a way of determining whether or not the organism should be alive or dead at any given time.
  • We somehow need to factor reproduction into this model, possibly as a function of the overall fitness (we don’t know enough to consider mutations yet).
  • The fitness contribution is a function of the property value and should most likely be a continuous function and not necessarily linear.
  • An organisms properties may be dependent on each other (due to their contribution to the overall fitness of the organism). i.e. Some properties may be derived from others.
  • Environmental properties affect a property’s fitness contribution.
  • Property values should be real numbers in the ranges –1.0 to +1.0, –1.0 to 0.0 or 0.0 to +1.0, since this makes sense for continuous non-linear functions.

In the next part of this series we’ll look at these observations in more detail and come up with a more realistic model for our static temperature dependant ALS and start thinking about how to build a software simulator.

written by Paul Mason \\ tags:

Nov 01

I suppose it’s inevitable that I’ll weigh in on this whole “Delphi is no good for teaching programming at schools” hissy fit that is getting the South African developer community’s pee into a froth.  Before I go any further though, I want to make it clear that I don’t think that Delphi is a particularly good choice, or any other programming language for that matter.  That’s probably because I don’t believe that the purpose of school (or even university) level programming instruction is meant to produce drones who are proficient in the particular programming language flavour of the month, but rather people that have the necessary critical thinking skills that will allow them to fill whatever industry position required.  In other words, if you still don’t get it, I don’t think that Delphi is the right choice (but it’s not wrong) – I’m simply attacking the response of the so-called “professional” software industry in this country.

Just a little background first.  This whole little tantrum started with the Department of Basic Education (BASIC, people, BASIC) announcing that they will be dropping Java in favour of Delphi for teaching programming at schools (and some stuff about Microsoft Office that I don’t care about).  I think the whole thing got rolling with a post by Derek Keats which was also, coincidently, the apparent start of so-call experts commenting on things that they don’t seem to know much about.  It will take me ages to refute every inaccuracy in Derek’s post, but the first one is perhaps the most telling:

“Delphi, a language that is not in general use today and is basically Pascal with a Graphical User Interface”

Come on!  Get off your butt and actually make an attempt to actually research things first, you are an “academic”, after all.  Here, go read this, and stop talking rubbish.  Another little gem is “The decision to implement Delphi is a bit like mandating Latin as the language for literature”.  Yet another stupid argument, which should be correctly phrased as “The decision to implement Delphi is a bit like mandating Latin as the language for teaching ENGLISH”.  Yes folks, the whole point is to teach PROGRAMMING, not Delphi/Java/C++/etc.  His argument for not using Delphi because it’s not generally used in industry would be a whole lot more credible if it wasn’t followed by arguing against the use of Microsoft Office (which is the industry standard) in favour of an open source alternative.  So, it’s fine to teach concepts when it comes to word processors etc. but you can’t do that when it comes to programming?  Not to come across as insulting or elitist, but I’m really glad I decided not to go into academia, it would have addled my brain.

Of course, not to be outdone, somebody had to go compare teaching Delphi to genocide.  Genocide?  Seriously?  I had a look at the Genocide Watch website and I couldn’t find a single reference to teaching Delphi on it.  I don’t want to labour the point, but comparing something like the choice of programming language to genocide is a bit of an insult to people that have experienced real genocide.  I’m sure most people in Syria would much rather be sitting in front of a PC coding in Delphi than being slaughtered by the thousand, but who knows, maybe I’m wrong – Delphi could be worse than a horrible and painful death.  I suppose I should forgive such a thoughtless comparison from a software developer, after all, we like to compare our “coding skills” to “ninja skills”.  Ridiculous, I know.

This whole illogical argument can be summed up in one illogical tweet:


I’m amazed that there are three inaccuracies in a nineteen word tweet.  Firstly, we have not moved on from procedural programming.  Almost all object oriented languages are used in a procedural manner and just use the baked in library and tool generated classes, and there are a number of mainstream languages that are essentially procedural (JavaScript, SQL and Lua come to mind).  If anything, there appears to be a move towards procedural and functional programming languages.  How come none of the hysterical masses are suggesting F#?  Secondly, Delphi is not a procedural language, it’s fully OO and supports much the same feature set as C# (I don’t hear anyone calling C# procedural) and has much the same heritage (which is obvious to anyone who bothers to understand both).  Again, it doesn’t hurt to find out a bit about the poor little programming language before you make assumptions about it.  Thirdly, and probably the worst, is the assumption that using Delphi will somehow increase the “gap” between academia and industry.  What gap?  The gap between the barely literate school leavers and industry requirements?  Does anyone really think that teaching Java or Python (or whatever) is magically going to turn around the software industry and make the world a better place?  Not fucking likely!  I suppose it might in the mind of people who think that teaching an unpopular programming language constitutes genocide.  If you’re going to trivialize something like that, then exaggerating something else makes perfect sense.

Okay, so what is my argument?  The first is that people need to get it through their little skulls that the purpose of academia is not to produce tailor made workers for any industry.  The ideal outcome of any education is to produce independent thinkers who can adapt to industry (or whatever).  I find that a little ironic because, based on my experience, those in academia (teachers and university lecturers) live for the most part in a world that is largely divorced from industry (and reality, in many cases).  No amount of case studies and research is a substitute for being in the industry.  If you’ve spent your entire career at a university I don’t care how much research and how many case studies you’ve done, or how many “industry leaders” you’ve spoken to or collaborated with.  You really don’t know what you’re talking about.  Sorry.

The same applies to people in industry.  Stop bleating about how schools and universities aren’t producing graduates that don’t meet your exact requirements.  Schools and universities are NOT a substitute for in-house training and experience.  Learning does NOT stop once you leave school or university.  As I said before, the purpose of an education is to produce a thinking individual, and if successful will instil a lifelong curiosity and love of learning that even industry can’t destroy.  If you aren’t teaching people, don’t criticise those who are.  I’m pretty sure that being a good teacher is far more difficult than whatever it is you do for a living.

Sadly, the general response to this whole issue just highlights the problem with our educational system; industry and academia is already full of people that lack basic critical thinking skills.  Even more telling is the fact that the department of basic education’s response (and justification) for the case for Delphi is far more eloquent and logical than the case against it.

I think XKCD sums it up perfectly (if you don’t see the connection then you’re lacking critical thinking skills and are helping make my point).

Another good read is this article, particular the comments, which have been written by real software developers who appear to actually write software.

I’m always grateful for being given the opportunity to learn to think, and for school teachers and university lecturers who taught me that concepts have value.  Almost everything that I learned that makes me a good software developer has no obvious connection to programming or computer science and I think it’s high time that the software industry in general recognises that simple fact.  I don’t think it’s a coincidence that the best software developers that I know are almost all self taught.

I apologise for any typos or bad grammar – I typed this pretty quickly (maybe they should teach typing at school, rather).

written by Paul Mason \\ tags: ,

Oct 30


This is slightly old news now, but it’s probably still the best news I’ve heard in a while (days at least).  Although I’ve been expecting Corona Labs to support Windows Phone 8 at some stage, their sudden announcement caught me a little by surprise.  I’m even more surprised at the analysis of the announcement; that it’s good for Microsoft (and their platforms) and shows that people are taking them seriously in the mobile space.  This is all well and true, but I’m inclined to think that the move is of more value to Corona Labs.

Why so, you might ask?  Well, I’m a huge fan of Corona SDK and I think it’s by far the best approach for writing 2D mobile games, but I also want to target as many platforms as possible.  Developing a successful mobile game is a costly exercise and it makes sense to support as many platforms as possible, if the tools make it feasible.  There are already a number of good solutions that target iOS, Android and Windows Phone 8, the better ones being Unity and Game Maker, so even though Corona SDK beats both of them in ease of use (my opinion), the fact that it doesn’t support an important mobile platform gives my a good reason not to use it.  Of course, that’s not the whole story, because I feel that mobile developers should also be able to offer a web version (Flash or HTML5) for Facebook (and possibly other platforms such as Kongregate) to maximize the exposure of their mobile offerings (and Facebook is a pretty lucrative platform if you can get your monetization right).

So, I admit that Microsoft has a way to go to get their mobile platforms (Windows Phone 8 and the weird Windows 8 App Store) into the hands of more consumers, but let’s not make this all about what Microsoft needs – Corona Labs really needed to support the Microsoft Platforms to remain competitive, especially now that Unity is adding native 2D support to their tooling.  Can Corona Labs do more?  Most definitely.  If they really want to be a one stop shop for 2D game development they need to support web (Flash or HTML5), Windows Desktop (especially for Steam), MacOS (I believe this is in the works as well) and the consoles with indie friendly developer programmes.

written by Paul Mason \\ tags: , , , ,

Aug 01

I’ve finally gotten around to putting my thoughts down on the new OUYA game console.  In case you don’t know what it is, it’s a tiny (Rubik’s Cube size) Android game console that raised over $8M in a very successful Kickstarter campaign and sells for $99.  I’m not going to bore you with the details, just head off to the official OUYA website for the specs and story.


Unfortunately, I only came to know its existence shortly after the Kickstarter closed, but I pre-ordered one in early January and it was supposed to ship in April.  That didn’t happen.  It finally shipped near the end of June, although I did expect a delay and I really don’t blame them.  Apparently there were a few issues with the initial consoles, especially the controller, that they ironed out.  Shipping was from Hong Kong to South Africa via DHL Global Mail Packet Plus and the dispatch email gave me a tracking number, but no tracking link (even though it was mentioned in the email).  Their support took six days to respond to my email asking for the tracking url, which is understandable given that they had just launched the console, but I hope they improve their after sales service.

Anyhow, I finally got my package and I was disappointed to find that it shipped in a bland dark grey shoe box (essentially) that ripped when I took the sealing tape off (it appears that the retail packaging is much better) and the interior packaging is pretty cheap too.  I know it’s a cheap product, but I’d expected a bit better.  The console is a different story though.  It’s solid and well built, although I’m not crazy about the dark matt colouring.  I know they’re trying to go for a premium look, but I would have preferred a more funky colour scheme (maybe bright white with neon colour insets).  I really think that they should have gone the Nokia Lumia route and not the Samsung route.  The controller is nice and functional, but the removable magnetic face plates that cover that batteries pop off if you drop it and are finicky to replace.  Apparently you can use an Xbox 360 controller with a bit of effort, although the button mappings will be a bit unintuitive.

By the time I had actually received the console I had pretty much lost interest in it, so it sat on a shelf for over a week until I decided to set it up.  Setting up the console was dead easy, I just plugged it in, connected it to my TV with the supplied HDMI cable and I was off.  Well, sort of, only after the firmware had been updated.  Again, I found the user interface to be rather dull and uninspiring but hopefully that will be changed in a subsequent update.  One major complaint that I have is that you are forced to enter a credit card number before you can use the console.  I think that’s a bit of a cheek and you should only have to do that when you want to make your first purchase.

I downloaded a few games to try out (the trial versions) and I must admit that I’m underwhelmed.  I wasn’t expecting Xbox quality games, but it really felt that I was playing a cell phone game.  I’m sure this is temporary (there’s only 300 games available at the time of writing) and better games will appear.  My main gripe is that the colours seem a bit muted (I’m using a Samsung 5 Series full HD SmartTV, and my Xbox is just fine), the graphics are sometimes badly upscaled and the controller isn’t very responsive at times.  The controller is the only real weak point, because the responsiveness is variable (this is particularly noticeable when using it with the soft keyboard).

So, overall, I rate the different components as follows:

Packaging 2/5
Console 4/5
Controller 3/5
UI 3/5
Games 3/5
Overall 3/5


An overall score of 3/5 looks bad, but for $99 it is actually a good console.  It’s definitely not a replacement for your Xbox 360 or a PlayStation 3 and doesn’t even begin to compete with them, but if you’re looking for a simple console to play simple games then the OUYA is definitely worth a look.  Two very big plusses, however, are they facts that the hardware will be updated on a yearly cycle, apparently (which means you need to get a new console, but at $99 it’s no big deal really) and anyone can write and release games for it (more on this in a subsequent blog post).  I’m sure that the developer community will turn the OUYA into something far better.

So, should you buy an OUYA?  I don’t see why not.  It’s functional and will most likely have a good selection of fun games (just be patient).  There’s also a few other cheap and small Android game consoles in the works, and a rumour that Google is working on one as well.  I’m sure the OUYA will have serious competition fairly soon, so it remains to be seen if it can hold on an be the “premium” cheap Android console.  No matter what though, you can expect most games to be available on all of the Android consoles because they have a common platform and the controllers will all have similar button layouts.

written by Paul Mason \\ tags: , , , ,

May 28

Anybody who has worked for a company for any reasonable length of time has probably had the “we must be more innovative” line thrown at them (or forced down their throat) many times.  The argument usually goes along the lines that for company “X” to remain competitive, gain market share or enter new markets they somehow must be more “innovative” (or “disruptive”, in hipster speak).  But what exactly does this mean, and why do most companies struggle with it?  Even Apple, which is considered to be at the forefront of innovation is beginning to show signs of weakness in the face of what appears to be more innovative rivals.  Is Apple becoming less innovative, or are their competitors (Samsung) simply becoming more innovative?

The Business Dictionary has a long winded definition of “innovation”, which is probably half the problem.  A much more appropriate definition is “the act of introducing something new”.  That’s a pretty broad and vague definition, but that’s because innovation is hard to define and is only really obvious long after the fact, especially in a business environment.  Facebook was certainly innovative, but not at its inception when it was simply a method for students at a single university to keep in touch.  What makes Twitter so innovative?  It’s hard to say, since Twitter can just be thought of as a hugely scaled down version of Facebook.  What was so innovative about the iPhone?  Nothing really stands out, but the sum of the parts revolutionized the communications industry.

So, how do companies try to become more innovative?  Sadly, in most cases, the way they do that is to ask the staff to submit ideas for improving some metric (usually profit).  Why is this a bad idea?  Simply because you can’t add “be innovative” to a job description and expect it to just happen.  To make matters worse, these nicely documented ideas (red tape is a sure innovation killer) are then “evaluated” by the same people that asked for the innovative ideas and couldn’t come up with them on their own.  To put it bluntly, if you’re not the innovator then you probably wouldn’t recognize an innovative idea if it stuck its fingers up your nose!  Ideas that sound good to run of the mill management people are rarely innovative, since obvious ideas are, well, obvious.  Most companies operate on the premise of safe innovation (there’s no such thing) and best practices (a euphemism for average) so true innovation scares the crap out of them and won’t happen.

Okay, so we’ve established that you can’t just demand innovation and that most companies just don’t have it in them to be truly innovative; what can be done about it?  Unless you’re a government department you’re going to have to find a way to innovate (read: scrap best practices and be better than average) or simply become obsolete (you’ll be in good company).  Here’s the kicker.  Innovation isn’t a job description, a title, or a duty.  It’s a culture.  Read that again and let it really sink in. Innovation is a culture.  You can’t set aside an hour a day, or Fridays to be innovative.  You have to be innovative all the time, it’s simply a way of life.  Sure, you can set aside specific times to actually implement or hash out ideas, but the inspiration can hit at any time and your working environment must be conducive to that.  This leads to the obvious question: How does one create an innovation friendly working environment?  It’s actually surprisingly easy, and difficult at the same time.  You need to have less control and more trust.  This is easy because it leads to less micromanagement (an out-dated concept if there ever was one) but giving up the control, associated metrics and more importantly, the position of authority, is incredibly difficult for most managers.  This isn’t to say that all control must be given up and chaos allowed to reign, all in the hope that some good idea will crawl out of the woodwork and match some random business objective.  The opposite is, in fact, true.  You need to increase visibility across all related areas of the company so that employees can get a detailed big picture of where they fit in.  This will allow them to see and influence the effect that they have on the rest of the company.  This takes effort, but the end result is employees that know which wheels their cog turns and how to optimize for the whole and not just the part.  That is just part of creating a culture of innovation though.  The main part is trust.  You need to allow people to come up with ideas and to implement them.  Please note that I’ve linked coming up with the idea and the implementation.  The absolutely worst thing that you can do is to take the idea away from the originator, mangle it with your own half-baked ideas, and then hand it off to someone else to screw up.  Leave the damn idea with the originator and let them see it through to completion (unless it’s a really stupid idea or really impractical).  Ownership is extremely important to people and most companies push the idea of ownership, but in reality they mean ownership of failure and quickly subvert anything that looks like it might be successful.  Am I being too harsh?  Maybe, but just take my word for it, let innovation flow and don’t impede it.

Managers are probably feeling very nervous now.  How do they control things, allocate time and resources, make sure the right things are being worked on etc.?  It’s quite simple actually; the way you’ve always done it.  As I said before, innovation requires a culture change, not a process change.  Certain processes are, however, more conducive to innovation.  Coming up with new ideas is implicitly risky.  Most ideas don’t pan out and need to be ruthlessly culled, but they only way to do this is to implement them as quickly as possible and discard failures as soon as possible.  This leads to another cultural identity – a culture of failure.  This doesn’t necessarily mean that failure is encouraged or accepted, just that failure is inevitable and should be managed like everything else.  Agile and Lean methodologies are particularly supportive of this type of culture, where ideas are quickly iterated to determine their viability.  Being a leader in any industry is difficult and requires constant innovation.  If you want to be like Apple, don’t be stupid and try to copy Apple.  You don’t want to be like Apple, you’re probably in a different business so their metrics don’t apply to you, or if you are in the same business (sorry for you) then you want to do things differently to compete.

To summarize then.  If you want to foster innovation, do the following:

  • Trust your employees
  • Throw your employees in the deep end
  • Be transparent
  • Let go of the reins
  • Don’t punish failure (control it)
  • Give people the tools that they need (training, books, software, whatever.  Create a budget for this)
  • Give equal weighting to all ideas
  • Don’t remove ownership of ideas
  • Remove obstacles
  • Keep employees happy

If you’re only going to take one thing from this, makes sure it’s the fact that innovation is about the person, not the idea.  If you invest in the people the ideas will flow.  If you try to invest in the ideas only then the people will become disillusioned and wander off.

written by Paul Mason \\ tags: ,

Feb 11

Wonders never cease – I actually managed to get the next part out less than a month after the previous one!  If you’re new to this series on mobile game design patterns you might want to have a look at the previous two posts first.

Mobile Game Development: Design Patterns Part 1 – Introduction

Mobile Game Development: Design Patterns Part 2 – Simple State Navigation

Mobile Game Development: Design Patterns Part 3 – Advanced State Navigation

In the previous post I discussed how you would create the various states for a simple (but realistic) game.  In this post I’m going to expand a bit on the simple design pattern and discuss a slightly more complicated state arrangement that is commonly found in physics type games, such as Angry Birds.  These games are characterised by having a large number of separate levels, as opposed to levels that are characterised simply by a speed, length etc. change within the same game screen.

The diagram below illustrates this more advance game navigation.  I’ve left out the states that are the same as those discussed in the previous post and just included the new ones that add the advanced level navigation that these games display.


Game Design Patterns-Advanced


When the player taps the “Play” button, they are presented with a selection of levels.  Typically, a player can only play the first level when they start the game and the next level is only unlocked once they have completed the current level.  Levels may also be grouped into somewhat arbitrary groups (usually just for display convenience) and often require a certain aggregate group score to progress to the next group (simply completing all the levels isn’t good enough).  There are usually far more levels than can be displayed on the screen so the groups can either form part of a panorama display or be grouped into separate screens.  The pause behaviour is also a bit more complicated and is used to also give the player the option to skip to a different level (usually one that they have already completed) or go back to the game menu.  When the player completes a level they are given their score (usually based on a simple star system, not numeric) and given the option to replay the level, go to the next level, or go back to the game menu.

If you group your levels into sections you might want to merge the two levels of separation by displaying the individual levels within a designated group area (the various Angry Birds games use both methods).


Game Design Patterns-Advanced-Alternative


That’s it for the high level overview of mobile game design patterns.  I’ve obviously only just scratched the surface of the ins and outs of organizing the various moving parts of a game, but this is a good place to start and build from (covering every possibility is impossible and not a very good use of my time).  I’d encourage you to play various mobile games and document the various design patterns that you pick up and keep them as a reference for your own games.

In the next post I’m going to cover how you would actually go about putting together a little framework to make the state management of a game a little easier, together with a simple reference game.  Unfortunately, this has to be technology specific and I’m going to use ActionScript and the Starling Framework.  The principles are still the same though and should be easily transferred to the development tool of your choice.

written by Paul \\ tags: , , , ,

Jan 18

It’s been a long time since part one of this series (I got side-tracked a bit) but I’m finally back with part two.

Mobile Game Development: Design Patterns Part 1 – Introduction

Mobile Game Development: Design Patterns Part 2 – Simple State Navigation

Mobile Game Development: Design Patterns Part 3 – Advanced State Navigation


This part, and the next, will cover the state (screen) navigation of 2D mobile games at a high level.  I selflessly played and analysed a number of popular Android games to come up with a collection of common state navigation design patterns and from those, extract what I consider a starting point design pattern that can be used to design the state navigation framework for a game.  Before we go any further though, we need to be clear on exactly what a state is.  In the context we are discussing, a state is a particular activity (not necessarily interactive) in the game.  Examples of these are the actual game play, level selection, the settings screen, credits, the loading screen etc.  Things like the pause state are also considered states because the game play is suspended and a new state is entered that usually has some kind on overlay that indicates that the game is paused.  In other words, every “different” type of screen in the game is a state (at least one), and we use a state manager to allow the transition from one state to another.  It’s often possible for more than one state to be visible at a time, but only one is usually active at a time (for example, the pause state, where the game is suspended but the pause overlay or dialog box is interactive and can be dismissed to resume the game).  Having multiple active states at the same time is rare from a user perspective, but from a programming perspective it makes sense if you want to separate game logic into separate layers.  For example, you might overlay the game state with a HUD (heads up display) state to display things like the score, level, lives and the pause button.  In this case, both states are active and interactive.

The simple state navigation pattern that will be presented here is suitable for simple games that have a single game screen with either a single level or automatic progression to the next level, which is hosted in the same screen or state (from a technical perspective they may actually be different classes or objects).  Some examples of this type of game are Bejewelled (or any matching type game, actually) and Tetris.  Physics and puzzle games like Angry Birds will be considered in the advanced state navigation part because they have a more complicated level structure.  The advanced pattern is, however, just an extension of the simple pattern, which can be considered a basis for all pattern variations (by adding or removing feature states).  This is important because it will allow you to build a reusable game state framework to use in multiple games.

Continue reading »

written by Paul \\ tags: , , , ,

Jan 10

The first (major) issue that I ran into when trying to write a game for Android using Starling was getting everything to display nicely without clipping and distortion.  There are a number of samples and blog posts littered around but they all seem to have some issues under specific conditions.  I’m not saying that my solution is perfect, but it works for me.  There are a number of approaches to fitting content on the screen, but the simplest is just letter boxing.  This is simply scaling the content while keeping the original aspect ratio so that it fits on the screen, with either vertical or horizontal whitespace if the screen aspect ratio differs from the game aspect ratio.  If you want a really comprehensive overview of this topic, have a look here.

The code is actually quite simple, so no explanation is needed (I’m lazy).  Please excuse the dodge code, it just serves to illustrate a solution to the screen size problem and isn’t meant to be the best way of structuring the game code.

Application Class

   1:  import flash.desktop.NativeApplication;
   2:  import flash.display.Sprite;
   3:  import flash.display.StageAlign;
   4:  import flash.display.StageScaleMode;
   5:  import flash.events.Event;
   6:  import flash.geom.Rectangle;
   7:  import starling.core.Starling;
   9:  [SWF(width="480", height="800", frameRate="60", backgroundColor="#000000")]
  10:  public class MyGame extends Sprite
  11:  {
  12:    private var _starling: Starling;
  14:    public function MyGame()
  15:    {
  16:      var viewPort:Rectangle = ConfigureViewPort(480, 800, false);
  18:      _starling = new Starling(Game, stage, viewPort, null, "auto", "baseline");
  19:      _starling.simulateMultitouch = false;
  20:      _starling.enableErrorChecking = false;
  22:      _starling.start();
  24:      NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, function (e:Event):void { _starling.start(); });
  25:      NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, function (e:Event):void { _starling.stop(); });
  26:    }
  28:    private function ConfigureViewPort(gameWidth:Number, gameHeight:Number, centerVertically:Boolean = true) : Rectangle
  29:    {
  30:      stage.scaleMode = StageScaleMode.NO_SCALE;
  31:      stage.align = StageAlign.TOP_LEFT;
  33:      Starling.multitouchEnabled = true;
  34:      Starling.handleLostContext = true;
  36:      var viewPort: Rectangle = new Rectangle();
  37:      var xAspect:Number = stage.fullScreenWidth / gameWidth;
  38:      var yAspect:Number = stage.fullScreenHeight / gameHeight;
  40:      if (xAspect > yAspect)
  41:      {
  42:        viewPort.height = int(gameHeight * yAspect);
  43:        viewPort.width = int(gameWidth * yAspect);
  44:      }
  45:      else
  46:      {
  47:        viewPort.height = int(gameHeight * xAspect);
  48:        viewPort.width = int(gameWidth * xAspect);
  49:      }
  51:      viewPort.x = int((stage.fullScreenWidth - viewPort.width) / 2);
  53:      if (centerVertically)
  54:      {
  55:        viewPort.y = int((stage.fullScreenHeight - viewPort.height) / 2);
  56:      }
  57:      else
  58:      {
  59:        viewPort.y = int(stage.fullScreenHeight - viewPort.height);
  60:      }
  62:      return viewPort;
  63:    }
  64:  }


Game Class

   1:  import flash.display.Bitmap;
   2:  import starling.core.Starling;
   3:  import starling.display.Image;
   4:  import starling.display.Sprite;
   5:  import starling.textures.Texture;
   7:  public class Game extends Sprite
   8:  {
   9:    private var _gameWidth:Number = 480;
  10:    private var _gameHeight:Number = 800;
  12:    // A 480x800 background image.
  13:    [Embed(source="/background.png")]
  14:    private static const Background: Class;
  16:    public function Game()
  17:    {
  18:      Starling.current.stage.stageWidth  = _gameWidth;
  19:      Starling.current.stage.stageHeight = _gameHeight;
  21:      var backgroundBitmap:Bitmap = new Background();
  22:      var texture:Texture = Texture.fromBitmap(backgroundBitmap);
  23:      var image:Image = new Image(texture);
  25:      addChild(image);
  26:    }
  27:  }


That’s all there is to it!  I might consider revisiting this to add a bit of an explanation…

written by Paul \\ tags: , , , ,

Nov 16

This is just a slight detour from my usual detours.  I was thinking about what I consider the “essentials” if a person wanted to set up shop developing software for the Microsoft stack (i.e. Windows, Xbox, Windows Phone, web).  I’m not necessarily going cheap here, I’m just interested in the essential software and tools to make development comfortable (I don’t think that trying to go free for everything is particularly smart).  Hardware is a personal choice, that’s up to you.

MSDN Professional

There’s no wiggle room here.  Sure, you could go with the free Express version, but then you have to do without Visual Studio addins (like ReSharper).  MSDN Professional gets you Visual Studio Professional (2010 and 2012), Expression Blend, developer versions of SQL Server and version versions of Windows and Windows Server.  You really can’t do without this.  The other bits, such as ASP.NET MVC, XNA, Silverlight etc. are all bundled in or available as free downloads.  The more expensive subscriptions are nice, but I don’t think that they offer any additional value that you can’t do without (apart from Office, but it’s cheaper to buy it separately)  You can get it here.

Cost: $1999

JetBrains ReSharper

I don’t know about you, but I can’t live without ReSharper.  This tool offers extremely good value for money and is a huge productivity increase.  The full version is probably unnecessary, so just get the C# or VB version.   Just get it.

Cost: $199 for the full version, or $149 for the C# or VB only version.


Sooner or later something is going to blow up or break and you’re going to lose your source code.  It’s essential that you have offsite source control, and GitHub is a reasonably priced solution that scales according to your needs.

Cost: $7/pm for 5 private repositories.  If you want more, you pay more.


I’m a big fan of the Telerik tools, since they have comprehensive offerings for all the relevant technologies (WPF, Winforms, ASP.NET, ASP.NET MVC, Silverlight, Windows 8, Windows Phone).  The individual packages are quite pricey.  If you’re targeting multiple platforms then one of the DevCraft subscriptions are probably the best value for money.  DevCraft UI Edition, at $1299, is the best bang for buck.  Kendo UI, in particular, is a fantastic web framework.

Mono for Android and iOS

Just a little optional extra here.  If you’re interested in writing apps for Android and/or iOS and don’t feel like messing around with the native toolsets then the Xamarin Mono toolsets for Android and iOS might come in handy.  They integrate with Visual Studio and allow you to use C# and .NET for development.  Not cheap, but worth it for the productivity gains.  You can also use it together with MonoGame, which is a cross platform open source XNA implementation, for game development.

Cost: $399 for each platform or $718 for both.

Final Word

Okay, maybe that isn’t terribly cheap ($4000+), but it covers pretty much everything you’ll need to target every platform of interest.  You’ll probably also need Microsoft Office, a drawing application and various other bits and pieces, but you can get by with the open source stuff for that.

written by Paul \\ tags: , , , , , , , , , ,

Nov 12

Because they had to!

Okay, I admit that’s a bit terse, but it is the truth, in a nutshell.  A little background first though.  Apple released a new clock app with iOS 6 that bore more than a striking resemblance to the Swiss national rail operator SBB clock.  Unfortunately for Apple, this resemblance to the famous icon didn’t go unnoticed and they had to cough up $21M for the rights to use it.  Read here for a bit more detail.

You have to admit, they do look very similar.

So, why did Apple quietly pay up and not fight this?  You might argue that they don’t compete with SBB or any watchmaker, and that $21M isn’t even worth going to court for, but there’s a bigger picture here.  The big picture is that no matter how Apple approaches it, they lose, and they lose big.  There are only two arguments here; they either copied the design or they didn’t, so let’s have a look at both defence arguments.

Yes, we copied it.

This is the simplest and least damaging approach (which is the one they took by settling, but without admitting any guilt, in public).  At best this just makes Apple look like the copycats that they accuse everyone (Samsung, HTC, Google, Motorola, and Microsoft etc.) else of being.  This would be deeply embarrassing for a company that trades on its “originality” and it opens them up to punitive damages.  Arguing that the copying was done deliberately at a lower level (i.e. management didn’t know about it) won’t work because a company like Apple, that is involved in multiple lawsuits around the world around exactly the same design infringement issues, would be expected to perform due diligence and not allow that to slip through.  The result would be the same; embarrassment, a fine and possibly punitive damages.

No, we didn’t copy it.

Now this is where it gets interesting.  For this argument to hold water, Apple would need to prove that the design is obvious and any competent designer would come up with that design in a logical manner.  It makes perfect sense; it’s a simple round clock with rectangular parts and no other details or adornments other than those required to function.  Unfortunately for Apple, this is exactly the same logic that applies to their patented hardware designs for the iPhone and the iPad, and what won them $1B in their case against Samsung.  Using this argument (and winning) would immediately invalidate their hardware patents.  Clearly this would be very bad for Apple.

My Opinion.

It’s no secret that I’m not a fan of Apple (their business practices) and that I think that the vast majority of software patents are extremely detrimental to the entire software and hardware industry (and that’s without patent trolls).  Although I have no real basis for my opinion, I think that Apple did knowingly copy the clock design (any designer worth their salt would know about that particular clock design), but felt that since the design is so simple it couldn’t be protected (or else they would have licensed it or used an original design).  Unfortunately, this lowers my already low opinion of Apple because they vigorously defend the same rights that they refuse to recognise in others.  It’s not acceptable to patent a simple black rectangle but refuse to acknowledge the copyright on a simple white circle with black rectangular markings (the clock design is actually more complicated than the external iPhone hardware appearance).  Unfortunately, Apple is trying to set a precedent that really isn’t in anyone’s best interest, but hopefully they’ll tread a bit more lightly now that things are coming full circle and they’re beginning to get bitten by their own creation. 

written by Paul \\ tags: ,

Switch to our mobile site