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.

Submit a hog_contest.py file containing a function called final_strategy and a TEAM_NAME.

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 the number of 1's rolled. Pig Out may award a maximum of 11 points minus the number of dice rolled on a turn.

    • Example 1: The current player rolls 7 dice, 5 of which are 1's. They score min(11 - 7, 5) = 4 points for the turn.
    • Example 2: The current player rolls 5 dice, 3 of which are 1's. They score min(11 - 5, 3) = 3 points from Pig Out. Hogtimus Prime (described below) will increase the score for the turn to 5.
    • Example 3: 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.
  2. 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.
  3. Hogtimus Prime. If a player's score for the turn is a prime number, then the turn score is increased to the next larger prime number. For example, if the dice outcomes sum to 11, the current player scores 13 points for the turn. This boost only applies to the current player. Note: 1 is not a prime number!
  4. Hog Wild. If the sum of both players' total scores is a multiple of seven (e.g., 0, 7, 14, 21, 35), then the current player rolls four-sided dice instead of the usual six-sided dice.
  5. Swine Swap. After the turn score is added, if one of the scores is double 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 current player's new total score (46) is half of the opponent's score. 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 55. The current player rolls five dice that total 17, a prime that is boosted to 19 points for the turn. The current player has 110, so the scores are swapped. The opponent ends the turn with 110 and wins the game.
  6. 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 14 points and Player 1 has 42 points, with Player 0 to roll. Player 0 uses Free Bacon and Hogtimus Prime to get 7 points; the scores are now 21 to 42, triggering a Swine Swap. The final score for this turn is 42 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 42.

Player 0 uses Pork Chop as well, switching the scores back to 42 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 1 receives 1 points for a final turn score of 42 to 22.

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!

The contest will use exactly the same Hog special rules as Project 1.

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 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.