Einar Egilsson

Idiot cardgame (a.k.a. Shithead)

Posted: Last updated:

UPDATE 20.10.2010: A few days ago I launched a completely revamped version of this game, with better cards, animated moves and just a lot better in every way. That means that this blog post is completely out of date! Play the new version at https://cardgames.io/idiot/ or at https://cardgames.io/shithead/. Or, you can play the original version, the one that this blog post is talking about at http://einaregilsson.com/idiot/.

Original blog post follows:

The last few weeks my hobby project has been creating a cardgame in Javascript. I've always wanted to create a cardgame and I decided to use simple Javascript so I could make it available online since no-one wants to bother to download small games. I figured there were thousands of blackjacks and solitaires out there so I decided to create my favorite cardgame, Idiot. After googling around I found that there was a Wikipedia page about it under the name Shithead which listed all sorts of different variations. My variation uses the rules that I've usually used in real life:

The game can be played at the url http://einaregilsson.com/idiot/. As for the implementation, don't expect any animation or fancy stuff. You simply choose the cards you want to put out and press the Play selected cards button. When the computer is playing the cards simply disappear from its hand and show up on the pile. However there is a small delay between each move by the computer so you can see when it puts out two or more cards and when it's drawing cards. As for the rule about drawing a card off the top of the deck when you have to take the pile, that is done automatically. You simply press the Take the pile button and you will see a new card appear at the top of the pile (given that the deck is not empty). If the move is legal then the pile will stay, if it is not legal you will get the whole pile in your hand.

The game is implemented in two files, cards.js and idiot.js. Cards.js is a generic library that has a base class for a card container and concrete classes for a hand, deck and card, it could easily be re-used for any card game. Idiot.js is the game itself, it works allright, although there are a lot of edge cases that could be added to the computer player to make it smarter. The code is pretty heavily commented so it should be easy to follow should anyone want to extend the game or use the library for something. The game files are licensed under a Creative Commons Attribution license and so can be used for pretty much anything, they have been tested on the latest versions of all the major browsers. Please leave any error reports or suggestions as comments on this page.


If you read this far you should probably follow me on Twitter.