Category Archives: coding

Back to the game ranking app

Finally after at least a couple of years I have returned to the rewrite of the ranking code I wrote.

I got a new copy of the data from the bgstat app that I use to record my game plays. The app also the master list of all the games that make up my game collection. And syncs all of that info back onto the bgg website for me.

The point I’m making is this new data file is different to the one I originally got from the app some six or seven years ago. Back then it was just a csv file of the game plays.

Now its a json file that contains all the apps data. So not only game results, list of games, locations, tags, etc.

Luckily using Python as the language of choice for this project means there is a nice json library I can import in to do all the heavy lifting for me to read in and process the json file I have.

Sadly for me the json used by bgstats is not a simple format. It contains arrays within arrays! A nightmare to code to get to the information that I need for this project, even with a json library.

Now if you had asked me before I had started this second attempt at a rewrite that the bits of data analysis I’ve been picking up (different projects) would be of use here. I would of been a bit sceptical.

However using the pandas library I found out I could use pandas to extract these arrays within arrays to get the data I want into a dataframe.

Having the data in a dataframe opens up all sorts of cool data analysis stuff I can do.

So not only can I do the paired comparisons, and top 10 lists, but also produce stats that not even the bgstats app currently does.

A VtM Rivals Deckbuilder #2

Between work and Portal coming to the Switch (see my “the cake is a lie” posts) I’ve not had much chance to work on this project.

However I found a little time yesterday to look at my first hurdle in getting to that sweet sweet card data, getting passed the login screen.

My Python code

The main problem with the login was extracting the hidden token from the page to pass into the login payload.

I know the login is working because I get the “<Response [200]>”. Which means it has been successful.

However when I try and get the database page all I get is the login page back. So now that’s my next hurdle. I’ve logged in, now to get the database page back. Oh and I need to get rid of those two warnings. They may not solve the problem I have but getting rid of them won’t hurt.

See you on the next post when I have something to report.

A VtM Rivals Deckbuilder #1

Temptation got the better of me. Well for the moment.

Let’s face it the odds of this being completed are low. There is a lot working against it. One of the main forces working against it is that I start nights for the next two and a half weeks. Basically my shift is 8pm to 5am. This starts tonight.

In the meantime let’s pretend I’m doing stuff.

So before you start building a deckbuilding app of any kind you need a card database. I know it seems obvious, but still.

There are a handful of options of getting one.

  • An official source – yep I could approach Renegade and ask them if they’d let me have the data. Not very likely, plus there might be a lot of legal paper stuff to sign.
  • Find a third party source – not a reliable option. You just don’t know how accurate it is. Plus it may not be all the cards available.
  • Enter it manual myself! Life is too short for this.
  • Web scrape the data from the Renegade website. This is the option I’ll be going with.

This morning having given in to temptation I started looking at scraping the data I need from the Renegade website.

I’m actually writing this deckbuilder using Pythonista on an iPad. So that’s Python 3.6 and the libraries that come with it. Which is a more limited set than available on a more open platform.

To scrape the data I’m going to be using the requests library.

Which means I have a steep little learning curve to do, along with refreshing my Python. It’s not as if I use this stuff daily, especially web scraping using the requests library.

The first hurdle to overcome before I can get to scraping the data I need is getting passed the login screen. To be able to get to the deckbuilding page you have to be logged in.

So that’s my first bit of focused Python and requests learning.

More soon (hopefully).

Acheron island paradise

Just a quickie I’m still alive!

I thought I’d better post something if only to confirm the opening statement.

Decided to take a “break” from Bioshock for a day or two to play, well start Animal Crossing New Horizons.

I know I’m nearly a year late to the party. But I’m here now. I started my island adventures yesterday, and if you stalk me on Instagram or Twitter amongst chihuahua and coffee/food pictures (not much gaming to photograph at the mo) you will be able to follow my struggles with island life.

It won’t be more than a day or so more before I return to Rapture, and get into a daily routine of visiting Acheron between visits to that dystopian utopia!

If you wish to visit Acheron in a dream you can with the dream address below.

Also during this radio silence I’ve made a start rewriting my python game ranking program.

Once that’s complete I’ll repeat the exercise I did in 2017 of working out what my top 100 games of all time are.

More D&D Coding

After yesterday’s little bit of coding to generate some initiative numbers in python, I decided to do some more coding.

This time it was to generate random D&D characters. Yeah I know there are websites out there that do this already (such as D&D Beyond). And that their results are more complete than mine.

But that’s not the point. This was an exercise to create something that meets my very basic needs.

Here are some examples of the characters it generates at the moment.

At the moment for a half elf it doesn’t do anything clever when choosing which two abilities to give the boost too. It just picks them at random. But ideally it would chose ones that fit nicely with the class. For a human it does the easy to implement +1 to everything.

Next up if I decide to take this further I’ll get it to randomly chose the skill proficiencies, followed by backgrounds. Height and weight might be an interesting exercise as well.

This has been a fun little distraction to avoid final prep for tomorrow’s session. But now I can’t avoid putting it off any more. I need to do those final little bits.

Pre-generating initiative

You know what is über lazy?

Writing four lines of python code to generate random numbers between 1 and 20. Just so I didn’t have to go into the next room, get a d20 and roll it four times and record the results in my notes for Saturdays session!


I run the python script using Pythonista on my iPad, screen grab the results. And there I have it. Enough random numbers to use for the monsters initiative for the session plus any improvised encounters or last minute tweaks/on the fly additions to existing plans.

I do like rolling the monsters initiative before hand. It’s a minor speed up to combat. But one I think is definitely worth doing.

The python code is Mickey Mouse. Very very basic (pun intended). But that’s all that is needed. No need to over complicate things.

Ranking Engine Update

I feel like I have been doing lots to this project this week with not much to show for it.

As you can see I’ve just edged over the 25% mark for the number of pairwise comparisons that I need to do for my game ranking of my collection.

I’m not going to bore you with another “look at my current top 10”. Instead I’m going to bore you with my top 10 worker placement games based on my current rankings of games. 

What this really show cases is the start of the next stage of my stats engine. After a bit of behind the scenes rewriting of code, I’ve started a gui front end (see below). It’s an ugly, not designed gui. I’ll sketch something out over the weekend. 

But basically I can select a game mechanic and find all the games in my collection that have that mechanic. 

It then takes those results, and finds out how I’ve ranked them, followed by printing out the top ten. 

So before I add categories, designers and publishers I need to sort out the gui. That’s the major effort. 

Once that’s been done I’ll expand the stats to look at the bgg hotlist, followed by the bgg all time top 100. 

I then have more stuff on the road map. Wait did I just type that? That almost makes me sound like professional and I’ve planned it. But in reality I haven’t and I’m not. I’m making things up as I go along. I have ideas that I really should write down before they are lost. In away these posts are acting as my dev notebook. Well hopefully gentle reminders. 

Hopefully you can see things are progressing both code wise and rankings wise. I also hope you are finding the verses posts interesting. Which were a surprise spin off from this project.

Anyway I’ll see you in my next post.

Ranking – Progress Update

So this may not look much. BUT I have a ranking engine for my game collection!

Yep I now have a python script that creates match ups from my collection, and records the results. As you can see the script also gives me the depressing information that in total I will have to do a lot of pairwise comparisons. 23005 to be exact, based on a game collection of 215 games (it’s a couple more than that now, but that updated list hasn’t been imported into the database yet). The formula I used to work this out was totalNumTests = N(N-1)/2.

So two thirds of the way there. I now need to create my lists/stats engine. Or get an initial version done. But considering how many pairwise comparisons I have to do, it’s going to be a while before you see the fruits of that labour. However you may see the odd post that discusses one of the pairwise comparisons. Why did I rank game A better than game B, and asking for which one you’d choose?

To Do List:

  • Update script for populating to database with games to allow updates to the collection.
  • Lists/Stats Engine
  • Long term: create a GUI front end

Boardgaming and Coding

This post has taken me a day or three to write. Hence why you haven’t been bored by me.

Plus my only other gaming has been the enrichment session for my students since the last post. Which I don’t talk too much about. But do remind you from time to time that I do. I will say about the one at the start of the week is that I introduced a student to Star Realms and deckbuilding. We spent the session playing that game. It was just “one more game” from the student at the end of each one. Plus when I told the student there was an app. They were going to go on Steam to buy it that evening. So I think that was a success. It’s nice to see a student enjoy a game so much they get it for themselves.

Now on with the post and the words I’ve been struggling to write…

Everyone, and I mean everyone whose anyone in the boardgame social media world has done their top 100 games of all time or their top ten this or top five that. From time to time you also get a similar thing on Instagram (see screen grab below).


I’ve tried those sort of posts myself the odd time in the past. I’m not a big fan of them in reality. I kinda see them as click bait. Which will mean this post and the project I’m going to talk about will not make much sense.

These “my top 100 games (insert year here)” lists kind of interest me. Mainly how do they come up with their list? What process do they use? Now that I have started recording my game plays could I produce a similar list based on the number of plays? Would that be a fair reflection of how much I like the game? Is that a good way to rank games I like? I can see flaws in doing it this way.

Just before Christmas there was a website that went up that tried to help you rank the games in your collection. You uploaded a csv (comma separated file) of your collection. Then it would start a series of random game match ups from your collection, where you decide which is the winner. Eventually after lots of these match ups it ranks the games in your collection.

That process is known as pairwise comparison. And allows you to determine a relative order for a group of items. Which in our case is board games.

So I’ve started a project to create my own little ranking program. I’m using Python 3 to write this little project. Mainly because it is quick to prototype with, has some great libraries for doing stuff like accessing a database, web scraping, reading csv files etc. Plus I need to keep my Python skills fresh.

My initial question for this whole project is “What are my top 100 favorite games?” After this has been completed I will then be able to ask other questions such as “What are my top 5 drafting games?” And I’m sure with the data in place other questions will be asked, and expanded on.

But what have I done so far for this project? Well we all know there are not enough hours in the day to do everything. You can’t be lazy, watch tv, play board games, write a blog, hold down a full time job and do other stuff! In other words I did nothing until recently.

Here is what I have done so far…

I started off with a csv file of my game collection downloaded from the bgg website. Which I then tidied up in Excel. This was mainly removing entries that weren’t games but expansions. In data science terminology I was cleaning my data!

I then wrote a Python program to read in the cleaned up data and put it into a sqlite3 database. For each game in the file the program uses the bgg api to get its details. The program then extracts from the returned results the missing information that I want to use later, such as genre, mechanic, designer, etc. Once it has done that the game is added to the sqlite3 database.

This means I now have an sqlite3 database that holds my game collection on a table with the extra info that I have always felt was missing from the csv bgg provide you with. I can now interrogate the sqlite3 database and get a list of all my dice games, or all the games I own by Eric Lang.

I am currently working on a new program in this project which is the the actual ranking engine.  So far this program connects to the sqlite3 database, finds out the number of games I have and generates two random numbers, and then pulls the games details matching those two numbers. You then get something like the following image:

At the moment I can type something in, and the program will keep coming up with new match ups. However at the moment I do nothing with the answer. That’s the next stage of this ranking engine. I need to store the result in a new table. I’m just getting my head round what the best way is to store the information. Because I am using a two dimensional array (well list in Python, although I might use the numpy library to give me a real array) to store the results, I think the best way to store that is with a blob field type. Which means I will have to serialize the data in the array before storing it in the database.

Once the ranking engine has been finished. It’s onto my data visualization engine. This will be the program that pulls off the results and give me like my top 100 games, or top 10 deckbuilders. I also plan to have it also be able to tell me how many of the bgg hotlist I have played or own.

The nice thing about this project is I can also share the badly written code with my students. So they will have examples of how to connect to a sqlite3 database, or read in a csv file, use a web api and use the xml libraries.

So now that I have bored you with an “overview” of my little project. I will threaten you with a more detailed write up once it is completed.