Tuesday, 31 January 2012

Waterloo Game Analysis

Microsoft created the Facebook Game Waterloo in order to do some research on game theories.

Tonight, just for fun, I wanted to create a piece of software that enumerate all the possible combinations and find the move with the highest probability of win (one Nash Equilibrium).

I created it using a simple C# console application.

First of all, I created a function that returns a list of all possible moves for each player (the funniest part):

After that, for each pair of moves, I calculated the number of wins and finally get the better move.

The implementation of the Win extension method:

and the main body:

This is the output of the basic example:

Using total = 15 and n = 5 the result is:

The Waterloo game use total = 100 and n = 5. With these numbers the code is too slow to terminate but you can easily guess that the result will be (20, 20, 20, 20, 20).

If you are curious about the total number of possible moves in Waterloo I can tell you this with the following code. The code analyse a specific Waterloo move telling you what is the probability of win in addition to the total number of moves.


The output:

So, the total number of moves is 4598126 !!!

The move (20, 20, 20, 20, 20) is the "best move" in terms of probability. However, if you play against a human being it is probably easier to come up with a solution like (33, 33, 34, 0, 0) or (34, 34, 11, 11, 10). In both the cases, if you use the "best move" you lost.

Let's see the result using (33, 33, 34, 0, 0):

Let's see the result using (34, 34, 11, 11, 10):

Arrived at this point I feel a little bit lost. What is the best solution?

Probably there are more Nash Equilibrium's and the solution should be a probabilistic strategy instead of a simple move.

Let's see what will be the result of the research.

If you want to learn more about Game Theory, you can watch this introduction course taken from the Artificial Intelligence class:

You can find the full source code in my personal repository: Waterloo Game

UPDATE: Code from IanS

IanS proposed a recurvise implementation of the "combinations" algorithm. It it probably slower then mine (it is a recursive algorithm) but has the advantage of readability. This solution has the interesting property of not using any explicit assignments or increment operations.

Thank you Ian for your feedback.

Sunday, 29 January 2012

Unlimited Internet and my new Android device

Yesterday, I finally solved an important problem.

As many of you know, I am living in UK while my girlfriend live partially here and partially in Italy. We tend to stay quite in touch with each other but this costs me a lot of money. Unfortunately there are no telephone companies with offers on text between countries.

The solution? Unlimited Mobile Internet.

We started from the following situation:
  • I have a vodafone italian card without Internet access
  • I have a Windows Phone 7 device (LG Optimus 7)
  • She has a vodafone italian card without Internet access
  • She hasn't a smart phone
We decided to move to 3 and get two UK Sim cards with unlimited Internet and the offer with two android devices (two years plan). I could simply buy the Sim card and using my Windows Phone but the price was almost similar. I choose an Android device because it was silly to me to have two Windows Phones.

The situation is now:
  • We both have a smart phone with Android
    (Sony Ericsson XPERIA)
  • I have a Windows Phone 7 device with my Italian Sim card
  • We both have Unlimited Internet in UK
  • We both have lots of text and calls for free every month
  • I reduced my telephone costs of more than 50%
Yesterday, I played all the day with my new phone :)

Having Unlimited Internet is awesome. You feels like the entire world is in your hand.

Fantastic !!!

My New Official Blog


It is a while that I am considering ways to centralise my presence on the web and I finally decided what to do.

Until now I had three blogs and one personal web site:
In the past, I made the decision to separate technical blogs from personal blogs and trying to differentiate between Italian and English but actually I realised that has been a very very bad decision. When I wanted to create a post I had to decide the language to use and try to identify the type of content in order to choose where to write. However sometimes it is difficult to make this choice because some content are both technical and personal. In addition creating a pure impersonal technical blog is sad. For this reason I often mixed the things in strange ways loosing completely my original intention to differentiate. The advent of Facebook changed the rules significantly because I started to publish my personal stuffs there so I almost stop blogging.

At the same time I didn't want only a simple blog but I wanted a single personal homepage with a blog inside it. I basically wanted a single entry point to my digital life. Implementing a portal like this manually requires a lot of work and I couldn't really afford it in a reasonable time. Fortunately, I realised that BlogSpot could be easily solve all my problems.

Why BlogSpot:
  • Extremely easy to setup and use
  • Easy to customise with lots of gatdets available
  • Possibility to create custom pages in addition to the blog (the blog itself is just a page)
  • Possibility to choose a custom domain name (andrea-angella)
  • Possibility to add a new post using the browser (no need of external software like Live Writer)
  • Possibility to check the spelling
  • Support for mobile devices
  • Well integrated with Google services (Of course, this is Google)
  • Free
Unfortunately I didn't find a way to export my old posts in a format acceptable for import. For this reason, I imported manually only the most important old posts.

An another important decision is the language. For obvious reasons, I am going to write most of my posts in English. After all, I am living in UK and this seems the right decision. English is the way to reach a vast amount of people but I am very sorry for some of my Italian friends that could have problems reading my posts. For you, I suggest using automatic translation services offered by Google that are easily accessible at the right of the page. An another quick option is to install the Google Toolbar to get translations with a single click by adding one of the buttons below to your browser's toolbar.

I probably won't remove the others blogs for a while but I am not going to update them anymore. For this reason, please, consider this as my only blog.

This is my only blog.

My intentions with this blog are the following:
  • Create a single entry point to my digital life with links to my presence in the web
  • Share with the world my opinions and some technical stuffs
  • Receive constructive feedbacks
  • Keep track of my life experiences and my learning for personal reference
  • Improve my writing skills in English
Thank you