source: geniuswebcore/geniusweb/protocol/session/mopac/phase/VotingPhase.py@ 88

Last change on this file since 88 was 88, checked in by Bart Vastenhouw, 2 years ago

Added python SimpleRunner GUI

File size: 2.3 KB
Line 
1from typing import List, Any
2
3from geniusweb.actions.Action import Action
4from geniusweb.actions.EndNegotiation import EndNegotiation
5from geniusweb.actions.Offer import Offer
6from geniusweb.actions.PartyId import PartyId
7from geniusweb.actions.Votes import Votes
8from geniusweb.inform.Inform import Inform
9from geniusweb.inform.Voting import Voting
10from geniusweb.protocol.ProtocolException import ProtocolException
11from geniusweb.protocol.session.mopac.PartyStates import PartyStates
12from geniusweb.protocol.session.mopac.phase.DefaultPhase import DefaultPhase
13from geniusweb.protocol.session.mopac.phase.OptInPhase import OptInPhase
14from geniusweb.protocol.session.mopac.phase.Phase import Phase
15from geniusweb.voting.VotingEvaluator import VotingEvaluator
16
17
18class VotingPhase (DefaultPhase):
19
20 def __init__(self, offers: List[Offer],
21 partyStates:PartyStates,
22 deadline: int,
23 evaluator:VotingEvaluator ) :
24 super().__init__(partyStates, deadline, evaluator)
25 self._offers = offers
26 if offers==None:
27 raise ValueError("offers must be not null")
28
29 def With(self, actor:PartyId ,action: Action , now:int)-> "VotingPhase" :
30 try:
31 self._checkAction(actor, action, now)
32 except ProtocolException as ex:
33 return self.WithException(ex)
34 return VotingPhase(self._offers, self._partyStates.WithAction(action), self._deadline,
35 self._evaluator);
36
37 def getInform(self)->Inform :
38 return Voting(self._offers, self._partyStates.getPowers())
39
40 def WithException(self, e:ProtocolException ) ->"VotingPhase" :
41 return VotingPhase(self._offers, self._partyStates.WithException(e), self._deadline,
42 self._evaluator)
43
44 def finish(self)->"VotingPhase" :
45 return VotingPhase(self._offers, self._partyStates.finish(), self._deadline,
46 self._evaluator)
47
48 def _checkedNext(self,deadln:int) ->Phase :
49 return OptInPhase(self.getVotes(), self._partyStates.flush(), deadln,
50 self._evaluator);
51
52 def getAllowedActions(self) ->List[Any]: #Class<? extends Action>>:
53 return [Votes, EndNegotiation]
54
55 def getVotes(self)->List[Votes]:
56 '''
57 @return all votes done in this phase.
58 '''
59 return [ act for act in self._partyStates.getActions() if isinstance(act, Votes)]
60
61 def getOffers(self)->List[Offer]:
62 '''
63 @return the offers received in the {@link OfferPhase}
64 '''
65 return list(self._offers)
Note: See TracBrowser for help on using the repository browser.