King of the Cards
Code available here!
In this King of the Hill challenge, you must write a bot that can play Crazy Eights. This is a card game often played by children, in which the objective is to empty your hand.
How to Play
The game of Crazy Eights is deceptively simple. At the beginning of the game, each player gets dealt a hand of cards (in this case eight), with the remaining cards placed in the middle of the table as the draw pile. The top card is then placed face up and serves as the beginning of the discard pile. Then, each player can discard one card per turn if that card has a matching suit or rank with the top card on the discard pile. They may also play an 8, which allows them to change the effective suit of the 8 and therefore the suit the next player must follow. The played card then becomes the top card. If the player does not have any matching cards, they must draw from the draw pile until they get a matching card and play that. If they exhaust the draw pile, play passes to the next player. Players may draw at any time, even if they have playable cards (which does not count as a turn).
For example, if 6♣ is played, the next player:
- Can play a 6 of any suit
- Can play any club
- Can play an 8 (and then must declare a suit)
- Can draw and continue their turn.
If the draw pile runs out, then the discard pile (except for the top card) is shuffled and becomes the new draw pile.
The game ends once a player runs out of cards, in which case they are declared the winner. (This differs from normal Crazy Eights, and is included to make this game a bit simpler.)
Bots must be written in Python. Bots will have access to the
kotc module, which supplies these classes:
KOTCBot, which bots must extend
Card, which represents a card
Rank, enums representing the suit and value of a card
Bots must implement a
play method, which takes as input a
Card representing the top card on the discard pile. This method must return a
Card within that bot's
hand. If the returned
Card is not in the bot's
hand that bot is disqualified. (I will leave a comment on it with information about the state of the game when it happened.) However, if the
Card is an
Eight then only the
rank will be checked against the bot's
hand. If the bot has no playable cards in its hand, the
play method will NOT be called and the controller will automatically draw cards on behalf of the bot and add them to its
hand. The bot should NEVER modify its
hand! This will be done by the controller. The
play method may also return
False, which will cause its turn to be skipped.
Bots will compete against each other in matches of two, in an elimination-style tournament bracket. The winner will advance onwards, and the loser will be
This class is the actual bot.
Methods and properties: (Do NOT override any of these in your bot)
draw: When called, this function draws a card from the pile and adds it to the bot's hand. It also returns the card drawn.
hand: This property is a list of
Cards representing the bot's hand.
arena: This property is the
KOTCArenainstance the bot is playing in.
This class is accessible through the
arena property of the
Bot. It has three functions available to the bots:
handSizes: Returns a list of the lengths of the hands of the other bots
discardSize: Returns the size of the discard pile
drawSize: Returns the size of the draw pile
Card class represents a card, and takes a
Rank when constructed. This class must be returned by the bot's
play method. Its suit and rank can be accessed through their respective properties.
all: This classmethod takes no parameters and returns a 52-item list of all possible card combinations.
Note: All enumeration members are UPPERCASE.
Members of this enum:
Members of this enum:
This bot just plays any available card, without using eights.
import kotc class ExampleBot(kotc.KOTCBot): def play(self, discard): for card in self.hand: if card.suit == discard.suit or card.rank == discard.rank: return card