1 | package negotiator.parties;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import genius.core.AgentID;
|
---|
6 | import genius.core.Bid;
|
---|
7 | import genius.core.actions.Accept;
|
---|
8 | import genius.core.actions.Action;
|
---|
9 | import genius.core.actions.Offer;
|
---|
10 | import genius.core.actions.OfferForVoting;
|
---|
11 | import genius.core.actions.Reject;
|
---|
12 | import genius.core.parties.AbstractNegotiationParty;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Basic voting implementation: this agent accepts and rejects offers with a 50%
|
---|
16 | * chance.
|
---|
17 | * <p/>
|
---|
18 | * The class was created as part of a series of agents used to understand the
|
---|
19 | * api better
|
---|
20 | *
|
---|
21 | * @author David Festen
|
---|
22 | */
|
---|
23 | public class RandomFiftyFiftyNegotiationParty extends AbstractNegotiationParty {
|
---|
24 |
|
---|
25 | private Bid lastBid;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * If placing offers: do random offer if voting: accept/reject with a 50%
|
---|
29 | * chance on both
|
---|
30 | *
|
---|
31 | * @param possibleActions
|
---|
32 | * List of all actions possible.
|
---|
33 | * @return The chosen action
|
---|
34 | */
|
---|
35 | @Override
|
---|
36 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
37 |
|
---|
38 | // if we are the first party, place offer.
|
---|
39 | if (possibleActions.contains(OfferForVoting.class)) {
|
---|
40 | return new OfferForVoting(getPartyId(), generateRandomBid());
|
---|
41 | }
|
---|
42 |
|
---|
43 | // else do 50/50 accept or reject
|
---|
44 | return rand.nextBoolean() ? new Accept(getPartyId(), lastBid) : new Reject(getPartyId(), lastBid);
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Processes action messages received by a given sender.
|
---|
49 | *
|
---|
50 | * @param sender
|
---|
51 | * The initiator of the action
|
---|
52 | * @param arguments
|
---|
53 | * The action performed
|
---|
54 | */
|
---|
55 | @Override
|
---|
56 | public void receiveMessage(AgentID sender, Action action) {
|
---|
57 | if (action instanceof Offer) {
|
---|
58 | lastBid = ((Offer) action).getBid();
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public String getDescription() {
|
---|
64 | return "Random Fifty-Fifty Party";
|
---|
65 | }
|
---|
66 |
|
---|
67 | }
|
---|