Making Twitter Trading Card Game

twitter-trading-card-game-ttcg

I think it was about a year ago that I added this to my game ideas note in Evernote:

  • Randomly assign all twitter users some pokemon cards (by twitter id), allow trading by hashtag

Well after a year of having life get in the way, realising that I didn’t know how to use php and having to learn it, switching my hosting, and playing weird GameCube shit, here we are.
Three weeks ago I left my old job, and with a week off before starting at my new place I decided to take on the task of finishing what by then was called #ttcg, or Twitter Trading Card Game, and on the 11th of September 2016 it was set live.

So what exactly is #ttcg?

To be honest I think that note I made a year ago does a pretty good job of covering it. Once you know what cards you have it’s just a case of sending a tweet that looks something like this:

@BulchyC POK79 #ttcg

The site takes care of the rest.

So how does it work?

When you log into the site at chrisbulch.com/ttcg with your twitter account the site gets access to your unique user id (I guess this exists so that you can change your account name without it causing problems, as your user id always remains the same), from there it checks your id to see if it already has cards listed in a MySQL database.
If you’re listed in the database, then great! The site loads in all the cards you have. If your id isn’t found in the database however, then your twitter user id is used to seed a random number generator, which then spits out cards for you.
This is a nice set up as using a seeded RNG means that the site only needs to save a user in the database once they’ve sent or received a card, and if someone searches to see the cards a user who hasn’t played yet has, they’ll pull up the same cards that the user will if they ever decide to log in, all without the site needing to keep track of them.

twitter-trading-card-game-cards

Ok so we’ve assigned everyone a bunch of cards, I decided on 24 each to start with, partly because it seemed small enough for people to easily remember more or less what they have, but big enough to get some variety, and partly because it happened to fit nicely into the three column layout I used for the cards.
So now what we need to do is figure out how to trade. I ended up setting up a cron script to run once every 5 minutes (I would’ve liked it to be more frequent but then you start to run into issues with rate limiting on twitter’s API), this searches twitter for “#ttcg”, which happened to be in use already by some Japanese cinema chain but fuck ’em I guess.
So once we have a tweet containing the #ttcg hashtag we need to look for two other things: a recipient and a card, the recipient is easy, it just looks for the first bit of text following an ‘@’, we can do a similar thing for the card by just pulling whatever follows ‘POK’.

Once we have our tweet containing a recipient, a card and the hashtag, it’s just a case of removing the card number from one user in the database and adding it to the other (after a TON of logic of course).
And that’s it.

I did decide to throw in a little something extra when I saw a fun thing I could do though.
Part way through implementing the twitter user id stuff I realised that I could check those ids against whatever the hell list I felt like. So what could be funnier than actually taking a game away from those annoying cunts on twitter that are always accusing people of trying to take their games away?
So a quick shitlist later (the cron job that runs once a day is actually called updateShitlist) and all of those people are blocked from trading, with only one card assigned to them, as a reminder that they need to quit their macho bullshit 😉

twitter-trading-card-game-banned