import math
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import pandas as pd
import seaborn as sns
B = []
C = []
mediocre = []
#Exhaustive approach.
#B and C can both pick 0 - 10. Let us look at all 121 possibilities.
for b in range(0,11):
for c in range(0,11):
minigame = {"A" : 3,
"B" : b,
"C" : c}
finalscore = {"A" : 6,
"B" : 8,
"C" : 10}
cards = list(minigame.values())
med = np.median(cards)
split = cards.count(med)
#Update winnings for each player.
if split == 1:
for player in ("A", "B", "C") :
#The winner in each mini game had picked the median value.
if minigame[player] == med :
#The amount they receive is the median value divided by the number of players who picked it.
finalscore[player] = finalscore[player] + med
med_final = np.median(list(finalscore.values()))
winners = set([])
for player in ("A", "B", "C") :
if finalscore[player] == med_final :
winners.add(player)
elif split == 2:
winners = set([])
if minigame["A"] == med :
finalscoret = finalscore.copy()
finalscoret["A"] = finalscoret["A"] + med
med_final = np.median((6 + med, 8, 10))
for player in ("A", "B", "C") :
if finalscoret[player] == med_final :
winners.add(player)
if minigame["B"] == med :
finalscoret = finalscore.copy()
finalscoret["B"] = finalscoret["B"] + med
med_final = np.median((6, 8 + med, 10))
for player in ("A", "B", "C") :
if finalscoret[player] == med_final :
winners.add(player)
if minigame["C"] == med :
finalscoret = finalscore.copy()
finalscoret["C"] = finalscoret["C"] + med
med_final = np.median((6, 8, 10 + med))
for player in ("A", "B", "C") :
if finalscoret[player] == med_final :
winners.add(player)
else :
winners = set(["A", "B", "C"])
winners = list(winners)
winners.sort()
winners = "".join(winners)
B.append(b)
C.append(c)
mediocre.append(winners)
outcomes = pd.DataFrame(data = {"B": B,
"C": C,
"Mediocre": mediocre})
#Score the 5th round.
def score(row) :
#A, B, C tie.
if row['B'] == 3 and row['C'] == 3:
return "(3,3,3)"
#A, B tie.
elif row['B'] == 3:
return "(3,3,0)"
#A, C tie.
elif row['C'] == 3:
return "(3,0,3)"
#B, C tie.
elif row['B'] == row['C']:
return "(0," + str(row['B']) + "," + str(row['B']) + ")"
#One clear median.
else :
med = np.median((3, row['B'], row['C']))
if med == 3 :
return "(3,0,0)"
if med == row['B'] :
return "(0," + str(row['B']) + ",0)"
else :
return "(0,0," + str(row['C']) + ")"
outcomes['Score'] = outcomes.apply (lambda row: score(row), axis = 1)
outcomes
B | C | Mediocre | Score | |
---|---|---|---|---|
0 | 0 | 0 | B | (0,0,0) |
1 | 0 | 1 | B | (0,0,1) |
2 | 0 | 2 | B | (0,0,2) |
3 | 0 | 3 | AB | (3,0,3) |
4 | 0 | 4 | A | (3,0,0) |
... | ... | ... | ... | ... |
116 | 10 | 6 | B | (0,0,6) |
117 | 10 | 7 | B | (0,0,7) |
118 | 10 | 8 | B | (0,0,8) |
119 | 10 | 9 | B | (0,0,9) |
120 | 10 | 10 | BC | (0,10,10) |
121 rows × 4 columns
sns.set()
def helper121(option) :
fig = plt.figure(figsize = (12, 12))
ax = fig.add_subplot(111, xlim = (-0.5, 10.5), ylim = (-0.5, 10.5))
for i in range(len(outcomes)) :
if option == "Score" :
label = outcomes["Score"][i]
fw = "normal"
size = 12
else :
label = outcomes["Mediocre"][i]
fw = "bold"
size = 24
plt.text(x = outcomes["B"][i],
y = outcomes["C"][i],
s = label,
ha = 'center',
va = 'center',
c = "k",
fontweight = fw,
size = size,
zorder = 1)
#Title setup.
if option == "Score" :
ax.set_title('5th Round Winnings', fontsize = 24)
else :
ax.set_title('Final Winner after 5th Round', fontsize = 24)
#X-axis setup.
ax.set_xlabel("B's Choice", fontsize = 24)
ax.set_xticks(range(11))
#Y-axis setup.
ax.set_ylabel("C's Choice", fontsize = 24)
ax.set_yticks(range(11))
ax.tick_params(axis = 'both', which = 'major', labelsize = 22)
#Higher Order Dominance.
if option == "Final" :
def symElim(n, c, z):
plt.axvline(x = n, color = c, lw = 4, zorder = z)
plt.axhline(y = n, color = c, lw = 4, zorder = z)
#1st Decision.
for x in (2,3) :
plt.axvline(x = x, color = '#FDE275', lw = 4, zorder = 2)
#2nd Decision
for y in range(4) :
plt.axhline(y = y, color = '#B8DE29', lw = 4, zorder = 3)
#3rd Decision.
for x in (0,1) :
plt.axvline(x = x, color = '#73D055', lw = 4, zorder = 4)
#4-8 Decisions.
symElim(4, "#3CBB75", 5)
symElim(5, "#20A387", 6)
symElim(6, "#238A8D", 7)
symElim(7, "#2D708E", 8)
symElim(8, "#39568C", 9)
symElim(9, "#453781", 10)
#Answer!
rect = patches.Rectangle((9.55, 9.55), .9, .9, linewidth = 4.5, edgecolor = '#481567', facecolor='none')
ax.add_patch(rect)
fig.savefig("2022.04.08 Classic " + option + ".png")
helper121("Score")
helper121("Winner")
helper121("Final")