from .strategy import *


class SimpleMindAI(PlayerAIBase):

    def __init__(self):
        self.round = 0
        self.strategy = None

    def get_name(self):
        return "SimpleMind"

    def start_of_game(self):
        self.round = 0

    def start_of_turn(self, game_state, player):
        if player.ai is self:
            if self.round == 0:
                self._initialise(game_state, player)
            self.round += 1
            self.strategy.update(game_state)
            self.strategy.decide_mode()
            self.strategy.deal_init(game_state)
            self.strategy.display_log(False)
            self.strategy.show(game_state)
        if self.round > 0:
            self.strategy.ply_in_action = player

    #----- make deals -----
    def propose_deal(self, game_state, player):
        # workaround for start_of_game initialisation
        if self.strategy is None:
            self._initialise(game_state, player)
        return self.strategy.propose_deal(game_state)

    def deal_result(self, deal_info):
        self.strategy.deal_result(deal_info)

    def deal_proposed(self, game_state, player, deal_proposal):
        # workaround for start_of_game initialisation
        if self.strategy is None:
            self._initialise(game_state, player)
        return self.strategy.deal_proposed(game_state, deal_proposal)

    def deal_completed(self, deal_result):
        if self.strategy is not None:
            return self.strategy.deal_completed(deal_result)

    #----- unowned property, take it or leave it -----
    def landed_on_unowned_property(self, game_state, player, property):
        return self.strategy.landed_on_unowned_property(game_state, property)

    def property_offered_for_auction(self, game_state, player, property):
        # workaround for start_of_game initialisation
        if self.strategy is None:
            self._initialise(game_state, player)
        self.strategy.update(game_state)
        return self.strategy.property_offered_for_auction(game_state, property)

    def auction_result(self, status, property, player, amount_paid):
        self.strategy.auction_result(status, property, player, amount_paid)

    #----- manage cash flow -----
    def money_will_be_taken(self, player, amount):
        if self.strategy is not None:
            self.strategy.set_money_will_be_taken(amount)

    def money_taken(self, player, amount):
        self.strategy.money_will_be_taken = 0

    #----- build house -----
    def unmortgage_properties(self, game_state, player):
        return self.strategy.unmortgage_properties(game_state)

    def build_houses(self, game_state, player):
        return self.strategy.build_houses(game_state)

    def sell_houses(self, game_state, player):
        return self.strategy.sell_houses(game_state)

    def mortgage_properties(self, game_state, player):
        # workaround for start_of_game initialisation
        if self.strategy is None:
            self._initialise(game_state, player)
        self.strategy.update(game_state)
        return self.strategy.mortgage_properties(game_state)

    def eminent_domain(self, game_state, player):
        if self.strategy is not None:
            self.strategy.set_eminent_domain(game_state)

    #----- other stuff -----
    def get_out_of_jail(self, game_state, player):
        return self.strategy.get_out_of_jail(game_state)

    def _initialise(self, game_state, player):
        self.strategy = Strategy(game_state, player)

    #----- unused -----
    def player_landed_on_square(self, game_state, square, player):
        pass

    def money_given(self, player, amount):
        pass

    def got_get_out_of_jail_free_card(self):
        pass

    def players_birthday(self):
        return "Happy Birthday!"

    def pay_ten_pounds_or_take_a_chance(self, game_state, player):
        return PlayerAIBase.Action.PAY_TEN_POUND_FINE

    def player_went_bankrupt(self, player):
        pass

    def player_ran_out_of_time(self, player):
        pass

    def game_over(self, winner, maximum_rounds_played):
        pass

    def ai_error(self, message):
        pass


