#!/usr/bin/python
import random
sum_strategy_keep = 0
sum_strategy_change = 0
sum_strategy_chaos = 0
attempts = 50
for attempt in range(1, attempts + 1):
#game logic
real_door = random.randint(1, 3)
#player logic
guess1_door = random.randint(1, 3)
#game logic
if guess1_door == real_door:
#stupid straighforward code in this branch, sorry :-)
open_door = random.randint(0, 1)
if real_door == 1:
open_door = (2,3)[open_door]
elif real_door == 2:
open_door = (1,3)[open_door]
if real_door == 3:
open_door = (1,2)[open_door]
else:
#deterministic branch:
open_door = 6 - real_door - guess1_door
#player logic - 3 strategies
strategy_keep = (real_door == guess1_door)
strategy_change = (real_door == 6 - guess1_door - open_door)
guess2_door = random.randint(0, 1)
if open_door == 1:
guess2_door = (2,3)[guess2_door]
elif open_door == 2:
guess2_door = (1,3)[guess2_door]
if open_door == 3:
guess2_door = (1,2)[guess2_door]
strategy_chaos = (real_door == guess2_door)
#game output:
print ( "#%02d: real: %d, guess1: %d, open: %d, strategy keep: %d, strategy change: %d, strategy chaos: %d "
% (attempt, real_door, guess1_door, open_door, strategy_keep, strategy_change, strategy_chaos))
if strategy_keep:
sum_strategy_keep += 1
if strategy_change:
sum_strategy_change += 1
if strategy_chaos:
sum_strategy_chaos += 1
print "strategy keep: %3.2f" % (float(sum_strategy_keep)/attempt)
print "strategy change: %3.2f" % (float(sum_strategy_change)/attempt)
print "strategy chaos: %3.2f" % (float(sum_strategy_chaos)/attempt)