source: geniuswebcore/geniusweb/actions/Vote.py@ 74

Last change on this file since 74 was 73, checked in by Bart Vastenhouw, 3 years ago

Fix for IssueValue hashcode.

File size: 2.0 KB
RevLine 
[73]1from geniusweb.actions.ActionWithBid import ActionWithBid
2from geniusweb.actions.PartyId import PartyId
3from geniusweb.issuevalue.Bid import Bid
4
5class Vote ( ActionWithBid ):
6 '''
7 A vote is an indication by a party that it conditionally accepts a bid. It's
8 then up to the protocol to determine the outcome.
9 '''
10
11 def __init__(self, actor:PartyId, bid:Bid ,minPower :int , maxPower:int):
12 '''
13 @param id the {@link PartyId} that does the action
14 @param bid the bid that is voted on
15 @param minPower the minimum power this bid must get in order for the vote
16 to be valid. Power is the sum of the powers of the
17 parties that are in the deal. If power=1 for all
18 participants (usually the default) power can be
19 interpreted as number of votes
20 @param maxPower the maximum power this bid must get in order for the vote
21 to be valid. See {@link #minPower}
22 '''
23 super().__init__(actor, bid)
24 self._minPower = minPower
25 self._maxPower = maxPower
26 if bid == None or minPower == None or minPower < 1 or maxPower == None or maxPower < minPower:
27 raise ValueError("Vote must have non-null bid and minVotes, and minPower must be >=1 and maxPower must be >=minPower")
28
29 def getMinPower(self) -> int:
30 '''
31 @return the minimum power this bid must get in order for the vote to be
32 valid.
33 '''
34 return self._minPower
35
36 def getMaxPower(self)->int:
37 '''
38 @return the max power this bid must get in order for the vote to be
39 valid.
40 '''
41 return self._maxPower;
42
43 #Override
44 def __repr__(self) -> str:
45 return "Vote[" + repr(self.getActor()) + "," + repr(self.getBid()) + ","\
46 + repr(self._minPower) + "," + repr(self._maxPower) + "]"
47
48 def __hash__(self):
49 return hash((self._actor, self._bid, self._minPower, self._maxPower))
50
51 def __eq__(self, other):
52 return isinstance(other, self.__class__) and \
53 super().__eq__(other) and self._minPower==other._minPower \
54 and self._maxPower==other._maxPower
55
56
Note: See TracBrowser for help on using the repository browser.