A strategy is
A single function that makes
Ten thousand choices.


This contest is completely optional!

A blank hog.py file and simple tests for correct formatting can be downloaded as a zip archive. Type python3 ok to run the provided tests.

Submit a hog.py file containing a function called final_strategy.

python3 ok --submit

Game rules

To spice up the game, we've introduced a new rule (Pork Chop) in addition to the rules from Project 1. Here is the entire set of rules:

  1. Pig Out. If any of the dice outcomes is a 1, the current player's score for the turn is 0.
  2. Piggy Back. When the current player scores 0, the opposing player receives points equal to the number of dice rolled that turn.
  3. Free Bacon. A player who chooses to roll zero dice scores one more than the largest digit in the opponent's total score.
  4. Hog Wild. If the sum of both players' total scores is a multiple of seven (e.g., 14, 21, 35), then the current player rolls four-sided dice instead of the usual six-sided dice.
  5. Hogtimus Prime. If a player's score for the turn is a prime number, then the turn score is increased to the next largest prime number. For example, if the dice outcomes sum to 19, the current player scores 23 points for the turn. This boost only applies to the current player. Note: 1 is not a prime number!
  6. Swine Swap. After the turn score is added, if the last two digits of each player's score are the reverse of each other, the players swap total scores.
  7. Pork Chop (New!). A player may choose to roll -1 dice, which scores no points for the turn, but swaps both players' scores (similar to Swine Swap). This move can only be used once by each player; every subsequent roll of -1 will be treated as if that player rolled 10 dice instead.

    Note: If Swine Swap would trigger immediately after Pork Chop, that swap doesn't take effect! There can be at most one swap per turn.

A sample game: Player 0 has 16 points and Player 1 has 12 points, with Player 0 to roll. Player 0 uses Free Bacon and Hogtimus Prime to get 5 points; the scores are now 21 to 12, triggering a Swine Swap. The final score for this turn is 12 to 21.

Player 1 uses Pork Chop and rolls -1 dice, triggering a swap. Because a swap can only happen once per turn, the scores are not immediately switched back. The scores are now 21 to 12.

Player 0 uses Pork Chop as well, switching the scores back to 12 and 21.

Player 1 attempts to use Pork Chop again, but since -1 has already been rolled, Player 1 rolls 10 dice instead. This results in a Pig Out and Player 0 receives 10 points via Piggy Back, for a final turn score of 22 to 21.

Contest rules

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:

  1. First place gets 3 points of extra credit
  2. Second place gets 2 points of extra credit
  3. Third place gets 1 point of extra credit

Winners will also be publicly recognized in future iterations of 61A!

Some additional 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 only be associated with at most one entry.
  • 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.
  • Calling your final_strategy function on every possible pair of scores should take less than 10 seconds. The provided tests check for this.