def __init__(self, parent, actions_manager, to_move, players_info,
                 af_network, actions_history):
        defenses = actions_manager.get_possible_defenses(
            af_network, players_info.defender)
        str_order_sets = [str(x[0]) for x in defenses]
        super().__init__(parent=parent,
                         to_move=to_move,
                         actions=str_order_sets,
                         af_network=af_network,
                         players_info=players_info,
                         actions_history=actions_history)

        #        if not defenses:
        #            self.budget.defender = 0 #in case there is only a small amount of money
        #       else:
        for order_set, cost in defenses:
            net2 = copy_network(af_network)
            net2.submit_buy_orders(order_set)
            actions_history2 = copy.deepcopy(actions_history)
            actions_history2[BUY].append(str(order_set))
            self.children[str(order_set)] = PPAMarketMoveGameState(
                self, actions_manager, MARKET,
                PPAPlayersHiddenInfo(players_info.attacker_attack,
                                     players_info.attacker_pid,
                                     players_info.defender - cost,
                                     players_info.attacker_budget), net2,
                actions_history2)
        self._information_set = ".{0}.{1}".format(
            players_info.defender, 'D_HISTORY:' + str(actions_history[BUY]))
        self.tree_size = 1 + sum([x.tree_size for x in self.children.values()])
    def __init__(self, parent, actions_manager, to_move, players_info,
                 af_network, actions_history):
        actions = actions_manager.get_possible_attacks_from_portfolio(
            players_info.attacker_attack, af_network.no_more_sell_orders())
        self.terminal = not actions

        super().__init__(parent=parent,
                         to_move=to_move,
                         actions=[str(x['action_subset']) for x in actions],
                         af_network=af_network,
                         players_info=players_info,
                         actions_history=actions_history)

        for action in actions:
            order_set = action['action_subset']
            net2 = copy_network(af_network)
            net2.submit_sell_orders(order_set)
            actions_history2 = copy.deepcopy(actions_history)
            actions_history2[SELL].append(str(order_set))
            self.children[str(order_set)] = PPADefenderMoveGameState(
                self,
                actions_manager,
                DEFENDER,
                PPAPlayersHiddenInfo(action['remaining_orders'],
                                     players_info.attacker_pid,
                                     players_info.defender,
                                     players_info.attacker_budget),
                net2,
                actions_history2,
            )

        self.tree_size = 1 + sum([x.tree_size for x in self.children.values()])
        self._information_set = ".{0}.{1}.{2}".format(
            str(players_info.attacker_budget), players_info.attacker_pid,
            'A_HISTORY:' + str(actions_history[SELL]))
    def __init__(self, parent, actions_manager, to_move, history_assets_dict,
                 budget, af_network, actions_history):
        defenses = actions_manager.get_possible_defenses(
            af_network, budget.defender, history_assets_dict)
        str_order_sets = [str(x[0]) for x in defenses]
        super().__init__(parent=parent,
                         to_move=to_move,
                         actions=str_order_sets,
                         history_assets_dict=history_assets_dict,
                         af_network=af_network,
                         budget=budget,
                         actions_history=actions_history)

        #        if not defenses:
        #            self.budget.defender = 0 #in case there is only a small amount of money
        #       else:
        for order_set, cost in defenses:
            net2 = copy_network(af_network)
            net2.submit_buy_orders(order_set)
            actions_history2 = copy.deepcopy(actions_history)
            actions_history2[BUY].append(str(order_set))
            self.children[str(order_set)] = MarketMoveGameState(
                self, actions_manager, MARKET,
                self._update_asset_history(order_set, BUY),
                Budget(budget.attacker, budget.defender - cost), net2,
                actions_history2)
        self._information_set = ".{0}.{1}".format(
            str(budget.defender), 'D_HISTORY:' + str(actions_history[BUY]))
        self.tree_size = 1 + sum([x.tree_size for x in self.children.values()])
    def __init__(self, parent, actions_manager, to_move, players_info,
                 af_network, actions_history):
        self.terminal = af_network.no_more_sell_orders()
        if self.terminal:
            actions = []
        else:
            net2 = copy_network(af_network)
            actions = [str(net2.simulate_trade())]

        super().__init__(parent=parent,
                         to_move=to_move,
                         actions=actions,
                         af_network=af_network,
                         players_info=players_info,
                         actions_history=actions_history)

        self._information_set = ".{0}.{1}.{2}".format(
            'MARKET_HISTORY:' + str(actions_history[SIM_TRADE]),
            'BUY:' + str(af_network.buy_orders),
            'SELL:' + str(af_network.sell_orders))

        if actions:
            action = actions[0]
            actions_history2 = copy.deepcopy(actions_history)
            actions_history2[SELL].append(action)
            actions_history2[BUY].append(action)
            actions_history2[SIM_TRADE].append(action)
            self.children[action] = PPAAttackerMoveGameState(
                self, actions_manager, ATTACKER, players_info, net2,
                actions_history2)
        self.tree_size = 1 + sum([x.tree_size for x in self.children.values()])
    def __init__(self, parent, actions_manager, to_move, history_assets_dict,
                 budget, af_network, actions_history):
        #        if af_network.margin_calls():
        #            str_order_sets = []
        #        else:
        #            attacks = actions_manager.get_possible_attacks(budget.attacker, history_assets_dict)
        #            str_order_sets = [str(x[0]) for x in attacks]
        attacks = actions_manager.get_possible_attacks(budget.attacker,
                                                       history_assets_dict)
        str_order_sets = [str(x[0]) for x in attacks]
        super().__init__(parent=parent,
                         to_move=to_move,
                         actions=str_order_sets,
                         history_assets_dict=history_assets_dict,
                         af_network=af_network,
                         budget=budget,
                         actions_history=actions_history)
        self._information_set = ".{0}.{1}".format(
            str(budget.attacker), 'A_HISTORY:' + str(actions_history[SELL]))
        if not str_order_sets:
            return

        for order_set, cost in attacks:
            net2 = copy_network(af_network)
            net2.submit_sell_orders(order_set)
            actions_history2 = copy.deepcopy(actions_history)
            actions_history2[SELL].append(str(order_set))
            self.children[str(order_set)] = DefenderMoveGameState(
                self, actions_manager, DEFENDER,
                self._update_asset_history(order_set, SELL),
                Budget(budget.attacker - cost, budget.defender), net2,
                actions_history2)

        self.tree_size = 1 + sum([x.tree_size for x in self.children.values()])