1 | package geniusweb.protocol.session.mopac.phase;
|
---|
2 |
|
---|
3 | import java.util.Arrays;
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.stream.Collectors;
|
---|
6 |
|
---|
7 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
8 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
9 |
|
---|
10 | import geniusweb.actions.Action;
|
---|
11 | import geniusweb.actions.EndNegotiation;
|
---|
12 | import geniusweb.actions.Offer;
|
---|
13 | import geniusweb.actions.PartyId;
|
---|
14 | import geniusweb.inform.Inform;
|
---|
15 | import geniusweb.inform.YourTurn;
|
---|
16 | import geniusweb.issuevalue.Bid;
|
---|
17 | import geniusweb.protocol.ProtocolException;
|
---|
18 | import geniusweb.protocol.session.mopac.PartyStates;
|
---|
19 | import geniusweb.voting.VotingEvaluator;
|
---|
20 |
|
---|
21 | public class OfferPhase extends DefaultPhase {
|
---|
22 |
|
---|
23 | @JsonCreator
|
---|
24 | public OfferPhase(@JsonProperty("partyStates") PartyStates partyStates,
|
---|
25 | @JsonProperty("deadlinems") Long deadlinems,
|
---|
26 | @JsonProperty("evaluator") VotingEvaluator evaluator) {
|
---|
27 | super(partyStates, deadlinems, evaluator);
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public OfferPhase with(PartyId actor, Action action, long timems) {
|
---|
32 | try {
|
---|
33 | checkAction(actor, action, timems);
|
---|
34 | } catch (ProtocolException ex) {
|
---|
35 | return this.with(ex);
|
---|
36 | }
|
---|
37 | return new OfferPhase(partyStates.with(action), deadline, evaluator);
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public Inform getInform() {
|
---|
42 | return new YourTurn();
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public OfferPhase with(ProtocolException e) {
|
---|
47 | System.out.println("Party kicked because of protocol exception:" + e);
|
---|
48 | return new OfferPhase(partyStates.with(e), deadline, evaluator);
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public Phase finish() {
|
---|
53 | return new OfferPhase(partyStates.finish(), deadline, evaluator);
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public VotingPhase checkedNext(long deadln) {
|
---|
58 | return new VotingPhase(getOffers(), partyStates.flush(), deadln,
|
---|
59 | evaluator);
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected List<Bid> getOffers() {
|
---|
63 | return partyStates.getActions(Offer.class).stream()
|
---|
64 | .map(offer -> offer.getBid()).collect(Collectors.toList());
|
---|
65 | }
|
---|
66 |
|
---|
67 | @Override
|
---|
68 | public List<Class<? extends Action>> getAllowedActions() {
|
---|
69 | return Arrays.asList(Offer.class, EndNegotiation.class);
|
---|
70 | }
|
---|
71 |
|
---|
72 | }
|
---|