to-report idxpairs01 [#lst]
...
end
For some strange reason, my 'playonce' procedure is preventing a proper check from occurring. Currently, it's more or less the standard code offered, but when I check the procedure, it says that 1 is an expected command (from the transfer #player1 #player2 1 line of code). Does anyone have an idea where the source of this problem might be? The only thing that I can think of is that I messed up the order of things somewhere.
#Create Play Once Function# Based on the results of the coin flip, transfer payments are made from/to each player
def play_once(player1,player2): if random.uniform(0,1) < 0.5: #flip coin transfer(player1, player2, 1) else: transfer(player2, player1, 1)
#Create Ruin2Player Function
'''Our simulation is bounded by a maximum number of iterations (100*100) for the entire game''''''Our simulation is bounded by one simulation per pairings before regrouping the pairs''''''Removed the minimum wealth condition as this is taken care of in the resampling function to follow'''maxitr=1def ruin2player(pairs): itr = 0 while (itr<maxitr): itr += 1 play_once(pairs[0], pairs[1])
'''An alternative is to allow players who still have wealth to continue playing until the maximum number of iterations is reached.'''
def resampling(pairs): for _ in range(1,10000,1): while (all(a != 0 for a in wealths.values())): pairs=pairup(list_of_players) for q in range(0,len(pairs)-1,1): ruin2player(pairs[q]) else: for k,v in wealths.items(): if v == 0: try: del wealths[k] except KeyErrror: pass del list_of_players[int(k.split('_')[1])] pairs=pairup(list_of_players) for q in range(0,len(pairs)-1,1): ruin2player(pairs[q])
#Run Simulationresampling(pairs)Some additional debugging shows the source of the error in the else-clause below. The while function takes care of one of the approaches to the random re-sampling (stop the simulation when any one players wealth falls to zero). The else clause is removing those players from the simulation whose wealth falls to zero (And thus allows the remaining winners to keep playing).
def resampling(pairs):
for _ in range(1,10000,1):while (all(a != 0 for a in wealths.values())):pairs=pairup(list_of_players)for q in range(0,len(pairs)-1,1):ruin2player(pairs[q])else:for k,v in wealths.items():if v == 0:
del wealths[k]
def resampling(pairs): for _ in range(1,10000,1): while (all(a != 0 for a in wealths.values())): pairs=pairup(list_of_players) for q in range(0,len(pairs)-1,1): ruin2player(pairs[q]) print _