source: src/main/java/negotiator/parties/UIAgentExtended.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 3.5 KB
Line 
1package negotiator.parties;
2
3import java.awt.Toolkit;
4import java.util.ArrayList;
5
6import javax.swing.JOptionPane;
7
8import genius.core.Agent;
9import genius.core.Bid;
10import genius.core.SupportedNegotiationSetting;
11import genius.core.actions.Accept;
12import genius.core.actions.Action;
13import genius.core.actions.EndNegotiation;
14import genius.core.actions.Offer;
15import genius.core.utility.AdditiveUtilitySpace;
16
17/**
18 *
19 * @author W.Pasman, modified version of Dmytro's UIAgent
20 */
21public class UIAgentExtended extends Agent {
22 private Action opponentAction = null;
23 private Bid myPreviousBid = null;
24
25 // Alina added...
26 private Bid oppPreviousBid = null;
27 protected int bidCounter = 0;
28 protected NegoRoundData roundData;
29 protected ArrayList<NegoRoundData> historyOfBids = null;
30
31 /** Creates a new instance of UIAgent */
32
33 /**
34 * One agent will be kept alive over multiple sessions. Init will be called
35 * at the start of each nego session.
36 */
37 @Override
38 public String getVersion() {
39 return "2.0";
40 }
41
42 public void init() {
43
44 System.out.println("try to init UIAgent");
45 System.out.println("Utility Space initialized: " + utilitySpace);
46 historyOfBids = new ArrayList<NegoRoundData>();
47
48 }
49
50 private EnterBidDialogExtended getDialog() throws Exception {
51 EnterBidDialogExtended ui = new EnterBidDialogExtended(this, null,
52 true, (AdditiveUtilitySpace) utilitySpace, oppPreviousBid);
53 // alina: dialog in the center- doesnt really work
54 Toolkit t = Toolkit.getDefaultToolkit();
55 int x = (int) ((t.getScreenSize().getWidth() - ui.getWidth()) / 2);
56 int y = (int) ((t.getScreenSize().getHeight() - ui.getHeight()) / 2);
57 ui.setLocation(x, y);
58 return ui;
59 }
60
61 public void ReceiveMessage(Action opponentAction) {
62 this.opponentAction = opponentAction;
63 if (opponentAction instanceof Accept)
64 JOptionPane.showMessageDialog(null,
65 "Opponent accepted your last offer.");
66
67 if (opponentAction instanceof EndNegotiation)
68 JOptionPane.showMessageDialog(null,
69 "Opponent canceled the negotiation session");
70
71 return;
72 }
73
74 public Action chooseAction() {
75 try {
76 return chooseAction1();
77 } catch (Exception e) {
78 e.printStackTrace();
79 }
80 return null;
81 }
82
83 public Action chooseAction1() throws Exception {
84 Action action = getDialog().askUserForAction(opponentAction,
85 myPreviousBid);
86 if ((action != null) && (action instanceof Offer)) {
87 myPreviousBid = ((Offer) action).getBid();
88 if (opponentAction != null) {
89 oppPreviousBid = ((Offer) opponentAction).getBid();
90 roundData = new NegoRoundData(oppPreviousBid, myPreviousBid);
91 historyOfBids.add(roundData);
92 }
93 // does this happen only the first time?
94 else {
95 roundData = new NegoRoundData(null, myPreviousBid);
96 historyOfBids.add(roundData);
97 }
98 bidCounter++;
99 }
100
101 return action;
102 }
103
104 public boolean isUIAgent() {
105 return true;
106 }
107
108 public Bid getMyPreviousBid() {
109 return myPreviousBid;
110 }
111
112 public Bid getOppPreviousBid() {
113 return oppPreviousBid;
114 }
115
116 @Override
117 public SupportedNegotiationSetting getSupportedNegotiationSetting() {
118 return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
119 }
120}
121
122class NegoRoundData {
123 private Bid lastOppBid;
124 private Bid ourLastBid;
125
126 public NegoRoundData(Bid lastOppBid, Bid ourLastBid) {
127 this.lastOppBid = lastOppBid;
128 this.ourLastBid = ourLastBid;
129 }
130
131 public Bid getOppentBid() {
132 return lastOppBid;
133 }
134
135 public Bid getOurBid() {
136 return ourLastBid;
137 }
138
139}
Note: See TracBrowser for help on using the repository browser.