source: src/main/java/negotiator/parties/UINegotiationParty.java@ 61

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

Initial import : Genius 9.0.0

File size: 2.3 KB
Line 
1package negotiator.parties;
2
3import java.util.List;
4
5import javax.swing.JOptionPane;
6
7import genius.core.AgentID;
8import genius.core.Bid;
9import genius.core.SupportedNegotiationSetting;
10import genius.core.actions.Accept;
11import genius.core.actions.Action;
12import genius.core.actions.EndNegotiation;
13import genius.core.actions.Offer;
14import genius.core.parties.AbstractNegotiationParty;
15import genius.core.parties.NegotiationInfo;
16import genius.core.utility.AdditiveUtilitySpace;
17
18/**
19 * @author W.Pasman, modified version of Dmytro's UIAgent
20 */
21public class UINegotiationParty extends AbstractNegotiationParty {
22
23 private Action opponentAction = null;
24
25 private Bid myPreviousBid = null;
26 private Bid mostRecentBid;
27
28 /**
29 * One agent will be kept alive over multiple sessions. Init will be called
30 * at the start of each nego session.
31 */
32 @Override
33 public void init(NegotiationInfo info) {
34 super.init(info);
35
36 }
37
38 @Override
39 public void receiveMessage(AgentID sender, Action arguments) {
40 this.opponentAction = arguments;
41 if (opponentAction instanceof Offer) {
42 mostRecentBid = ((Offer) opponentAction).getBid();
43 }
44
45 if (opponentAction instanceof Accept) {
46 JOptionPane.showMessageDialog(null, "Opponent accepted your last offer.");
47 }
48
49 if (opponentAction instanceof EndNegotiation) {
50 JOptionPane.showMessageDialog(null, "Opponent canceled the negotiation session");
51 }
52 }
53
54 @Override
55 public Action chooseAction(List<Class<? extends Action>> possibleActions) {
56 Action action = null;
57 try {
58 EnterBidDialog2 dialog = new EnterBidDialog2(this, getPartyId(), null, true,
59 (AdditiveUtilitySpace) utilitySpace, possibleActions.contains(Accept.class) ? mostRecentBid : null);
60
61 action = dialog.askUserForAction(opponentAction, myPreviousBid, mostRecentBid);
62 if ((action != null) && (action instanceof Offer)) {
63 myPreviousBid = ((Offer) action).getBid();
64 }
65 } catch (Exception e) {
66 System.out.println("Problem in UIAgent2.chooseAction:" + e.getMessage());
67 e.printStackTrace();
68 }
69
70 return action;
71 }
72
73 public SupportedNegotiationSetting getSupportedNegotiationSetting() {
74 return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
75 }
76
77 @Override
78 public String getDescription() {
79 return "UI Party";
80 }
81}
Note: See TracBrowser for help on using the repository browser.