def test_subgame(): game = rsgame.BaseGame([3, 4], [3, 2]) subg = np.asarray([1, 0, 1, 0, 1], bool) devs = subgame.deviation_profiles(game, subg) assert devs.shape[0] == 7, \ "didn't generate the right number of deviating profiles" adds = subgame.additional_strategy_profiles(game, subg, 1).shape[0] assert adds == 6, \ "didn't generate the right number of additional profiles" subg2 = subg.copy() subg2[1] = True assert (subgame.subgame(game, subg2).num_all_profiles == adds + subgame.subgame(game, subg).num_all_profiles), \ "additional profiles didn't return the proper amount" serial = gamegen.game_serializer(game) sub_serial = subgame.subserializer(serial, subg) assert (subgame.subgame(game, subg).num_role_strats == sub_serial.num_role_strats)
def test_missing_data_maximal_subgames(game_desc, prob): base = rsgame.BaseGame(*game_desc) game = gamegen.add_profiles(base, prob) subs = subgame.maximal_subgames(game) if subs.size: maximal = np.all(subs <= subs[:, None], -1) np.fill_diagonal(maximal, False) assert not maximal.any(), \ "One maximal subgame dominated another" for sub in subs: subprofs = subgame.translate(subgame.subgame(base, sub).all_profiles(), sub) assert all(p in game for p in subprofs), \ "Maximal subgame didn't have all profiles" for dev in np.nonzero(~sub)[0]: devprofs = subgame.additional_strategy_profiles( game, sub, dev) assert not all(p in game for p in devprofs), \ "Maximal subgame could be bigger {} {}".format( dev, sub)