#BayesBot
BayesBot
Tries to make the optimal choice using a simple statistical model.
import random
def dirichlet(counts):
counts = [random.gammavariate(n, 1) for n in counts]
k = 1. / sum(counts)
return [n * k for n in counts]
class BayesBot(object):
def __init__(self, index):
self.index = index
self.counts = [[0.2 * (10 - i) for i in range(10)] for _ in range(10)]
def select(self):
player_distributions = []
for i, counts in enumerate(self.counts):
if i == self.index:
continue
player_distributions.append(dirichlet(counts))
cumulative_unique = 0.
scores = [0.] * 10
for i in range(10):
p_unpicked = 1.
for d in player_distributions:
p_unpicked *= (1. - d[i])
p_unique = p_unpicked * sum(d[i] / (1. - d[i]) for d in player_distributions)
scores[i] = p_unpicked * (1. - cumulative_unique)
cumulative_unique += p_unique * (1. - cumulative_unique)
return scores.index(max(scores)) + 1
def update(self, choices):
for i, n in enumerate(choices):
self.counts[i][n - 1] += 1