Skip to content

Instantly share code, notes, and snippets.

@zrbecker
Created June 27, 2011 05:03
Show Gist options
  • Select an option

  • Save zrbecker/1048334 to your computer and use it in GitHub Desktop.

Select an option

Save zrbecker/1048334 to your computer and use it in GitHub Desktop.
Attack Probable Move Strategy
def attack_probable_move_strategy(history):
"""Chooses best response to opponents most probable response based on
last 100 moves."""
probable_move = [0, 0, 0, 0, 0, 0, 0]
# Calculates response to last move based on previous 100 moves
last_l = -1
for l, r in history[-100:]:
if last_l == history[-1][0]:
probable_move[r] += 1
last_l = l
# If no data, make a safe response. pA = [3, 3, 1.7, 3, 1.7, 3, 3]
if sum(probable_move) == 0:
return random_from_distribution([float(n) / 7 for n in [1, 1, 0, 1, 2, 1, 1]])
# Determines best action against most probable move
move = probable_move.index(max(probable_move))
if move == 0:
return choice([1, 3])
elif move == 1:
return choice([3, 6])
elif move == 2:
return 4
elif move == 3:
return choice([5, 6])
elif move == 4:
return choice([0, 1, 3, 5, 6])
elif move == 5:
return choice([0, 1])
elif move == 6:
return choice([0, 5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment