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 point is to lose all your cards by putting them on the pile, a card that is put on the pile must be equal or higher than the top card of the pile. If you have no card to put on the pile you must take the entire pile.
- There are always three cards in your hand, if you have less than three you must draw enough cards from the deck to get three again. After the deck is finished no more cards are drawn.
- There are three downwards facing cards and three upwards facing cards on the table. You cannot play them until your hand is finished. You cannot look at a downward facing card before playing it.
- Before you start you can exchange cards from your hand with the upwards facing cards on the table.
- You can put a two on top of everything, it is the restart card.
- You can put a five on top of everything, it is the reverse card, meaning that in the next turn the opponent must put a card equal or lower than five.
- You can put a ten on top of everything and it burns the pile, and you get to put out the first card in the new pile.
- You can put out more than one card at a time as long as they have the same rank.
- If there are four cards with the same rank at the top of the pile then the pile is removed.
- If you have no card that you can put on top of the pile then you may draw the top card of the deck and put on the pile, if it is a legal move then you do not have to take the pile.
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.