Sunday, 30 December 2012

Some analysis of the game shut the box

This Christmas, +Zoe Prytherch and I got my mother a small board game called: "Shut the Box" (also known as "Tric-Trac", "Canoga", "Klackers", "Zoltan Box", "Batten Down the Hatches", or "High Rollers" according to the wiki page). It's a neat little game with all sorts of underlying mathematics.
Here's a picture of us playing:

Here's a close up of the box:

A good description of the game can be found on the wiki page but basically the game can be described as follows:
  • It is a Solitaire game that can be played in turns and scores compared (but no strategies arise due to interactions of players).
  • The aim is to "shut" as many tiles (each being one of the digits from 1 to 9) as possible.
  • On any given go, a player rolls two dice and/or has a choice of rolling one dice if the tiles 7,8,9 are "shut".
  • The sum total of the dice roll indicates the sum total of tiles that must be "shut". If I roll 11, I could put down [2,9],[3,8],[1,2,8] etc...
  • The game ends when a player can't "shut" tiles corresponding to the dice roll (including the case when all tiles are "shut").
Here's a plot of a game we played with a few of my mother's friends:

You can see that myself and Jean did fairly poorly while Zoë made the difference just at the end to win :)

The game could be modelled as a Markov decision process but over the past few days I decided to code it in Sage and investigate whether or not I could find out anything cool with regards to strategies. If you're not aware of Sage I thoroughly recommend you taking a look, it's an awesome open source mathematics package. In this instance I used the Partitions function to rapidly obtain various combinations of dice rolls and/or tile options to get the results I wanted.

The code is all in a github repo and I feel I've written an ok README file explaining how it works so if you're interested in playing with it please do! The code basically has two parts, the first allows you to play using the program instead of a game board (with prompts telling you what your available plays are).

Here's a quick screencast of me demonstrating some of the code:

The second part of the code allows for strategies to be written that play the game automatically ("autoplay"). I've considered 4 strateges:
  • Random (Just randomly pick any potential tile combination)
  • Shortest (Choose the tile combination that has shortest length: i.e. [3] instead of [1,2] ~ in case of a tie pick randomly)
  • Longest (Choose the tile combination that has longest length: i.e. [1,2] instead of [3] ~ in case of a tie pick randomly)
  • Greedy. This chooses the tile combination that ensures the best possible chance of the game not ending on the next go. This is calculated by summing the probabilities of obtaining a dice roll that could be obtained.
I've been leaving my computer run the code in the background for a while now so here are some early results. I've got over 90000 instances for Greedy and Random with over 40000 instances for the other two which I thought of later (EDIT: I know have over 400000 instances...). I've collected (as and when one of my home boxes was ideal) more data since writing this and the file is available for anyone to play with here. If I've made any mistakes with my analysis, I'd love to hear it!.

First of all what does the average score look like:

Greedy_Score   Random_Score     Longest_Score   Shortest_Score  
Min.   : 0.00  Min.   : 0.00    Min.   : 0.00   Min.   : 0.00  
1st Qu.: 6.00  1st Qu.:14.00    1st Qu.:18.00   1st Qu.: 7.00   
Median :11.00  Median :21.00    Median :24.00   Median :11.00
Mean   :11.42  Mean   :20.45    Mean   :24.16   Mean   :12.06  
3rd Qu.:16.00  3rd Qu.:27.00    3rd Qu.:30.00   3rd Qu.:17.00  
Max.   :43.00  Max.   :43.00    Max.   :43.00   Max.   :43.00  

Shortest and Greedy seem to do a fair bit better then the other two. If we take a look at the distribution of the scores that is confirmed:

If we also take a look at the length of the game (i.e. how many total dice rolls there were):

Greedy_Length  Random_Length  Longest_Length  Shortest_Length
Min.   :1.000  Min.   :1.000  Min.   :1.00    Min.   :1.00    
1st Qu.:4.000  1st Qu.:3.000  1st Qu.:2.00    1st Qu.:4.00    
Median :5.000  Median :3.000  Median :3.00    Median :5.00    
Mean   :4.897  Mean   :3.414  Mean   :2.86    Mean   :4.82    
3rd Qu.:6.000  3rd Qu.:4.000  3rd Qu.:4.00    3rd Qu.:6.00    
Max.   :9.000  Max.   :9.000  Max.   :8.00    Max.   :9.00    

We see that games last longer when using Greedy and Shortest. If we look at the distribution we see (I've updated this graph since first publishing this post):

It looks like Greedy might allow for slightly longer games than Shortest. Whether or not playing Shortest or Greedy is actually any different seems interesting. A simple analysis of variance (ANOVA) seems to indicate that there is a significant effect:
Df Sum Sq Mean Sq F value P
stbaov$Method 1 11337 11337 196.3 2e-16
Residuals 127169 7345725 58

This is all experimental of course and analysing whether or not my suggested greedy strategy is indeed the optimal strategy would require some markov decision process modelling. I might look in to this with an undegraduate project student next year.

The tricky part about using the greedy method whilst actually playing the game with friends is that it requires a fair bit of calculation. Nothing that Sage can't handle in a split second but something that could keep people waiting a fair bit if you were to work it out with a pen and paper. Despite the significant statistical difference between the methods this analysis seems to indicate that choosing the shortest set of tiles is a pretty good strategy so if in doubt I recommend choosing that...

If anyone cares enough about all this to fork the code or suggest a different strategy I'd be delighted :) In case you missed it above, here's the github repo:

(On a technical note some of the pre analysis is done using python and the actual graphs seen here are done using R)

Sunday, 16 December 2012

My experience of G+ as an academic

So Patrick Honner wrote a blog post about twitter for Math teachers. I thought I'd try and do something similar for G+.

DISCLAIMER: I don't know what I'm talking about. I'm in no way a social media expert and/or claim to have any better knowledge on this subject then anyone else. This post will most probably just turn in to a story about how I've used G+ over the past 18 months or so.

My General Philosophy

I've been on G+ for a while now and I'm a really big fan. I joined twitter and got an invite for G+ from an old pal about a month later. As I didn't have any attachement to twitter at that moment I didn't really have a reason to invest in it. I believe that G+ is by far the best designed social platform out there and I was an immediate fan. I thought I'd fully move over to G+ (once I figured out how to get all my photos off facebook I actually quit that). I wrote a blog post about this a while back.

My main rule from the start with G+ was (and pretty much still is apart from one exception that I'll get to in a bit): only post publicly about stuff linked to my "professional life" ~ so "science-y" stuff. I stick to this not because I don't want to share pictures of my holidays with the world but mainly because I think no one would care and I don't want to bore anyone. Having said that, I know a lot of people who share non "science-y" stuff publicly and I certainly enjoy reading it, for example Dana Ernst (a mathematician) often posts about his trail running activities which I always enjoy reading.

I know some people actually do the opposite and use circles to "direct" information. For example they have a math circle and post mathematical content to that circle. I personally don't feel that is the best way to do things as it stops people you haven't circled from finding your posts. 

I use circles for personal things (ie stuff I don't think the world cares about ~ with some friends we communicate via G+ instead of text messages as a bunch of us can follow a single conversation) and also to filter how I read information. For example I have a math circle, a programming circle and a news circle. During the day, depending on my mood I'll read from one of those circles.

That's the very basics of how I use G+ on a day to day basis. 

Some Anecdotes

I really enjoy G+ and have had some great interactions (by all means skip this section as it's just a couple of personal experiences):

- A recent conversation about the teaching of Game theory on one of John Baez's post is a great example of how G+ allows for sharing of knowledge and interaction. I "met" quite a few people on that post and got quite a few ideas for teaching.

- I've learnt a lot about R from Josh Wiley who even took a look at some teaching materials I was putting together. I'm not too sure how Josh and I met (ie on what post) but I guess it was following a series of conversations that I felt comfortable enough to ask him for a hand.

- I've had some students points out typos in my notes :)

- At the very beginning of my time on G+ I spent a while looking for mathematicians and Operational Researchers. One of the early people that I interacted with was Bo Jensen. Paul Harper and myself would chat for ages with Bo about how to use circles (I think we still don't agree :) ). We had a 1 year anniversary hangout:

All of the above are just some small examples of some cool interactions I've had on G+. One of the best things I've done that had some connection to G+ was when I posted about it during the long run my fiancée and I did (160 km over 5 days). This was from Cardiff to Gregynog (where a mathematics colloquium is held every year). This slightly broke with my above "rule" about just posting publicly about "science-y" stuff. Having said that it was a very special experience and I actually posted publicly about it the whole way using the hashtag (oh yeah they work on G+ as well): #jog2nog. On the second day I proposed to Zoe and it was kind of fun to share it.

How I do things

The main point for me about G+ is that you can make it as personal as you want. There is no "right way" to use G+. I've often discussed this on G+ when some people have stated that people "do things the wrong way". I think that's what's great about it, there is no right or wrong way to use it.

Having said that this is how I do things:
  • Engage on other people's posts. I think that I enjoy discussions on other people's post far more than on mine. So I often spend time just reading through posts chatting and meeting new people.
  • Engage with people on your posts. I'm always flattered when people take the time to post a comment on one of my posts so I always try to enter in to a conversation if there's scope for one. 
  • Don't circle everybody. I love the asymmetry of G+. This allows for the possibility that some people might be interested in what I say whilst I might not care for what they say (and obviously vice versa - there are quite a few people I've circled who haven't circled me back and I'm certainly not offended by that). I do my best to take a look at people who engage with me and often circle people who post stuff that interests me.
  • Tag wisely. There's a lot going on on G+ (people who call it a ghost town make me giggle but I'll get back to that). So it's tricky to see everything so I often tag people in to conversations if I feel that they might have something to add or might like to listen in. Similarly I always appreciate being tagged in to a conversation that I might be interested in.
  • Link to G+ stuff on other sites. Photos are awesome on G+ and a public post can be seen by anyone (whether or not they're on G+) so I often grab the link to a post (by clicking on the date stamp) and share that (that's in fact the only way I currently use twitter).
  • Have buffer circles. When large circles get shared I often add the whole circle but put it in a particular circle (eg "Science [to edit]" as opposed to my "Science" circle). I put the noise filter up quite high on that circle (see pic) and slowly move people I'm interested in over to my main "Science" circle.
  • NEVER "Also send email to ...". You can post to a particular circle and choose to notify everyone in that circle (see pic). I only ever tag particular people if I want them to seethe post but I never spam an entire circle. I don't recommend doing it as it's an easy way to make people mad...

Find stuff

People who call G+ a ghost town are like people who walk in to a busy bar with their eyes closed, walk out and say that no one was in there. Search for stuff you like (for example "math" and/or "science") and just meet people. If you don't want to meet people then I guess G+ also works, just sit by yourself and don't speak to anybody (I don't think that would be that much fun though).

If you want science take a look at the following:

- Fraser Cain's handpicked  science circle.
- The Science on Google+ Public Database: a bunch of circles on science.
- A small circle of Operational Researchers who post publicly. I put that together while ago so I really should update it.

Something brand new has appeared on G+ in the last couple of days: Communities. I'm still unsure about them as I'm a bit worried that they're compartmentalising information but just search for a community and you'll find people in there to meet :)

Some final thoughts

The one word I always think about when describing G+ to people is "learn". I have learnt so much from G+ (cool programming things, teaching methodologies, general mathematics etc). I am very grateful.

I never really got going with twitter and so I'm sure I'm "not using it right" but I just don't see how it can offer the same level of engagement as G+ does. A while back someone tweeted "at" me (I'm not even sure if I'm saying it right) and I wanted to answer (they complemented me and I wanted to say thanks). After 10 seconds I gave up as I wasn't sure how to get it all down in 140 characters and also I didn't want to confuse my followers on twitter. So I simply went over to G+ and sent them a limited message (i.e. posting to just them). We ended up having a long conversation about G+ and twitter. I don't believe that that would have happened on twitter but again, perhaps I wasn't "using it right".

I've not really mentioned hangouts. They're awesome. Use them.