Skip to content

Instantly share code, notes, and snippets.

@mjhea0
Forked from ivanilos/count_to_five_bot.py
Created October 16, 2015 14:00
Show Gist options
  • Save mjhea0/d7fc846ea8ab2b03e819 to your computer and use it in GitHub Desktop.
Save mjhea0/d7fc846ea8ab2b03e819 to your computer and use it in GitHub Desktop.
# Made by Ivan Petrin
def computer_strategy(scores, player_answers, computer_answers,
total_iterations, current_iteration):
v = [] # counter of values
expected = [] # expected values of scores
for i in range(10):
v.append(1)
expected.append(0)
for i in player_answers:
i = i - 1
if i < 0:
i = 0
if i > 9:
i = 9
v[i] = v[i] + 1
# compute expected value
# computer chooses i
# adversary chooses j
for i in range(10):
for j in range(10):
score = 1
if i + 1 == j:
score = -2
elif i - 1 == j:
score = 2
elif i == j:
score = 0
elif j < i:
score = -1
expected[i] = expected[i] + score * v[j]
best = 1
maxi = -10000000 # -INF
for i in range(10):
if expected[i] > maxi:
maxi = expected[i]
best = i + 1
return best
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment