Post History
The Rules In this game, each round, every player faces off against every other player in a round robin format. In each match, players pick 3 positive integers that sum to 360. Let's say player 1 p...
#1: Initial revision
Three Number Monte
## The Rules In this game, each round, every player faces off against every other player in a round robin format. In each match, players pick 3 positive integers that sum to 360. Let's say player 1 picks `[a, b, c]` and player 2 picks `[x, y, z]` Now `a` is compared to `x`, `b` is compared to `y`, and `c` is compared to `z`. If `a > x`, player 1 gets a tally, and vice versa, for all 3 numbers. If either player gets at least 2 tallies, they win the match and receive 1 point - otherwise, both players receive half a point. To make this game more interesting, each match, the players get a `data` object that they can use for memory, and also a `history` object that contains all of their opponent's previous choices. ## Submission Write a Python function that takes in two arguments, `data` and `history`, described above, and returns an array of positive integers that sums to 360. You can find some example players in the driver code. ## Driver ```py import random, itertools, math def onethird(data, history): a = [120, 120, 120] random.shuffle(a) return a def onehalf(data, history): a = [180, 180, 0] random.shuffle(a) return a def rand(data, history): x = random.randint(0, 360) y = random.randint(0, 360 - x) return [x, y, 360 - x - y] players = [onethird, onehalf, rand] #Game logic ROUNDS = 10000 pairs = list(itertools.combinations(players, 2)) data = {} history = {} scores = {} for p in players: data[p] = {} history[p] = [] scores[p] = 0 for _ in range(ROUNDS): random.shuffle(pairs) for pair in pairs: p1, p2 = pair a1 = p1(data[p1], history[p2]) a2 = p2(data[p2], history[p1]) assert sum(a1) == 360, (p1, a1) assert sum(a2) == 360, (p2, a2) assert all(isinstance(i, int) for i in a1), (p1, a1) assert all(isinstance(i, int) for i in a2), (p2, a2) assert all(0 <= i <= 360 for i in a1), (p1, a1) assert all(0 <= i <= 360 for i in a2), (p2, a2) history[p1].append(a1) history[p2].append(a2) p1c, p2c = 0, 0 for i in range(3): if a1[i] > a2[i]: p1c += 1 elif a2[i] > a1[i]: p2c += 1 if p1c >= 2: scores[p1] += 1 elif p2c >= 2: scores[p2] += 1 else: scores[p1] += 0.5 scores[p2] += 0.5 print(scores) ``` The tentative deadline for this competition is **8/16/21 00:00 UTC**.