source: src/main/java/negotiator/parties/RandomFiftyFiftyNegotiationParty.java@ 52

Last change on this file since 52 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 1.7 KB
Line 
1package negotiator.parties;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.actions.Accept;
8import genius.core.actions.Action;
9import genius.core.actions.Offer;
10import genius.core.actions.OfferForVoting;
11import genius.core.actions.Reject;
12import 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 */
23public 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}
Note: See TracBrowser for help on using the repository browser.