import random def factory(i, b, c): return 4 def distributor(i, b, c): return 4 def wholesaler(i, b, c): return 4 def retailer(i, b, c): return 4 def beerGameTurn(factory, distributor, wholesaler, retailer, inventory = [12, 12, 12, 12], backlog = [0, 0, 0, 0], currentRequest = [4, 4, 4, 4], sentBeer = [4, 4, 4, 4], delivered = [4, 4, 4, 4], score = [0, 0, 0, 0], customerRequest = 4): # step 0: add customer request to requests currentRequest.append(customerRequest) # step 1: collect new beer inventory = [i + d for i, d in zip(inventory, delivered)] # step 2: move sent beer to delivered delivered = [s for s in sentBeer] # step 3: send beer to fullfill currentRequest sentBeer[0] = currentRequest[0] for i in range(4): need = currentRequest[i+1] + backlog[i] # do you have enough beer? if need <= inventory[i]: inventory[i] -= need if i < 3: sentBeer[i+1] = need backlog[i] = 0 else: backlog[i] = need - inventory[i] if i < 3: sentBeer[i+1] = inventory[i] inventory[i] = 0 # step 4: update scores score = [s + .5 * i + b for s, i, b in zip(score, inventory, backlog)] # step 5: request something orderFromFactory = factory(inventory[0], backlog[0], currentRequest[1]) orderFromDistributor = distributor(inventory[1], backlog[1], currentRequest[2]) orderFromWholesaler = wholesaler(inventory[2], backlog[2], currentRequest[3]) orderFromRetailer = retailer(inventory[3], backlog[3], currentRequest[4]) newRequest = [None for _ in range(4)] newRequest[0] = orderFromFactory newRequest[1] = orderFromDistributor newRequest[2] = orderFromWholesaler newRequest[3] = orderFromRetailer return inventory, backlog, newRequest, sentBeer, delivered, score k = 52 customerRequests = [] for _ in range(k): customerRequests.append(random.randint(2, 10)) #start the game B = beerGameTurn(factory, distributor, wholesaler, retailer, inventory = [12, 12, 12, 12], backlog = [0, 0, 0, 0], currentRequest = [4, 4, 4, 4], sentBeer = [4, 4, 4, 4], delivered = [4, 4, 4, 4], score = [0, 0, 0, 0], customerRequest = customerRequests[0]) for i in range(1, k): B = beerGameTurn(factory, distributor, wholesaler, retailer, inventory = B[0], backlog = B[1], currentRequest = B[2], sentBeer = B[3], delivered = B[4], score = B[5], customerRequest = customerRequests[i]) print(B[5])