Recording Game Statistics

The competitive urge is one of the main reasons we play games.

To help tap into that, over and above the competitive nature of my game itself, I decided to record stats. If nothing else, it gives each game a little extra edge if you know that the CPU has 25 wins to your 24.

Recording such stats might seem like an easy enough task. Just add one to the win or draw or lose count at the end of every game against the CPU (I’m not recording two-player game stats). That would be very easy. I’d just need to create a table using SQLite – my data persistence mechanism of choice for iOS development – and write some code to store and retrieve stats, and job’s a good ‘un.

There is a problem with this approach. What if the player wanted to see how many games they’d won on a certain board? My simple stats wouldn’t be able to tell them. I could record that stat though, which would require a little change to the SQLite table.

There is a problem with this approach. What if the player wanted to see the average score in a 5-disc game playing Thief on the Classic board? Again, my simple stats wouldn’t…

When deciding which stats to record I decided the best approach wasn’t to second-guess what the player might want to see. The best approach was to just record the data of the games. By recording that data I could effectively display any relevant stats. Want to know your average score on Most Points Wins? Sorted. Need to know which game type you win at most often? No problem. Want to know which game you play so much you’re about to get a divorce? Done.

Once that was decided it was a simple matter of creating the table in SQLite and the Lua code to access it. Every time a CPU game finishes I write the details to this table, and I can then retrieve the data any time to show the stats.

The next challenge is to figure out how to display the stats in a way that fits in with the game. I love data and I love stats, so I’ll probably enjoy this design challenge a little more than most.

%d bloggers like this: