Optional Contest: Hog Strategy

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

Instructions

This contest is completely optional!

Download a blank final_strategy.py file and simple tests for correct formatting as a zip archive. Type python3 ok to run the provided tests.

Submit a final_strategy.py file containing a function called final_strategy and a PLAYER_NAME.

python3 ok --submit

The contest ends on Tuesday, February 23rd at 11:59 PM. We will use your latest submission before this date to determine the final results of the contest.

You can use the compare_strategies.py file to compute the exact win rate between any pair of two strategies using our server. Depending on server load, we may rate-limit or disable this functionality at any point, so consider re-implementing this file yourself locally!

Your strategy can run as long as you want. If ok complains that you're exceeding the time limit, run it with the flag --timeout 0 to disable the time limit.

Leaderboard

The leaderboard can be found here. It will continuously update as the contest progresses. Go to the server log to see the status of your submission.

Contest rules

Teams can have one or two people. Each person can only be part of one team.

Each submitted strategy will play against all other submissions. The player to go first will be determined by a flip of a fair coin. 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 or flip of a coin. A submission scores a match point each time it has an expected win rate strictly 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.

Game rules

To make things more interesting, we've introduced a new rule (Time Trot) in addition to the original set of special rules. Here are the full set of rules:

  • Sow Sad. 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 Sow Sad did not occur, they score 12 points for the turn.
  • Piggy Points. A player who chooses to roll zero dice scores k+3 points, where k is the digit in the squared opponent’s score that has the lowest value.
  • Example 1: The current player rolls zero dice and the opponent has a score of 4. 4 ** 2 = 16, so the current player will receive 3 + 1 = 4 points.
  • Example 2: The current player rolls zero dice and the opponent has a score of 10. 10 ** 2 = 100, so the current player will receive 3 + 0 = 3 points.
  • Example 3: The current player rolls zero dice and the opponent has a score of 94. 94 ** 2 = 8836, so the current player will receive 3 + 3 = 6 points.
  • Example 4: The current player rolls zero dice and the opponent has a score of 0. 0 ** 2 = 0, so the current player will receive 3 + 0 = 3 points.
  • More Boar. First, the points for the turn are added to the current player’s score. Then the current player takes another turn if the leftmost digit of the current player's score is smaller than the leftmost digit of the opponent's score and the second leftmost digit of the current player's score is smaller than the second leftmost digit of the opponent's score. If either score is only a singular digit, assume it has a 0 in front of it (e.g. 1 -> 01, 6 -> 06). You may not assume that the scores are under 100. The More Boar calculation should be done on the current player's score after the points from the current turn are added.
  • Example 1: After the points are added, the current player has a score of 21 and the opponent has a score of 43. Since 2 < 4, and 1 < 3, the current player takes another turn.
  • Example 2: After the points are added, the current player has a score of 32 and the opponent has a score of 33. Since the current player's leftmost digit is not strictly smaller (3 = 3), the current player does not take another turn.
  • Example 3: After the points are added, the current player has a score of 7 and the opponent has a score of 10. Since the current player's second leftmost digit is not smaller (7 > 0), the current player does not take another turn.
  • Example 4: After the points are added, the current player has a score of 21 and the opponent has a score of 43. Like in Example 1, the current player takes another turn. If the current player then rolls a 1 and now has a score of 22, More Boar activates again and the current player takes yet another turn.
  • 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 k on turn n, and n % 8 == k, then that player gets an extra turn immediately after the current turn. However, a player cannot get an extra turn as a consequence of Time Trot immediately after an extra turn, though they can get an extra turn as a consequence of More Boar. Furthermore, players will roll 8-sided dice on all extra turns (including those produced from More Boar).

Submission rules

  • 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 not behave as expected when submitted and will likely not do well.
  • You may use any libraries (such as NumPy, TensorFlow, or anything else you can think of) in your submission.

If you have any questions about the rules, don't hesitate to post on Piazza.

Happy coding!