A strategy is
A single function that makes
Ten thousand choices.
This contest is completely optional!
Download a blank
hog_contest.py file and simple tests for correct formatting
as a zip archive. Type
python3 ok to run the provided tests.
hog_contest.py file containing a function called
final_strategy and a
python3 ok --submit
To make things more interesting, we've introduced a new rule (Time Trot). Here is the entire set of rules:
Pig Out. If any of the dice outcomes is a 1, the current player's score for the turn is 1.
- Example 1: The current player rolls 7 dice, 5 of which are 1's. They score 1 point for the turn.
- Example 2: The current player rolls 4 dice, all of which are 3's. Since Pig Out did not occur, they score 12 points for the turn.
Free Bacon. A player who chooses to roll zero dice scores one more than the largest digit in the opponent's total score.
- Example 1: If the opponent has 42 points, the current player gains 1 + max(4, 2) = 5 points by rolling zero dice.
- Example 2: If the opponent has 48 points, the current player gains 1 + max(4, 8) = 9 points by rolling zero dice.
- Example 3: If the opponent has 7 points, the current player gains 1 + max(0, 7) = 8 points by rolling zero dice.
Swine Swap. After points for the turn are added to the current player's score, if both scores are larger than 1 and either one of the scores is a positive integer multiple of the other, then the two scores are swapped.
- Example 1: The current player has a total score of 37 and the opponent has 92. The current player rolls two dice that total 9. The opponent's score (92) is exactly twice the player's new total score (46). These scores are swapped! The current player now has 92 points and the opponent has 46. The turn ends.
- Example 2: The current player has 91 and the opponent has 37. The current player rolls five dice that total 20. The current player has 111, which is 3 times 37, so the scores are swapped. The opponent ends the turn with 111 and wins the game.
Time Trot. A turn involves a player rolling dice, and each turn is numbered, starting from 0. If a player chooses to roll a number of dice
n % 8 == k, then that player gets an extra turn immediately after the current turn. However, a player cannot get an extra turn immediately after an extra turn.
- On Turn 0, Player 0 rolls 5 dice that total 19. The score is 19 to 0.
- On Turn 1, Player 1 rolls 1 die that comes up 4. The score is now 19 to 4, and Player 1 gets an extra turn.
- On Turn 2, Player 1 rolls 2 dice that total 6. The score is 19 to 10. Player 1 does not get an extra turn becuase Player 1 cannot get two extra turns in a row.
- On Turn 3, Player 0 rolls 3 dice and pigs out, causing a Swine Swap. The score is now 10 to 20, and Player 0 gets an extra turn.
- On Turn 4, Player 0 rolls (...)
- Note: As with past contests, a strategy must be a deterministic function of the players' scores and cannot track the turn number or previous actions. See complete rules below.
Each submitted strategy will play against all other submissions. We will exactly compute the expected win rate for each player, so that the outcome of this tournament will be determined by strategy alone and not the roll of the dice. A submission scores a match point each time it has an expected win rate above 50.0001%. We will rank submissions based on the number of matches they won. Ties count as losses.
The top three submissions will earn the following:
- First place gets 3 points of extra credit.
- Second place gets 2 points of extra credit.
- Third place gets 1 point of extra credit.
Winners will also be publicly recognized in future iterations of 61A!
Some additional contest rules:
- The contest may be entered individually or in pairs. Two people submit a single entry (make sure you register each other as partners on okpy.org). Each person in the course can be associated with at most one entry.
- Calling your
final_strategyfunction on every possible pair of scores should take less than 10 seconds. The provided tests check for this.
- All strategies must be deterministic, pure functions of the current player scores! Non-deterministic strategies or strategies based on the history of the game will be disqualified.
We expect everyone to play fair. Attempts to "game the system" will not be tolerated.
If you have any questions about the rules, don't hesitate to post on Piazza.