def physical_clash(battle, context, bv, narrator): csource = context.csource ctarget = context.ctarget vulnerable = (csource.order == rps.FinalOrder('A')) and (ctarget.order == rps.FinalOrder('I')) Event(battle, "physical_strike", context.copy({"vulnerable": vulnerable})).activate() if random.random() < 0.5: Event(battle, "physical_strike", context.clean_switch({'cause': 'retaliation'})).activate()
def indirect_raid(battle, context, bv, narrator): csource = context.csource ctarget = context.ctarget if csource.attacked_by: Event(battle, "action_already_used", context).defer('Q_RESOLVE') return Event(battle, "engage", context).activate() # tactic 1: raid vulnerable = bool(ctarget.order == rps.FinalOrder('D')) Event(battle, "arrow_strike", context.copy({"vulnerable": vulnerable})).defer("Q_RESOLVE")
def get_final(self, bat): choose_expert = np.random.choice( [self.expert_yomi_1, self.expert_yomi_2, self.expert_yomi_3], p=[0.6, 0.3, 0.1]) strat = choose_expert(bat) strat += self.expert_commitment(bat) m = min(strat) if m < 0: strat += np.array([1 - m, 1 - m, 1 - m]) assert min(strat) > 0 nstrat = normalize(strat) return rps.FinalOrder(np.random.choice(FINAL_ORDER_LIST, p=nstrat))
def clear(self): """ Wipes state; kills everything except deck. used when we clear state before a turn. """ self.sc_dict = {} # self.stacks = {'A':[], 'D':[], 'I':[]} for un in self.army.present_units(): for sk in un.skills: sc_str = skills.get_skillcard(sk) if sc_str: for order_str in ['A', 'D', 'I']: sc = SkillCard(sc_str, un, rps.FinalOrder(order_str)) self.sc_dict[sc] = False # in our deck, not yet drawn
def get_final(self, battle): mat = self.get_final_matrix(battle) rstrats0, rstrats1, value = williams_solve_old(mat.tolist(), 100) strats = [normalize(rstrats0), normalize(rstrats1)] strat = strats[self.army.armyid] # logger.debug("Beststrats (A/D/I): {:4.3f}/{:4.3f}/{:4.3f} vs {:4.3f}/{:4.3f}/{:4.3f}, value={}".format(*(strats[0] + strats[1]), value)) battle.battlescreen.yprint( "Beststrats (A/D/I): {:4.3f}/{:4.3f}/{:4.3f} vs {:4.3f}/{:4.3f}/{:4.3f}, value={}" .format(*(strats[0] + strats[1]), value), mode=['AI']) battle.battlescreen.yprint( "Nash equilibria (A/D/I): {:4.3f}/{:4.3f}/{:4.3f}".format(*strat), mode=['AI']) return rps.FinalOrder(np.random.choice(FINAL_ORDER_LIST, p=strat))
def indirect_order(battle, context, bv, narrator): ctarget = context.ctarget ctarget.order = rps.FinalOrder('I') enemyunits = ctarget.army.other_army().present_units() if not enemyunits: ctarget.targetting = ("defending", ctarget) return cnewsource = ctarget # new event cnewtarget = random.choice(enemyunits) cnewsource.targetting = ("sneaking", cnewtarget) newcontext = contexts.Context({ "csource": cnewsource, "ctarget": cnewtarget }) Event(battle, "indirect_raid", newcontext).defer("Q_MANUEVER")
def input_battle_order(self, order_type, armyid): """ Input a list of orders. The orders are objects (probably rps.Order()) with - colored_abbrev method for display - str method for input """ if order_type == 'FORMATION_ORDER': order_list = [ rps.FormationOrder(s) for s in rps.FORMATION_ORDER_LIST ] else: assert order_type == 'FINAL_ORDER' order_list = [rps.FinalOrder(s) for s in rps.FINAL_ORDER_LIST] pausestr_1 = PAUSE_STRS[order_type].format(**{"armyid": armyid}) render_list = [order.color_abbrev() for order in order_list] pausestr_2 = " ({}):$[7]$".format("/".join(render_list)) return self._get_input(pausestr_1 + pausestr_2, [str(order).upper() for order in order_list])
def attack_order(battle, context, bv, narrator): """ what we do in a *committed* attack order (we no longer consider statuses, etc;) """ ctarget = context.ctarget ctarget.order = rps.FinalOrder('A') enemy = ctarget.army.other_army() enemyunits = enemy.present_units() if not enemyunits: ctarget.targetting = ("defending", ctarget) return cnewsource = context.ctarget # new event cnewtarget = random.choice(enemyunits) cnewsource.targetting = ("marching", cnewtarget) newcontext = contexts.Context({ "csource": cnewsource, "ctarget": cnewtarget }) Event(battle, "march", newcontext).defer("Q_MANUEVER")
def get_final_matrix(self, battle): # logger.debug("AI for final matrix") matrix = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) for i, strat0 in enumerate(FINAL_ORDER_LIST): for j, strat1 in enumerate(FINAL_ORDER_LIST): strat_strs = [strat0, strat1] for _ in range(3): tempbattle = battle.imaginary_copy("AI_RANDOM_RANDOM") for k in [0, 1]: tempbattle.armies[k].order = rps.FinalOrder( strat_strs[k]) init_eval = battle_edge_estimate(tempbattle, 0) tempbattle.resolve_orders() post_eval = battle_edge_estimate(tempbattle, 0) matrix[i][j] += post_eval - init_eval # logger.debug(" value: {}".format(matrix[i][j])) # logger.debug("{} vs {}: edge {}".format(strat0, strat1, matrix[i][j])) battle.battlescreen.yprint("{} vs {}: edge {}".format( strat0, strat1, matrix[i][j]), mode=['AI']) return matrix / 3
def defense_order(battle, context, bv, narrator): ctarget = context.ctarget ctarget.order = rps.FinalOrder('D') ctarget.targetting = ("defending", ctarget) Event(battle, "gain_status", context).activate("defended")
def get_final(self, battle): return rps.FinalOrder( battle.battlescreen.input_battle_order("FINAL_ORDER", self.armyid))
def get_final(self, battle): return rps.FinalOrder(str(self.army.formation))
def get_final(self, battle): return rps.FinalOrder(np.random.choice(FINAL_ORDER_LIST))