Optional Contest: Hog Strategy
A strategy is
A single function that makes
Ten thousand choices.
Results are in! Scroll down to the bottom to see the rankings.
Instructions
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 two extra rules (Ham Hijinks and Pig Fest) in addition to the rules from Project 1. Here is the entire set of rules:
- Pig out. During a turn, if one of the dice that a player rolls has an outcome of 1, the player receives a score of 1 for the entire turn.
- Free bacon. A player who chooses to roll zero dice scores one plus the largest digit in the opponent's score.
- 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.
- Swine Swap. At the end of each turn, if the last two digits of Player 0's score are the reverse of the last two digits of Player 1's score, the players' score will be swapped.
Ham Hijinks (New!). A player may choose to roll -1 dice, which scores 1 point for the turn and exchanges the dice. If the total number of times any player has exchanged the dice during the game is odd, then four-sided dice are rolled when six-sided dice would normally be rolled, and vice-versa. That is, players will roll four-sided dice unless Hog Wild is in effect, in which case they will roll six-sided dice.
A sample game: Player 0 rolls -1, exchanging the dice: the score is 1 to 0. Next, Player 1 rolls 2 dice; these are four-sided dice due to the previous exchange, and earn (let's say) six points: the score is 1 to 6. Player 0 rolls 4 six-sided dice (because of Hog Wild), earning (let's say) 10 points: the score is 11 to 6. Player 1 rolls -1, exchanging the dice again: the score is 11 to 7. Player 0 would next roll six-sided dice because of the previous exchange.
Note: Players do not know how many dice the opponent chose to roll and thus cannot be certain how many times the dice have been exchanged. The values bound to the global names
four_sided
andsix_sided
will not indicate what dice are being used.Pig Fest (New!). If a player Pigs Out (see first rule) multiple turns in a row, the player receives a score multiplier.
Let
consecutive_pig_outs
be the number of times a player has gotten Pig Out consecutively; then the score multiplier is equal tomax(1, consecutive_pig_outs
).The maximum score multiplier is capped at 3. Once the player completes a turn without Pig Out, that turn's score is multiplied by the score multiplier. For example, if a player's score multiplier is 3, and they score 12 on their next turn, their final turn score is
12 * 3 = 36
.After a score multiplier is used, the number of consecutive Pig Outs is set back to 0 (i.e. the score multiplier resets).
Players do not share a score multiplier. One player's Pig Outs will not affect the other player's score multiplier.
Contest rules
Each submitted strategy will play against all other submissions. For each pair of submissions, we will simulate 9 games with unbiased six-sided and four-sided dice. The submission that wins the most number of games is awarded one point for that match.
Note: the games will use random dice! There is an element of change to this game; it is a dice game after all!
In each game, we will randomly choose which submission is Player 0 and which submission is Player 1.
We will rank submissions based on the number of matches they won. We will break
ties by comparing each submission's exact win rate against an always_roll(5)
strategy.
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
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.
- Strategies are allowed to be non-deterministic (i.e. allowed to return random outputs). However, when computing exact win rates for tie-breaking, we will only compute your exact win rate once.
- Calling your
final_strategy
function on every possible pair of scores should take less than 10 seconds. The provided tests check for this.
Results
The results are in! Congratulations to top three contestants:
- Evin Yang (15 - 1, 76% against
always_roll(5)
) - Boyuan Yu (12 - 4, 71% against
always_roll(5)
) - Minsu Kim (12 - 4, 62% against
always_roll(5)
)
Rankings
Each entry was assigned a random number for anonymity.
Ranking | Entry number | Wins | Losses | Winrate against always_roll(5) |
---|---|---|---|---|
1 | 98 | 15 | 1 | 75.9% |
2 | 27 | 12 | 4 | 70.9% |
3 | 74 | 12 | 4 | 62.3% |
4 | 43 | 12 | 4 | 58.3% |
5 | 79 | 11 | 5 | 50.1% |
6 | 36 | 9 | 7 | 66.5% |
7 | 20 | 9 | 7 | 53.3% |
8 | 59 | 9 | 7 | 38.2% |
9 | 39 | 8 | 8 | 54.1% |
10 | 51 | 7 | 9 | 49.1% |
11 | 42 | 7 | 9 | 48.5% |
12 | 46 | 6 | 10 | 51.8% |
13 | 86 | 6 | 10 | 50.9% |
14 | 7 | 5 | 11 | 53.9% |
15 | 47 | 5 | 11 | 46.9% |
16 | 6 | 3 | 13 | 50.0% |
17 | 76 | 0 | 16 | 7.8% |
Matches
Entry 0 | Entry 1 | Entry 0's wins | Entry 1's wins |
---|---|---|---|
59 | 27 | 3 | 6 |
59 | 7 | 7 | 2 |
59 | 79 | 4 | 5 |
59 | 51 | 3 | 6 |
59 | 98 | 3 | 6 |
59 | 47 | 6 | 3 |
59 | 46 | 2 | 7 |
59 | 74 | 6 | 3 |
59 | 76 | 9 | 0 |
59 | 86 | 6 | 3 |
59 | 42 | 4 | 5 |
59 | 6 | 5 | 4 |
59 | 36 | 4 | 5 |
59 | 20 | 5 | 4 |
59 | 39 | 5 | 4 |
59 | 43 | 7 | 2 |
27 | 7 | 7 | 2 |
27 | 79 | 5 | 4 |
27 | 51 | 6 | 3 |
27 | 98 | 2 | 7 |
27 | 47 | 7 | 2 |
27 | 46 | 8 | 1 |
27 | 74 | 4 | 5 |
27 | 76 | 9 | 0 |
27 | 86 | 7 | 2 |
27 | 42 | 6 | 3 |
27 | 6 | 6 | 3 |
27 | 36 | 5 | 4 |
27 | 20 | 4 | 5 |
27 | 39 | 4 | 5 |
27 | 43 | 6 | 3 |
7 | 79 | 3 | 6 |
7 | 51 | 2 | 7 |
7 | 98 | 1 | 8 |
7 | 47 | 3 | 6 |
7 | 46 | 2 | 7 |
7 | 74 | 3 | 6 |
7 | 76 | 7 | 2 |
7 | 86 | 6 | 3 |
7 | 42 | 5 | 4 |
7 | 6 | 5 | 4 |
7 | 36 | 4 | 5 |
7 | 20 | 5 | 4 |
7 | 39 | 3 | 6 |
7 | 43 | 4 | 5 |
79 | 51 | 6 | 3 |
79 | 98 | 3 | 6 |
79 | 47 | 5 | 4 |
79 | 46 | 5 | 4 |
79 | 74 | 2 | 7 |
79 | 76 | 5 | 4 |
79 | 86 | 6 | 3 |
79 | 42 | 5 | 4 |
79 | 6 | 6 | 3 |
79 | 36 | 7 | 2 |
79 | 20 | 6 | 3 |
79 | 39 | 4 | 5 |
79 | 43 | 3 | 6 |
51 | 98 | 4 | 5 |
51 | 47 | 5 | 4 |
51 | 46 | 4 | 5 |
51 | 74 | 2 | 7 |
51 | 76 | 7 | 2 |
51 | 86 | 6 | 3 |
51 | 42 | 4 | 5 |
51 | 6 | 7 | 2 |
51 | 36 | 5 | 4 |
51 | 20 | 1 | 8 |
51 | 39 | 3 | 6 |
51 | 43 | 4 | 5 |
98 | 47 | 5 | 4 |
98 | 46 | 6 | 3 |
98 | 74 | 4 | 5 |
98 | 76 | 9 | 0 |
98 | 86 | 5 | 4 |
98 | 42 | 7 | 2 |
98 | 6 | 5 | 4 |
98 | 36 | 6 | 3 |
98 | 20 | 7 | 2 |
98 | 39 | 7 | 2 |
98 | 43 | 7 | 2 |
47 | 46 | 5 | 4 |
47 | 74 | 3 | 6 |
47 | 76 | 9 | 0 |
47 | 86 | 6 | 3 |
47 | 42 | 4 | 5 |
47 | 6 | 4 | 5 |
47 | 36 | 6 | 3 |
47 | 20 | 4 | 5 |
47 | 39 | 3 | 6 |
47 | 43 | 4 | 5 |
46 | 74 | 4 | 5 |
46 | 76 | 6 | 3 |
46 | 86 | 6 | 3 |
46 | 42 | 4 | 5 |
46 | 6 | 6 | 3 |
46 | 36 | 3 | 6 |
46 | 20 | 3 | 6 |
46 | 39 | 2 | 7 |
46 | 43 | 3 | 6 |
74 | 76 | 9 | 0 |
74 | 86 | 4 | 5 |
74 | 42 | 9 | 0 |
74 | 6 | 5 | 4 |
74 | 36 | 6 | 3 |
74 | 20 | 4 | 5 |
74 | 39 | 5 | 4 |
74 | 43 | 4 | 5 |
76 | 86 | 2 | 7 |
76 | 42 | 2 | 7 |
76 | 6 | 2 | 7 |
76 | 36 | 1 | 8 |
76 | 20 | 0 | 9 |
76 | 39 | 1 | 8 |
76 | 43 | 1 | 8 |
86 | 42 | 5 | 4 |
86 | 6 | 5 | 4 |
86 | 36 | 5 | 4 |
86 | 20 | 2 | 7 |
86 | 39 | 6 | 3 |
86 | 43 | 2 | 7 |
42 | 6 | 3 | 6 |
42 | 36 | 4 | 5 |
42 | 20 | 6 | 3 |
42 | 39 | 6 | 3 |
42 | 43 | 4 | 5 |
6 | 36 | 4 | 5 |
6 | 20 | 4 | 5 |
6 | 39 | 3 | 6 |
6 | 43 | 4 | 5 |
36 | 20 | 7 | 2 |
36 | 39 | 7 | 2 |
36 | 43 | 5 | 4 |
20 | 39 | 7 | 2 |
20 | 43 | 4 | 5 |
39 | 43 | 3 | 6 |