Beispiel #1
0
 def get_formation(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)
     m = min(strat)
     if m < 0:
         strat += np.array([1 - m, 1 - m, 1 - m])
         assert min(strat) > 0
     nstrat = normalize(strat)
     return rps.FormationOrder(
         np.random.choice(FORMATION_ORDER_LIST, p=nstrat))
Beispiel #2
0
 def get_formation(self, battle):
     mat = self.get_formation_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.FormationOrder(np.random.choice(['A', 'D', 'I'], p=strat))
Beispiel #3
0
    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])
Beispiel #4
0
 def get_formation_matrix(self, battle):
     # logger.debug("AI for formation matrix")
     matrix = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
     for i, strat0 in enumerate(FORMATION_ORDER_LIST):
         for j, strat1 in enumerate(FORMATION_ORDER_LIST):
             # logger.debug("{} vs {}".format(i,j))
             strat_strs = [strat0, strat1]
             for _ in range(3):
                 tempbattle = battle.imaginary_copy("AI_RANDOM_COMMITTER")
                 for k in [0, 1]:
                     tempbattle.armies[k].formation = rps.FormationOrder(
                         strat_strs[k])
                 init_eval = battle_edge_estimate(tempbattle, 0)
                 # simulate the rest of the turn; should get orders and then resolve them
                 tempbattle._get_orders()
                 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
Beispiel #5
0
 def get_formation(self, battle):
     return rps.FormationOrder('I')
Beispiel #6
0
 def get_formation(self, battle):
     return rps.FormationOrder(np.random.choice(FORMATION_ORDER_LIST))
Beispiel #7
0
 def get_formation(self, battle):
     return rps.FormationOrder(
         battle.battlescreen.input_battle_order("FORMATION_ORDER",
                                                self.armyid))