if __name__ == "__main__": parser = OptionParser() parser.add_option("-i","--input", help="Read from FILE", metavar="FILE") parser.add_option("-d","--disq", action="store_true", default=False, help="echo disqualified") parser.add_option("-q","--qual", action="store_true", default=False, help="echo qualified") parser.add_option("-r","--reason", action="store_true", default=False, help="show reason") opts, args = parser.parse_args() if not opts.input: parser.error("Must specify input file") t_pass = True fail_reason = None try: with open(opts.input) as f: student_code, student_output = sandbox.as_module(f) # Run the actual test suite for t, t_fn in sandbox.TEST_SUITE: if hasattr(student_code, t): #t_result = t_fn(getattr(student_code,t)) t_ran, t_result, t_out = sandbox.timeout(t_fn, args=(getattr(student_code,t),), timeout_duration=30) if t_ran: t_pass = t_pass and t_result[0] if not t_result[0]: fail_reason = "failed {0}".format(t) else: t_pass = False e = t_result[1] fail_reason = "{0}: {1}".format(e.__class__.__name__, str(e)) else: t_pass = False
help="echo qualified") parser.add_option("-r", "--reason", action="store_true", default=False, help="show reason") opts, args = parser.parse_args() if not opts.input: parser.error("Must specify input file") t_pass = True fail_reason = None try: with open(opts.input) as f: student_code, student_output = sandbox.as_module(f) # Run the actual test suite for t, t_fn in sandbox.TEST_SUITE: if hasattr(student_code, t): #t_result = t_fn(getattr(student_code,t)) t_ran, t_result, t_out = sandbox.timeout(t_fn, args=(getattr( student_code, t), ), timeout_duration=30) if t_ran: t_pass = t_pass and t_result[0] if not t_result[0]: fail_reason = "failed {0}".format(t) else: t_pass = False
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 = OptionParser() parser.add_option('-o','--output',help='output to FILE', metavar='FILE') parser.add_option('-i','--input',help='read from FILE instead of stdin', metavar='FILE') parser.add_option('-n','--numiter',help='number of games', type=int, default=1000) 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=1000) 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(