In this competition, you will be tasked to develop an algorithm in Python to play the card game Big Two. In each match, your algorithm will be matched up against three other teams’ algorithms that will play four games of Big Two, accumulating points to decide the match’s overall rankings.
You can submit your team’s algorithm file on your team’s dashboard on the competition site. During the prototyping phase, you may submit an algorithm as many times as you want. Upon reaching the competition phase, the most recently submitted algorithm will be used as your final algorithm.
Cards will be represented as a string, with the first character being their rank and the second character being the first letter of their suit. A rank of ten is represented with the character T. For example, KS is the king of spades, 5H is the five of hearts, TD is the ten of diamonds.
Your algorithm is to be implemented in the form of a method called getAction() in a predefined stateless Algorithm class. This method will be called each time it is your turn, and will provide you with a MatchState object containing relevant info about the current match, including the turn history, the number of cards each player has, your current hand and current best trick in play. On each call of getAction(), your algorithm is to return a valid list of cards that you’ll play for your trick (or an empty list if you wish to pass) and a string that will be passed in to the next call of getAction() which you can use to store data between calls to getAction().
<aside> 💡
Use of Python’s json library is permitted and may be used to serialize complex data into a string.
</aside>
A new Algorithm object will be instantiated each turn from this class so please do not implement any attributes to store data. Creation of helper methods is permitted. Please do not change the name of the class or signature of the getAction() method as this will cause your algorithm to throw an error.
Below is the boilerplate implementation of the Algorithm class. In this basic form, this implementation will pass every turn.
from classes import *
class Algorithm:
def getAction(self, state: MatchState):
action = [] # The cards you are playing for this trick
myData = state.myData # Communications from the previous iteration
# TODO Write your algorithm logic here
return action, myData
The MatchState object passed to your getAction() method contains all information about the current match. Its attributes are:
myPlayerNumber |
The player number of your algorithm. Each player in the match is given a unique player number between 0 and 3 inclusive. This will be used to identify which moves were performed by which players and access player information. |
|---|---|
players |
A list of Player objects that stores some basic information about each player. Each player in the list is indexed by their player number. |
myHand |
A list of all the cards currently in your hand |
toBeat |
A Trick object representing the current best trick in play that you must beat if you wish to play a trick of your own. If you are the starting player in a trick, this value will be None |
matchHistory |
A list of gameHistory objects that store information about the games that have been played and the game that is currently being played. The games in the list are ordered from oldest to newest such that the last gameHistory object in the list always represents the game currently being played. |
myData |
A string that was returned by the previous call to getAction(). This can be used to communicate data and states between iterations. |
The Player class stores information about a player. Its attributes are: