def delegate(self, goal_wrapper, client_id, auction_steps=None, own_cost=CostEvaluatorBase.IMPOSSIBLE_COSTS, known_depth=None): """ Makes a delegation for the goal and starts an auction for this delegation. Adds my own cost as a proposal if wanted. The auction will be closed after the given number of steps were taken, a winner will be determined and the goal will be delegated to that winner. :param goal_wrapper: wrapper for the goal that should be delegated :type goal_wrapper: GoalWrapperBase :param client_id: ID of the client who starts this delegation :type client_id: int :param auction_steps: number of steps that are waited for proposals while the auction is running :type auction_steps: int :param own_cost: cost if i have to achieve the goal myself, greater than 0 if not achievable for me :type own_cost: int :param known_depth: if a specific delegation depth is known for this delegation, give this depth here :type known_depth: int :return: the auction_id of the auction :rtype: int :raises DelegationError: if the MAX_DELEGATION_DEPTH is reached """ if auction_steps is None: auction_steps = self.DEFAULT_AUCTION_STEPS if known_depth is not None: depth = known_depth elif self.depth_checking_possible: depth = self._current_delegation_depth else: depth = -1 if not self._check_depth(depth=depth): raise DelegationError("MAX_DELEGATION_DEPTH is reached") new = Delegation(goal_wrapper=goal_wrapper, auction_id=self.get_new_auction_id(), auction_steps=auction_steps, client_id=client_id, depth=depth, max_timeout_steps=self.MAX_CONSECUTIVE_TIMEOUTS) self._delegations.append(new) self._start_auction(delegation=new) if own_cost > 0: proposal = Proposal(name=self._name, value=own_cost) new.add_proposal(proposal=proposal) return new.auction_id
def create_delegation(self): system('cls') country = input("Enter the country: ") if self.find_delegation(country) == -1: num_players = int(input("Enter the delegation's number players: ")) gold_medals = int(input("Enter the delegation's gold medals: ")) silver_modals = int( input("Enter the delegation's silver medals: ")) bronze_medals = int( input("Enter the delegation's bronze medals: ")) new_delegation = Delegation(country, num_players, gold_medals, silver_modals, bronze_medals) self.delegations.append(new_delegation) system('cls') print("The delegation was created successful!!") else: system('cls') print("ERROR - The delegation already exists") input()
def test_rejects_spec_with_leading_digit_in_keyword(): specs = ( 'foo to 2bar', '3foo to bar', ) for spec in specs: with pytest.raises(SpecValueError): Delegation(spec)
def test_rejects_spec_with_extra_word(): specs = ( 'foo to bar xyz', 'foo to bar as baz xyz', 'foo xyz to bar', ) for spec in specs: with pytest.raises(SpecValueError): Delegation(spec)
def test_rejects_spec_without_to_clause(): with pytest.raises(SpecValueError): Delegation("foo")
def test_parses_valid_spec_with_name(): deleg = Delegation("foo to bar as baz") attr_target_name = (deleg.attr_name, deleg.target_name, deleg.name) assert attr_target_name == ('foo', 'bar', 'baz')
def test_parses_valid_minimal_spec(): deleg = Delegation("foo to bar") attr_target = (deleg.attr_name, deleg.target_name) assert attr_target == ('foo', 'bar')
def test_rejects_spec_with_invalid_char(): with pytest.raises(SpecValueError): Delegation("foo! to bar")