Exemplo n.º 1
0
    def play(self):
        # define what the trantor should do
        self.state = self.action_to_perform()

        if self.state == State.SEARCH_FOOD:
            return self.action_to_find_resource(Resource.FOOD)

        # check number of food hold by this trantor (the food will
        # be decreased by the server without the client being notifed, refresh
        # inventory to check current state of food)
        if random.randint(1, 30) == 1:
            return 'inventaire'

        # check if there is enough connection slots for new trantors to join
        if random.randint(1, 150) == 1:
            return 'connect_nbr'

        if self.state == State.SEARCH_STONE:
            if self.voir == None:
                return 'voir'
            res = self.stone_to_find()
            # self.action_to_perform evaluate if we have all required resources
            # so res should not be none
            if res == None:
                return 'inventaire'
            return self.action_to_find_resource(res)

        if self.state == State.JOIN_TRANTOR_FOR_INCANTATION:
            msg = self.messages.someone_to_join(self.team, self.level)
            action = msg.action_to_join_sender()
            if action == None:
                return message.message_to_cmd(
                        message.incantation_ready(self.team, self.level), self)
            else:
                return action

        if self.state == State.START_INCANTATION:
            if self.enough_trantor_for_incantation():
                return 'incantation'
            return message.message_to_cmd(
                    message.incantation_call(self.team, self.level), self)
Exemplo n.º 2
0
 def test_action_to_perform(self):
     trantor = TestTrantor.new_trantor(2, Inventory.from_nbrs(5, 5, 5, 5, 5, 5, 5))
     trantor.messages.add_msg('message 0 0 0 0 0 ' + message.incantation_call(2)[10:])
     action = trantor.action_to_perform()
     self.assertTrue(action == State.JOIN_TRANTOR_FOR_INCANTATION)