[81] | 1 | from typing import List, Any
|
---|
| 2 |
|
---|
| 3 | from geniusweb.actions.Action import Action
|
---|
| 4 | from geniusweb.actions.EndNegotiation import EndNegotiation
|
---|
| 5 | from geniusweb.actions.Offer import Offer
|
---|
| 6 | from geniusweb.actions.PartyId import PartyId
|
---|
| 7 | from geniusweb.inform.Inform import Inform
|
---|
| 8 | from geniusweb.inform.YourTurn import YourTurn
|
---|
| 9 | from geniusweb.protocol.ProtocolException import ProtocolException
|
---|
| 10 | from geniusweb.protocol.session.mopac.phase.DefaultPhase import DefaultPhase
|
---|
| 11 | from geniusweb.protocol.session.mopac.phase.Phase import Phase
|
---|
| 12 | from geniusweb.protocol.session.mopac.phase.VotingPhase import VotingPhase
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | class OfferPhase (DefaultPhase):
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | def With(self, actor:PartyId , action:Action ,timems:int)->"OfferPhase" :
|
---|
| 19 | try:
|
---|
| 20 | self._checkAction(actor, action, timems)
|
---|
| 21 | except ProtocolException as ex:
|
---|
| 22 | return self.WithException(ex)
|
---|
| 23 | return OfferPhase(self._partyStates.WithAction(action), self._deadline, self._evaluator);
|
---|
| 24 |
|
---|
| 25 | def getInform(self)->Inform :
|
---|
| 26 | return YourTurn()
|
---|
| 27 |
|
---|
| 28 | def WithException(self, e:ProtocolException) -> "OfferPhase" :
|
---|
| 29 | # don't print to stdout
|
---|
| 30 | # System.out.println("Party kicked because of protocol exception:" + e);
|
---|
| 31 | return OfferPhase(self._partyStates.WithException(e), self._deadline,
|
---|
| 32 | self._evaluator)
|
---|
| 33 |
|
---|
| 34 | def finish(self)->Phase :
|
---|
| 35 | return OfferPhase(self._partyStates.finish(), self._deadline, self._evaluator)
|
---|
| 36 |
|
---|
| 37 | def _checkedNext(self, deadln:int) ->VotingPhase :
|
---|
| 38 | return VotingPhase(self._getOffers(), self._partyStates.flush(), deadln,
|
---|
| 39 | self._evaluator)
|
---|
| 40 |
|
---|
| 41 | def _getOffers(self)->List[Offer] :
|
---|
| 42 | return self._partyStates.getActionsOfType(Offer)
|
---|
| 43 |
|
---|
| 44 | def getAllowedActions(self)->List[Any] : #Class<? extends Action>>
|
---|
| 45 | return [Offer, EndNegotiation]
|
---|
| 46 |
|
---|