def sim_naive_actions_calculated_targets_selfish_blocks_no_doubts(players): """ AI PROFILE: Action Used Targets Blocked income yes foreign_aid yes any available duke coup yes steal yes unlikely victim only tax yes assassinate yes unlikely victim only exchange yes unlikely no """ testgame = Play_Coup(players, PERSONALITIES.keys()) for acting_player in cycle(testgame.players): if not acting_player.influence_remaining: continue elif len(testgame) == 1: return testgame while 1: try: action = acting_player.random_naive_priority() if action == 'steal': random_player = acting_player.select_opponent(testgame.players) if action in random_player.calculate('probable', 'blocks'): raise RethinkAction(action, acting_player, random_player) if action in random_player.valid_blocks: raise BlockedAction(action, acting_player, random_player, None) acting_player.perform(action, random_player) elif action == 'assassinate': random_player = acting_player.select_opponent(testgame.players) if action in random_player.valid_blocks: raise BlockedAction(action, acting_player, random_player, None) position, random_target = random_player.random_remaining_influence acting_player.perform(action, random_target) elif action == 'foreign_aid': for savior in testgame.filter_out_players([acting_player]): if action in savior.valid_blocks: raise BlockedAction(action, acting_player, None, savior) acting_player.perform(action) elif action == 'exchange': acting_player.perform(action, testgame.court_deck) elif action == 'coup': random_player = acting_player.select_opponent(testgame.players) position, random_target = random_player.random_remaining_influence acting_player.perform(action, random_target) else: acting_player.perform(action) except (IllegalTarget, IllegalAction): pass except RethinkAction: pass except BlockedAction: break else: break
def sim_random_actions_random_targets_selfish_blocks_no_doubts(players): """ AI PROFILE: Action Used Targets Blocked income yes foreign_aid yes if random char is duke coup yes steal yes random victim/honest tax yes assassinate yes random victim/honest exchange yes random no """ testgame = Play_Coup(players, PERSONALITIES.keys()) for acting_player in cycle(testgame.players): if not acting_player.influence_remaining: continue elif len(testgame) == 1: return testgame while 1: try: action = choice(list(Play_Coup.ACTIONS['all'])) if action == 'steal': random_player = acting_player.select_opponent(testgame.players) if action in random_player.valid_blocks: raise BlockedAction(action, acting_player, random_player, None) acting_player.perform(action, random_player) elif action == 'assassinate': random_player = acting_player.select_opponent(testgame.players) if action in random_player.valid_blocks: raise BlockedAction(action, acting_player, random_player, None) position, random_target = random_player.random_remaining_influence acting_player.perform(action, random_target) elif action == 'foreign_aid': random_player = acting_player.select_opponent(testgame.players) if action in random_player.valid_blocks: raise BlockedAction(action, acting_player, None, random_player) acting_player.perform(action) elif action == 'exchange': acting_player.perform(action, testgame.court_deck) elif action == 'coup': random_player = acting_player.select_opponent(testgame.players) position, random_target = random_player.random_remaining_influence acting_player.perform(action, random_target) else: acting_player.perform(action) except (IllegalTarget, IllegalAction): pass except BlockedAction: break else: break
def sim_a_full_on_yomi(players): testgame = Play_Coup(players, PERSONALITIES.keys()) for acting_player in cycle(testgame.players): if not acting_player.influence_remaining: continue elif len(testgame) == 1: return testgame action_plan = [] remaining_opponent = None if len(testgame) == 2: remaining_opponent = acting_player.select_opponent(testgame.players) action_plan = acting_player.one_on_one_strategy(remaining_opponent.best_guess, True) while 1: try: if action_plan: action = action_plan.pop(0) else: action = acting_player.random_naive_priority() if action == 'income': acting_player.perform(action) break if action == 'tax': acting_player.perform(action) break elif action == 'coup': if remaining_opponent: victim = remaining_opponent else: for random_opponent in testgame.filter_out_players([acting_player]): if not acting_player.wins_duel(random_opponent): victim = random_opponent break else: victim = acting_player.select_opponent(testgame.players) position, random_target = victim.random_remaining_influence acting_player.perform(action, random_target) victim.remove_suspicion(str(random_target)) break elif action == 'foreign_aid': for savior in testgame.filter_out_players([acting_player]): if not savior.wins_duel(acting_player): opponent = savior break else: opponent = None if opponent and opponent.will_intervene(action, acting_player): for spectators in testgame.filter_out_players([acting_player, opponent]): spectators.didnt_block_as['spectator'].extend([action]) if acting_player.will_callout('block_foreign_aid', opponent) and \ acting_player.plays_numbers and \ random() > AI_Persona.probability_player_influences(testgame.players, opponent, 'Duke', acting_player): if action not in opponent.valid_blocks: acting_player.perform(action) raise QuestionInfluence(acting_player, opponent, 'Duke', testgame.court_deck, 'foreign_aid') elif action in opponent.valid_blocks: raise BlockedAction(action, acting_player, None, opponent) acting_player.perform(action) break elif action == 'steal': if remaining_opponent: victim = remaining_opponent else: for opponent in testgame.filter_out_players([acting_player]): if not acting_player.wins_duel(opponent) and action not in opponent.calculate('judge', 'blocks'): victim = opponent break else: victim = acting_player.select_opponent(testgame.players) if action in victim.valid_blocks: raise BlockedAction(action, acting_player, victim, None) else: for savior in testgame.filter_out_players([acting_player, victim]): representing = savior.will_intervene(action, acting_player, victim) if representing: #logic to doubt savior (ambassador doesnt leave hints, so excess failed callouts) '''for doubter in testgame.filter_out_players([acting_player, savior, victim]): if doubter.will_callout('block_steal', savior): if action not in savior.valid_blocks: acting_player.perform(action, victim) self.ACTIONS[acting_player.alpha].append(action) raise QuestionInfluence(doubter, savior, representing, testgame.court_deck, 'block_steal') ''' for spectators in testgame.filter_out_players([acting_player, savior, victim]): spectators.didnt_block_as['spectator'].extend([action]) raise BlockedAction(action, acting_player, victim, savior) for doubter in testgame.filter_out_players([acting_player]): if doubter.will_callout(action, acting_player): if action in acting_player.valid_actions: acting_player.perform(action, victim) raise QuestionInfluence(doubter, acting_player, 'Captain', testgame.court_deck, 'steal') acting_player.perform(action, victim) for spectators in testgame.filter_out_players([acting_player]): spectators.didnt_block_as['spectator'].extend([action]) break elif action == 'assassinate': if remaining_opponent: victim = remaining_opponent else: for opponent in testgame.filter_out_players([acting_player]): if not acting_player.wins_duel(opponent) and \ random() > AI_Persona.probability_player_influences(testgame.players, opponent, 'Contessa', acting_player): victim = opponent break else: victim = acting_player.select_opponent(testgame.players) if action in victim.valid_blocks: raise BlockedAction(action, acting_player, victim, None) else: for savior in testgame.filter_out_players([acting_player, victim]): representing = savior.will_intervene(action, acting_player, victim) if representing: for spectators in testgame.filter_out_players([acting_player, savior, victim]): spectators.didnt_block_as['spectator'].extend([action]) #omitted logic to doubt savior (contessa doesnt leave hints, so excess failed callouts) raise BlockedAction(action, acting_player, victim, savior) for doubter in testgame.filter_out_players([acting_player]): if doubter.will_callout(action, acting_player): if action in acting_player.valid_actions: position, random_target = victim.random_remaining_influence acting_player.perform(action, random_target) victim.remove_suspicion(str(random_target)) raise QuestionInfluence(doubter, acting_player, 'Assassin', testgame.court_deck, 'assassinate') position, random_target = victim.random_remaining_influence acting_player.perform(action, random_target) victim.remove_suspicion(str(random_target)) for spectators in testgame.filter_out_players([acting_player, victim]): spectators.didnt_block_as['spectator'].extend([action]) break elif action == 'exchange': for doubter in testgame.filter_out_players([acting_player]): if doubter.will_callout(action, acting_player) and \ doubter.plays_numbers and \ random() > AI_Persona.probability_player_influences(testgame.players, acting_player, 'Ambassador', doubter): if action in acting_player.valid_actions: acting_player.perform(action, testgame.court_deck) raise QuestionInfluence(doubter, acting_player, 'Ambassador', testgame.court_deck, 'exchange') acting_player.perform(action, testgame.court_deck) break except IllegalAction: pass except IllegalTarget: pass except BlockedAction: break except RethinkAction: pass except QuestionInfluence: break
def sim_calculated_actions_calculated_targets_more_calculated_blocks_systemic_doubts(players): """ AI PROFILE: Action Used Targets Blocked income yes foreign_aid yes victim/by ai profile coup yes steal yes best_guess victim/by ai profile tax yes assassinate yes best_guess victim/by ai profile exchange yes random no """ testgame = Play_Coup(players, PERSONALITIES.keys()) for acting_player in cycle(testgame.players): if not acting_player.influence_remaining: continue elif len(testgame) == 1: return testgame while 1: try: action = acting_player.random_naive_priority() #print '{0} performing {1} (coins={2})'.format(acting_player, action, acting_player.coins) if action == 'income': acting_player.perform(action) break if action == 'tax': acting_player.perform(action) break elif action == 'coup': random_player = acting_player.select_opponent(testgame.players) position, random_target = random_player.random_remaining_influence acting_player.perform(action, random_target) random_player.remove_suspicion(str(random_target)) break elif action == 'foreign_aid': for savior in testgame.filter_out_players([acting_player]): if savior.will_intervene(action, acting_player): for spectators in testgame.filter_out_players([acting_player, savior]): spectators.didnt_block_as['spectator'].extend([action]) raise BlockedAction(action, acting_player, None, savior) else: acting_player.perform(action) break elif action == 'steal': random_player = acting_player.select_opponent(testgame.players) if action in random_player.calculate('probable', 'blocks') and random() > .33: raise RethinkAction(action, acting_player, random_player) elif action in random_player.valid_blocks: raise BlockedAction(action, acting_player, random_player, None) else: for savior in testgame.filter_out_players([acting_player, random_player]): if savior.will_intervene(action, acting_player, random_player): raise BlockedAction(action, acting_player, random_player, savior) for doubter in testgame.filter_out_players([acting_player]): if doubter.will_callout(action, acting_player): if action in acting_player.valid_actions: acting_player.perform(action, random_player) raise QuestionInfluence(doubter, acting_player, 'Captain', testgame.court_deck, 'steal') acting_player.perform(action, random_player) for spectators in testgame.filter_out_players([acting_player, savior]): spectators.didnt_block_as['spectator'].extend([action]) break elif action == 'assassinate': random_player = acting_player.select_opponent(testgame.players) if action in random_player.calculate('probable', 'blocks') and random() > .33: raise RethinkAction(action, acting_player, random_player) elif action in random_player.valid_blocks: raise BlockedAction(action, acting_player, random_player, None) else: for savior in testgame.filter_out_players([acting_player, random_player]): if savior.will_intervene(action, acting_player, random_player): raise BlockedAction(action, acting_player, random_player, savior) for doubter in testgame.filter_out_players([acting_player]): if doubter.will_callout(action, acting_player): if action in acting_player.valid_actions: position, random_target = random_player.random_remaining_influence acting_player.perform(action, random_target) random_player.remove_suspicion(str(random_target)) raise QuestionInfluence(doubter, acting_player, 'Assassin', testgame.court_deck, 'assassinate') position, random_target = random_player.random_remaining_influence acting_player.perform(action, random_target) random_player.remove_suspicion(str(random_target)) for spectators in testgame.filter_out_players([acting_player, random_player]): spectators.didnt_block_as['spectator'].extend([action]) break elif action == 'exchange': for doubter in testgame.filter_out_players([acting_player]): if doubter.will_callout(action, acting_player): if action in acting_player.valid_actions: acting_player.perform(action, testgame.court_deck) raise QuestionInfluence(doubter, acting_player, 'Ambassador', testgame.court_deck, 'block_exchange') break elif action == 'coup': random_player = acting_player.select_opponent(testgame.players) position, random_target = random_player.random_remaining_influence acting_player.perform(action, random_target) random_player.remove_suspicion(str(random_target)) break except (IllegalAction, IllegalTarget): pass except BlockedAction: break except RethinkAction: pass except QuestionInfluence: break
def sim_calculated_actions_calculated_targets_more_calculated_blocks_no_doubts(players): """ AI PROFILE: Action Used Targets Blocked income yes foreign_aid yes victim/by ai profile coup yes steal yes best_guess victim/by ai profile tax yes assassinate yes best_guess victim/by ai profile exchange yes random no """ testgame = Play_Coup(players, PERSONALITIES.keys()) for acting_player in cycle(testgame.players): if not acting_player.influence_remaining: continue elif len(testgame) == 1: return testgame while 1: try: action = acting_player.random_naive_priority() if action == 'steal': random_player = acting_player.select_opponent(testgame.players) if (action in random_player.calculate('probable', 'blocks') and random() > .24): raise RethinkAction(action, acting_player, random_player) if action in random_player.valid_blocks: raise BlockedAction(action, acting_player, random_player, None) for savior in testgame.filter_out_players([acting_player, random_player]): if savior.will_intervene(action, acting_player, random_player): raise BlockedAction(action, acting_player, random_player, savior) acting_player.perform(action, random_player) elif action == 'assassinate': random_player = acting_player.select_opponent(testgame.players) if (action in random_player.calculate('probable', 'blocks') and random() > .24): raise RethinkAction(action, acting_player, random_player) if action in random_player.valid_blocks: raise BlockedAction(action, acting_player, random_player, None) for savior in testgame.filter_out_players([acting_player, random_player]): if savior.will_intervene(action, acting_player, random_player): raise BlockedAction(action, acting_player, random_player, savior) position, random_target = random_player.random_remaining_influence acting_player.perform(action, random_target) random_player.remove_suspicion(str(random_target)) elif action == 'foreign_aid': for savior in testgame.filter_out_players([acting_player]): if savior.will_intervene(action, acting_player): raise BlockedAction(action, acting_player, None, savior) acting_player.perform(action) elif action == 'exchange': acting_player.perform(action, testgame.court_deck) elif action == 'coup': random_player = acting_player.select_opponent(testgame.players) position, random_target = random_player.random_remaining_influence acting_player.perform(action, random_target) random_player.remove_suspicion(str(random_target)) else: acting_player.perform(action) except (IllegalTarget, IllegalAction): pass except BlockedAction: break except RethinkAction: pass else: break
def simulation(players): testgame = Play_Coup(players, PERSONALITIES.keys()) for acting_player in cycle(testgame.players): if not acting_player.influence_remaining: continue elif len(testgame) == 1: WINS[acting_player.saved_personality] += 1 return testgame action_plan = [] remaining_opponent = None if len(testgame) == 2: remaining_opponent = acting_player.select_opponent(testgame.players) action_plan = acting_player.one_on_one_strategy(remaining_opponent.best_guess, True) while 1: try: if action_plan: action = action_plan.pop(0) else: action = acting_player.random_naive_priority() if action == "income": acting_player.perform(action) ACTIONS[acting_player.alpha].append(action) break if action == "tax": acting_player.perform(action) ACTIONS[acting_player.alpha].append(action) break elif action == "coup": if remaining_opponent: victim = remaining_opponent else: for random_opponent in testgame.filter_out_players([acting_player]): if not acting_player.wins_duel(random_opponent): victim = random_opponent break else: victim = acting_player.select_opponent(testgame.players) position, random_target = victim.random_remaining_influence acting_player.perform(action, random_target) victim.remove_suspicion(str(random_target)) ACTIONS[acting_player.alpha].append(action) break elif action == "foreign_aid": for savior in testgame.filter_out_players([acting_player]): if not savior.wins_duel(acting_player): opponent = savior break else: opponent = None if opponent and opponent.will_intervene(action, acting_player): for spectators in testgame.filter_out_players([acting_player, opponent]): spectators.didnt_block_as["spectator"].extend([action]) if ( acting_player.will_callout("block_foreign_aid", opponent) and acting_player.plays_numbers and random() > AI_Persona.probability_player_influences( testgame.players, opponent, "Duke", acting_player ) ): if action not in opponent.valid_blocks: acting_player.perform(action) ACTIONS[acting_player.alpha].append(action) raise QuestionInfluence(acting_player, opponent, "Duke", testgame.court_deck, "foreign_aid") elif action in opponent.valid_blocks: raise BlockedAction(action, acting_player, None, opponent) acting_player.perform(action) ACTIONS[acting_player.alpha].append(action) break elif action == "steal": if remaining_opponent: victim = remaining_opponent else: for opponent in testgame.filter_out_players([acting_player]): if not acting_player.wins_duel(opponent) and action not in opponent.calculate( "judge", "blocks" ): victim = opponent break else: victim = acting_player.select_opponent(testgame.players) if action in victim.valid_blocks: raise BlockedAction(action, acting_player, victim, None) else: for savior in testgame.filter_out_players([acting_player, victim]): representing = savior.will_intervene(action, acting_player, victim) if representing: # logic to doubt savior (ambassador doesnt leave hints, so excess failed callouts) """for doubter in testgame.filter_out_players([acting_player, savior, victim]): if doubter.will_callout('block_steal', savior): if action not in savior.valid_blocks: acting_player.perform(action, victim) self.ACTIONS[acting_player.alpha].append(action) raise QuestionInfluence(doubter, savior, representing, testgame.court_deck, 'block_steal') """ for spectators in testgame.filter_out_players([acting_player, savior, victim]): spectators.didnt_block_as["spectator"].extend([action]) raise BlockedAction(action, acting_player, victim, savior) for doubter in testgame.filter_out_players([acting_player]): if doubter.will_callout(action, acting_player): if action in acting_player.valid_actions: acting_player.perform(action, victim) ACTIONS[acting_player.alpha].append(action) raise QuestionInfluence(doubter, acting_player, "Captain", testgame.court_deck, "steal") acting_player.perform(action, victim) ACTIONS[acting_player.alpha].append(action) for spectators in testgame.filter_out_players([acting_player]): spectators.didnt_block_as["spectator"].extend([action]) break elif action == "assassinate": if remaining_opponent: victim = remaining_opponent else: for opponent in testgame.filter_out_players([acting_player]): if not acting_player.wins_duel( opponent ) and random() > AI_Persona.probability_player_influences( testgame.players, opponent, "Contessa", acting_player ): victim = opponent break else: victim = acting_player.select_opponent(testgame.players) if action in victim.valid_blocks: raise BlockedAction(action, acting_player, victim, None) else: for savior in testgame.filter_out_players([acting_player, victim]): representing = savior.will_intervene(action, acting_player, victim) if representing: for spectators in testgame.filter_out_players([acting_player, savior, victim]): spectators.didnt_block_as["spectator"].extend([action]) # omitted logic to doubt savior (contessa doesnt leave hints, so excess failed callouts) raise BlockedAction(action, acting_player, victim, savior) for doubter in testgame.filter_out_players([acting_player]): if doubter.will_callout(action, acting_player): if action in acting_player.valid_actions: position, random_target = victim.random_remaining_influence acting_player.perform(action, random_target) ACTIONS[acting_player.alpha].append(action) victim.remove_suspicion(str(random_target)) raise QuestionInfluence( doubter, acting_player, "Assassin", testgame.court_deck, "assassinate" ) position, random_target = victim.random_remaining_influence acting_player.perform(action, random_target) victim.remove_suspicion(str(random_target)) ACTIONS[acting_player.alpha].append(action) for spectators in testgame.filter_out_players([acting_player, victim]): spectators.didnt_block_as["spectator"].extend([action]) break elif action == "exchange": for doubter in testgame.filter_out_players([acting_player]): if ( doubter.will_callout(action, acting_player) and doubter.plays_numbers and random() > AI_Persona.probability_player_influences( testgame.players, acting_player, "Ambassador", doubter ) ): if action in acting_player.valid_actions: acting_player.perform(action, testgame.court_deck) ACTIONS[acting_player.alpha].append(action) raise QuestionInfluence( doubter, acting_player, "Ambassador", testgame.court_deck, "exchange" ) acting_player.perform(action, testgame.court_deck) ACTIONS[acting_player.alpha].append(action) break except IllegalAction as e: ILL_ACT[acting_player.alpha].append(e.message) except IllegalTarget as e: ILL_TAR[acting_player.alpha].append(e.message) except BlockedAction as e: if e.spectator: BLOCKS_SAVIOR[e.spectator.saved_personality].append(action) else: BLOCKS_VICTIM[e.victim.saved_personality].append(action) break except QuestionInfluence as e: DOUBTS_ACTIONS[e.doubter.saved_personality].append(e.action) DOUBTS_RIGHT[e.doubter.saved_personality].append(e.doubter_is_correct) DOUBTS_ACTIONS_RIGHT[e.action].append(e.doubter_is_correct) threshold = e.alleged_bluffer.judge_player.get(e.alleged_influence, 0) if e.doubter_is_correct: DOUBTS_THRESHOLD_RIGHT[e.doubter.saved_personality].append(threshold) else: DOUBTS_THRESHOLD_WRONG[e.doubter.saved_personality].append(threshold) break