import daifugo.game as game import daifugo.sandbox as sandbox game.DEBUG = True players = [ sandbox.as_module(open('players/interactive.py'))[0], sandbox.as_module(open('players/some_call_me'))[0], sandbox.as_module(open('players/mlui.py'))[0], sandbox.as_module(open('players/mlui_cost.py'))[0], ] game.play_game([p.play for p in players])
parser.add_option('-s','--seed',help='seed for deck shuffling',default='daifugo') opts, args = parser.parse_args() if not opts.output: parser.error("Output directory must be specified") all_players = {} for i,path in enumerate(open(opts.input) if opts.input else sys.stdin): path = path.strip() with open(path) as f: all_players[i] = sandbox.as_module(f)[0] output = open(opts.output, 'a') if opts.output else sys.stdout random.seed(opts.seed) deck = game.deal() for i in xrange(opts.numiter): players = random.sample(all_players, 4) try: with sandbox.redirect_stdout(open('/dev/null','w')): game_trace = game.play_game([all_players[p].play for p in players], 'pass', initial_deal=deck) output.write(','.join(map(str,players)+[str(game_trace[0][-1])]) + '\n') except Exception, e: pass
'--niter', help='Number of iterations', type=int, default=100) parser.add_option('-t', '--trace', help='Show game trace', action='store_true', default=False) opts, args = parse.parse_args() game.DEBUG = opts.trace if not opts.input: parser.error("must specify input file") with open(opts.input) as f: module, _ = as_module(f) p1 = module.play p2 = module.play p3 = module.play p4 = module.play win_count = defaultdict(int) players = (p1, p2, p3, p4) for i in range(opts.niter): print i winner, _, _ = game.play_game(players) win_count[winner[-1]] += 1 print win_count
from daifugo.sandbox import as_module from optparse import OptionParser if __name__ == "__main__": parser = OptionParser() parser.add_option('-i','--input',help='Read player from FILE', metavar='FILE') parser.add_option('-n','--niter',help='Number of iterations', type=int, default=100) parser.add_option('-t','--trace',help='Show game trace', action='store_true', default=False) opts, args = parse.parse_args() game.DEBUG = opts.trace if not opts.input: parser.error("must specify input file") with open(opts.input) as f: module, _ = as_module(f) p1 = module.play p2 = module.play p3 = module.play p4 = module.play win_count = defaultdict(int) players=(p1,p2,p3,p4) for i in range(opts.niter): print i winner, _, _ = game.play_game(players) win_count[winner[-1]] += 1 print win_count
default='daifugo') opts, args = parser.parse_args() if not opts.output: parser.error("Output directory must be specified") all_players = {} for i, path in enumerate(open(opts.input) if opts.input else sys.stdin): path = path.strip() with open(path) as f: all_players[i] = sandbox.as_module(f)[0] output = open(opts.output, 'a') if opts.output else sys.stdout random.seed(opts.seed) deck = game.deal() for i in xrange(opts.numiter): players = random.sample(all_players, 4) try: with sandbox.redirect_stdout(open('/dev/null', 'w')): game_trace = game.play_game( [all_players[p].play for p in players], 'pass', initial_deal=deck) output.write( ','.join(map(str, players) + [str(game_trace[0][-1])]) + '\n') except Exception, e: pass