Ignore:
Timestamp:
10/11/21 16:01:02 (3 years ago)
Author:
Wouter Pasman
Message:

Added MOPAC protocol. For GeniusWeb 2.0.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • geniuswebcore/test/testparty/TestParty.py

    r67 r69  
    22import logging
    33import sys
    4 from typing import Dict, Any
     4from typing import Dict, Any, Set
    55from typing import cast
    66
     
    99from geniusweb.actions.Offer import Offer
    1010from geniusweb.actions.PartyId import PartyId
     11from geniusweb.actions.Vote import Vote
     12from geniusweb.actions.Votes import Votes
    1113from geniusweb.inform.ActionDone import ActionDone
    1214from geniusweb.inform.Finished import Finished
    1315from geniusweb.inform.Inform import Inform
     16from geniusweb.inform.OptIn import OptIn
    1417from geniusweb.inform.Settings import Settings
     18from geniusweb.inform.Voting import Voting
    1519from geniusweb.inform.YourTurn import YourTurn
    1620from geniusweb.issuevalue.Bid import Bid
     
    3539        #self.getReporter().log(logging.INFO,"received info:"+str(info))
    3640        if isinstance(info,Settings) :
    37             settings:Settings=cast(Settings,info)   
    38             self._me = settings.getID()
    39             self._protocol = settings.getProtocol()
     41            self._settings:Settings=cast(Settings,info)   
     42            self._me = self._settings.getID()
     43            self._protocol = self._settings.getProtocol()
    4044        elif isinstance(info, ActionDone):
    4145            action:Action=cast( ActionDone,info).getAction()
     
    5458                val(self.getConnection()).send(offer)
    5559                self.getReporter().log(logging.INFO,"sent empty offer:")
     60        elif isinstance(info, Voting):
     61            # MOPAC protocol
     62            self._lastvotes = self._vote(cast(Voting, info));
     63            val(self.getConnection()).send(self._lastvotes)
     64        elif isinstance(info, OptIn):
     65            val(self.getConnection()).send(self._lastvotes)
     66
    5667        elif isinstance(info, Finished):
    5768            self.terminate()
     
    7687            self._profile = None
    7788
     89    def _vote(self, voting:Voting) ->Votes :
     90        '''
     91        @param voting the {@link Voting} object containing the options
     92       
     93        @return our next Votes. Stupid: vote for all received offers.
     94        '''
     95        votes:Set[Vote]  = set([Vote(self._me, offer.getBid(), 2, 5)\
     96                for offer in voting.getOffers() ])
     97        return Votes(self._me, votes)
Note: See TracChangeset for help on using the changeset viewer.