def test_minreg_grid_roshambo(): game = gamegen.rock_paper_scissors() eqm = nash.min_regret_grid_mixture(game, 3) # Not enough for eq assert np.isclose(regret.mixture_regret(game, eqm), .5), \ "min regret grid didn't find [.5, .5, 0] profile with regret .5" eqm = nash.min_regret_grid_mixture(game, 4) # hit eqa perfectly assert np.isclose(regret.mixture_regret(game, eqm), 0), \ "min regret grid didn't find equilibrium"
def main(args): game, serial = gameio.read_game(json.load(args.input)) if args.type == 'pure': equilibria = nash.pure_nash(game, args.regret) if args.one and not equilibria: equilibria = nash.min_regret_profile(game)[None] elif args.type == 'mixed': rep_args = { 'max_iters': args.max_iterations, 'converge_thresh': args.convergence } equilibria = nash.mixed_nash(game, args.regret, args.distance, random_restarts=args.random_mixtures, grid_points=args.grid_points, at_least_one=args.one, processes=args.processes, replicator=rep_args, optimize={}) equilibria = game.trim_mixture_support(equilibria, args.support) elif args.type == 'min-reg-prof': equilibria = nash.min_regret_profile(game)[None] elif args.type == 'min-reg-grid': equilibria = nash.min_regret_grid_mixture( game, args.grid_points)[None] equilibria = game.trim_mixture_support(equilibria, args.support) elif args.type == 'min-reg-rand': equilibria = nash.min_regret_rand_mixture( game, args.random_mixtures)[None] equilibria = game.trim_mixture_support(equilibria, args.support) elif args.type == 'rand': equilibria = game.random_mixtures(args.random_mixtures) equilibria = game.trim_mixture_support(equilibria, args.support) else: raise ValueError('Unknown command given: {0}'.format(args.type)) # pragma: no cover # noqa json.dump([serial.to_prof_json(eqm) for eqm in equilibria], args.output) args.output.write('\n')