from numpy.random import choice
def get_turn_diffs(counts, n_kids):
possible_choices = ["left", "keep", "right"]
probs = [.15, .7, .15]
choices = list(choice(possible_choices, n_kids, probs))
if choices[0] == "left":
choices[0] = "keep"
if choices[-1] == "right":
choices[-1] = "keep"
diffs = [0] * n_kids
for i in range(len(choices)):
if choices[i] == "right" and counts[i] != 0:
diffs[i] -= 1
diffs[i + 1] += 1
elif choices[i] == "left" and counts[i] != 0:
diffs[i - 1] += 1
diffs[i] -= 1
return diffs
def add_diffs(counts, diffs):
for i in range(len(diffs)):
counts[i] += diffs[i]
def run_turn(counts, n_kids):
diffs = get_turn_diffs(counts, n_kids)
add_diffs(counts, diffs)
counts = [100, 0, 0, 1, 2, 0, 0, 3]
n_kids = len(counts)
for i in range(100000):
run_turn(counts, n_kids)