Computer Science Programming

The Generation Game – A Simple Genetic Algorithm

Last night my housemate Hayley and I were talking about the Data Mining and Decision Systems module we took last semester, during that discussion the concept of genetic algorithms came up.

In the computer science field of artificial intelligence, a genetic algorithm (GA) is a search heuristic that mimics the process of natural selection, except that GAs use a goal-oriented targeted search and natural selection isn’t a search at all

– Wikipedia

Hayley explained the concept to me using the idea of an animal that is more likely to survive in its environment by blending in with the colour of its surroundings. So tonight, as a nice change from revision and work on my Final Year Project, I had a go at developing such an algorithm — with a somewhat humorous undertone. The result of this undertaking is a little tech demo called “The Generation Game – A Simple Genetic Algorithm”.

In the demo it is advantageous for a sheep to be green, in order to fit in with its field. However at the beginning of the game the ten sheep in the initial flock are of completely random colours.

Turns are taken, in order by

  1. A Flock of Sheep, which breeds, producing 1 new sheep for every two sheep in the flock (if there is a left over sheep it doesn’t breed). Sheep produced by the mating process are the median colour of its two parents.
  2. A Wolfpack which depending on its hunting ability can eat 10% – 60% of the heard in any given turn

The closer a sheep is to the colour green, the less likely it is the be a casualty of a wolf attack (however there are other contributing factors, and a green sheep can still be killed).

As you can see from the gif image above if the initial flock has a green sheep amongst its ranks then evolution takes place (survival of the fittest, like how Darwin described it) and within just 20 generations the flock consists of only green sheep.

Another interesting situation is when there is no green sheep in the initial flock.

Evolution with No Green Sheep
Evolution with No Green Sheep

As you can see from the example above which starts with no green sheep the flock gradually becomes a light brown colour, this is the closest colour the flock could get to green with the genes avaliable in its gene pool.

This is just a simple tech demo (written in C# with XNA) to prove to myself I understood the concept, but it worked out quite well and I think its cool. I’ll be cleaning up the code and adding some comments, so be sure to check out the repository containing the program on GitHub.

Thats all for now,

Microsoft Student Partner

The Perks of Working with Microsoft

Reasonably often I hear my friends saying how they’re dreading a certain lecture or hate writing a certain essay they have to do. I’ve never really experienced that, I love what I do and I think I get to do a lot of really cool stuff — from making games to mucking around with robots. Another of the things I adore about this subject is the opportunities  you get that a lot of other subjects don’t seem to get, a good example of this was yesterday when I got two emails from Microsoft.

The first email was to confirm to me that my free tickets to the App Builder Showcase at Modern Jago in London had been reserved. This event is particularly exciting because the special guest is Steve Ballmer, the CEO of Microsoft and one of my favorite people in the technology industry because of his famous enthusiasm for what he does. I can’t wait to meet the man himself and hopefully learn a lot of things about both the company and the industry as a whole from a man who’s been there since the foundation.

Steve Ballmer, CEO of Microsoft - Somehow this man is in charge of one of the largest companies in the world ;)
Steve Ballmer, CEO of Microsoft

The second email was to confirm my place at the Western European Microsoft Student Partner Summit in Dublin, Ireland. Microsoft are very kindly paying all my expenses, including getting there, staying in a hotel and all my food for the 3 days. They will also be putting on a range of events and activities ranging from learning about porting XNA to Windows 8 & Networking with MVPs and MSPs to going for Dinner at the Guinness Storehouse (Yay! ;)).

I shall of course be blogging about my experiences at both events, so check back for those!

And it would be rude not to end he post with a big thank-you to Microsoft for being so good to me, particularly Phil Cross and everyone else on the Academic Audience Team.


Conferences University

Windows 8 Camp

One of the slides compared how people see Windows 7 and 8 using what people drew after each experience, this slide shows Windows 7 – All of the experience is actually chrome not content

Today we had a Windows 8 Bootcamp at the University of Hull. The idea of the camp was to showcase Microsofts up-and-coming operating system and hopefully inspire us to produce some Metro-style applications for the Windows 8 Marketplace.

Simon Michael and Joanna Tong provided some cool insight into the OS, which has just reached the Release Preview stage of development — you can download it for free here.

I was particularly impressed by the concept of “Contracts” within the OS, which allow a program to say “I can be searched” or “I will accept pictures from another application” and then be searched or shared to from any other application. This means in theory that if a new big social network comes out developers won’t have to integrate into it manually, they can just wait for the network to make a Windows 8 app that says “I can have pictures and text shared to me” and it will automatically work with their programs without any changes — just like a more future proof version of the ShareStatusTask on Windows Phone 7.

Another feature which I quite liked was notification support. I’ve thought for the last few years that Social Networking and even Email has been better on smart phones than the desktop, particularly on Windows Phone and iOS and this is partly due to the fact that you always know when you have a message, whether and application or programming is running or not, it’s delivered through the operating system! I’m all for taking the best features of mobile OS’s to the desktop, and this is one of those occasions where it makes sense — as long as apps don’t abuse it :P.

A lot of the talk was on how to produce good quality, chromeless, Metro-Style applications on the desktop, it was really interesting how much thought Microsoft have put into the idea and implementation — even down to the exact font sizes that should be used in different situations.

One of the diagrams shown to express why chromeless applications are better is shown above — after a few hours use of Windows 7 people were asked to draw their experiences, the average result is the picture above, notice how it’s all user interface items (the start bar, applications buttons, a window with minimize, maximize and close buttons and some scroll bars) — Microsofts argument is that no one starts their computer thinking “Ooh, I wanna see some buttons!” — ok, ok, maybe computer scientists do 😉 — but instead they start their computer looking for content, whether that be train times, weather or news or even social networking feeds.

The next diagram we were shown, which I neglected to take a photo of,  showed the diagrams people drew after a few hours of use with Windows 8. My attempt to recreate it is shown below:

Windows 8 UI Diagram
Windows 8 UI Diagram

As you can see, everything the user drew in this diagram was actual content (the title, and the tiles were information about weather in a weather application). Microsoft say this shows that Windows 8 “makes content King” which is what you want if you’re a content provider, or even if you just want people to remember your application rather than the Operating System around it.

The actual Windows 8 applications are really very good looking, due in part to their simplistic monochrome Icons and large image — or even video — backgrounds. A great example of which is the weather application which displays a video background based around the current weather. If its sunny you’ll see a nice sunny scene, if its raining droplets of rain will “hit” your screen and an occasional pair of windscreen wipers will come along to get rid of  it — its quite cool in practice.

Windows 8 Weather Application Metro UI
Windows 8 Weather Application Metro UI

During one of the breaks I got my first opportunity to play with a Windows 8 Tablet, and I must say it was really fluid and really made a lot of sense — compared to on a desktop where sometimes the whole mix of desktop and metro user interfaces doesn’t quite work. The tablet itself was a x86 device so had access to the full Windows 8 experience including the complete desktop — which the cheaper, more power efficient ARM based devices won’t have. So it’ll be interesting to see how useful they are when they’re released. 🙂

The only bad thing about the session, and perhaps Microsoft as a whole recently recently, was the “No comment” stance on XNA support in the operating system. XNA is a game development framework which I personally love. It’s the only way to write games on Windows Phone 7, and according to Rob Miles will be fully supported on Windows Phone 8, but it’s been left out of WindowsRT so far and therefore cannot run in the metro environment or on ARM Tablets whatsoever, however it will function as normal in the traditional desktop on x86 machines.

When asked about XNA support Joanna said “The official line is No Comment, keep checking” — which I suppose is better than a flat out “we wont support it in Metro or on ARM” but I’d like to know the unofficial line too 😉

A suggestion was that people could move on the C++ and DirectX or HTML5 and JavaScript for development of games on the desktop but its a shame that XNA, a framework we’ve all learnt so recently, but more importantly a framework which is so good at what it does, appears to be being neglected :(.

Other than that It was a great session and I reccomend anyone who has the opportunity goes to a Windows 8 camp!


Mobile Application Development University

Reaction to my XNA Windows Phone Theme Library

Since publishing my blog post about my XNA Theme Library I’ve had some great feedback from the Windows Phone Development Community. My lecturer and Windows Phone MVP, Rob Miles, posted a blog post about the library which you can read by clicking here.

Windows Phone Geek, a windows phone fan site, posted a blog post which is available here.

Chris Smith also pinged me an email and wrote about the Theme at DZone here, so thank-you to him for contacting me and letting me know!

All these links and general interest in the library resulted in my best ever 48 hours, as far as unique page views are concerned, since I started the blog before joining my University in September last year, So I take this oppertunity to say thank you again to all my visitors.

Remember you can download the source code and dynamic link library file for the XNA Windows Phone Theme here.

Mobile Application Development

XNA Windows Phone Theme Library

Recently, whilst developing Sweepy Cleaner I found that it was a bit of a pain to get the theme colour of the phone in XNA, Microsofts Game Development API. This was frustrating, especially compared to how easy Microsoft have made it for Silverlight Applications. My solution to this issue is WindowsPhoneTheme.dll, a simple to set up, simple to use library which does what it says on the tin. It has the following features:

  • Get the following resources delivered to your XNA game code as an XNA colour
    • Phone Background Colour (Dark / Light)
    • Phone Accent Colour (Tile Colour)
    • Phone Border Colour
    • Phone Chrome Colour
    • Phone Contrast Background Colour (i.e. The opposite of the current background colour)
    • Phone Contrast Foreground Colour
  • Get the colour of any tile type. Don’t want to have to remember the RGB values for all the possible colours? Now you don’t have to.
    • will return you blue
    • Here are the other colours
      • blue
      • red
      • green
      • mango (orange)
      • pink
      • brown
      • lime
      • teal
      • purple
      • magenta
  • Simple Syntax
    • Just want the tile colour?

      Simple as that

    • Use intellisense for the other methods

The Windows Phone Theme Library is released under an MIT license. Do whatever you want with it, but I would love it if you credited me and emailed me to let me know you’ve done so at this email address.

To download the library and see the associated usage guide click here

Mobile Application Development University

Learning XNA with Sweepy Cleaner

So, a few days ago we got our ACW 2 brief for the Programming 2 module. Our task, should we choose to accept it, is to make an “all action domestic cleaning game” or a  bank management application. Wanting to learn how to use Microsoft’s XNA Framework, which is used to make games for Windows, Windows Phone 7 and XBOX, I chose the former.

So far I have learnt quite  a lot (mainly from Rob Miles’ XNA Game Studio 4 book) including how to animate a sprite (which you can see being done with the world most realistic vacuum cleaner sprite in the video above), how to record and manage touch input (which is used to see when a button has been pressed) and how to use “Launchers and Choosers” (for example launch internet explorer, which I do to show the Sweepy Cleaner website)

For the moment I have only created the menu which has the following functions:

  • Allows the user to click to play the game
  • Allows the user to view highscores
  • Allows the user to visit the sweepy cleaner website
  • Allows the user to see who made the app and other information about the app itself
  • Allows the user to see other apps published by me in the store
  • Allows the user to rate “Sweepy Cleaner”

I’m currently in the process of writing code to decide if a user has achieved a new Highscore or is in the top 5 (or indeed if they have the worst score ever!) and then save these highscores to an XML file in Isolated Storage.

That’s all for now,

Mobile Application Development

Evil Squash for Windows Phone 7 Usage Statistics at (just over) 100 Downloads

I’ve always quite enjoyed reading Rick Brewsters usage statistics blog posts for Paint.NET so I thought it might be interesting to write a similar post about Evil Squash on the Windows Phone 7 Marketplace. I reached a milestone earlier this month of 100 downloads (not bad for an application that was originally intended to only be part of my coursework.) So here it goes:

Downloads by Market (Country)

Unsurprisingly most of my Downloads are from the United Kingdom with 56 out of a total of 112 coming from the UK.

Just behind this is the United States with 51 Downloads.

The third and last market with any downloads is rather surprising, Hong Kong with just 5.

Interestingly enough, though the app is available in Canada and Australia not a single download has taken place in either country.

Downloads by Day

As you can see from the feature image of this post most people downloaded the app immediately after its availability, probably due to being high in the “new games” section of the marketplace. Since then downloads have slowly trailed off, but this is to be expected.

The Future

Having started the application off as a Silverlight based app I have decided to move over to XNA which will more easily allow me to more easily implement some more of the features I want to be in the game (including the AI doing their own moves, Animations etc). The only issue is, I’ve never used XNA… yet. So I’m steadily learning from Rob Miles XNA 4.0 book.

The next version of Evil Squash will also have social network integration so you can boast of your wins.

Thats all for now,


Things to look forward to…

Today was a pretty average day, tomorrow however are I’m attending some extra XNA lectures and the weekly Computer Society Fragfest! Fun fun fun 🙂 Today I also bought my train tickets to London to have a tour round the houses parliament on November 11th!

Its only 3 days till my next train journey, speaking of trains, I’m back home in Dunstable Friday – Sunday! 🙂

Lots of exciting things coming up!