source: src/main/java/agents/SimpleTFTAgent.java@ 209

Last change on this file since 209 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: 5.5 KB
Line 
1package agents;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6
7import genius.core.Agent;
8import genius.core.Bid;
9import genius.core.Domain;
10import genius.core.actions.Action;
11import genius.core.actions.Offer;
12import genius.core.issue.Issue;
13import genius.core.issue.Value;
14import genius.core.issue.ValueReal;
15
16/**
17 *
18 * @author TB Always bids the highest for himself
19 *
20 */
21public class SimpleTFTAgent extends Agent {
22 private static int round = 0;
23 private Bid myLastBid = null;
24 private Action opponentAction = null;
25 private List<Bid> opponentPreviousBids;
26
27 public void init() {
28 opponentPreviousBids = new ArrayList<Bid>();
29 }
30
31 @Override
32 public String getVersion() {
33 return "1.0";
34 }
35
36 public void ReceiveMessage(Action opponentAction) {
37 this.opponentAction = opponentAction;
38 }
39
40 public Action chooseAction() {
41 Action myAction = null;
42
43 if (round == 0)
44 myAction = chooseOpeningAction();
45 else if (round == 1)
46 myAction = chooseOffer2();
47 else if (round == 2)
48 myAction = chooseOffer3();
49 else if (round == 3)
50 myAction = chooseOffer4();
51 else if (opponentAction instanceof Offer) {
52 myAction = chooseCounterOffer();
53 }
54
55 // We start
56 // if (opponentAction == null)
57 // myAction = chooseOpeningAction();
58 // Opponent started, now it is our turn
59 // else if (myLastBid == null)
60 // myAction = chooseOffer2();
61
62 try {
63 Thread.sleep(1000);
64 } catch (InterruptedException e) {
65 e.printStackTrace();
66 }
67
68 // Remember
69 if (myAction instanceof Offer)
70 myLastBid = ((Offer) myAction).getBid();
71 if (opponentAction instanceof Offer)
72 opponentPreviousBids.add(((Offer) opponentAction).getBid());
73
74 System.out.println("Round " + round + ", " + getName() + " offers "
75 + myAction);
76 round++;
77
78 return myAction;
79 }
80
81 private Action chooseCounterOffer() {
82 Bid opponentBid = ((Offer) opponentAction).getBid();
83 double opponentOffer = toOffer(opponentBid);
84 Bid opponentPreviousBid = opponentPreviousBids.get(opponentPreviousBids
85 .size() - 1);
86 double previousOpponentOffer = toOffer(opponentPreviousBid);
87
88 double myPreviousOffer = toOffer(myLastBid);
89
90 // double myOffer = (previousOpponentOffer / opponentOffer) *
91 // myPreviousOffer;
92 double myOffer = (previousOpponentOffer - opponentOffer)
93 + myPreviousOffer;
94
95 if (getName().equals("Agent B"))
96 myOffer = 0.3 - (5.0 / round) * 0.1;
97 Domain domain = utilitySpace.getDomain();
98 Issue pieForOne = domain.getIssues().get(0);
99 HashMap<Integer, Value> myOfferedPackage = new HashMap<Integer, Value>();
100 ValueReal value = new ValueReal(myOffer);
101 myOfferedPackage.put(pieForOne.getNumber(), value);
102 Bid firstBid = null;
103 try {
104 firstBid = new Bid(domain, myOfferedPackage);
105 } catch (Exception e) {
106 e.printStackTrace();
107 }
108 System.out.println(getName() + " previously got "
109 + previousOpponentOffer + " and now gets offer "
110 + opponentOffer + " and counter-offers " + myOffer);
111
112 // if (offeredutil > 0.5)
113 // return new Accept(getAgentID());
114
115 return new Offer(getAgentID(), firstBid);
116 }
117
118 private double toOffer(Bid bid) {
119 Domain domain = utilitySpace.getDomain();
120 Issue pieForOne = domain.getIssues().get(0);
121 try {
122 return ((ValueReal) bid.getValue(pieForOne.getNumber())).getValue();
123 } catch (Exception e) {
124 e.printStackTrace();
125 }
126 return -1;
127 }
128
129 /**
130 * pie voor mij -> pie voor agent A
131 */
132 private ValueReal personalValue2IssueValue(double personalValue) {
133 ValueReal value;
134 if (getName().equals("Agent A"))
135 value = new ValueReal(personalValue);
136 else
137 value = new ValueReal(1 - personalValue);
138 return value;
139 }
140
141 private Action chooseOpeningAction() {
142 Domain domain = utilitySpace.getDomain();
143 Issue pie = domain.getIssues().get(0);
144 HashMap<Integer, Value> myOfferedPackage = new HashMap<Integer, Value>();
145 myOfferedPackage.put(pie.getNumber(), personalValue2IssueValue(0.9));
146 Bid firstBid = null;
147 try {
148 firstBid = new Bid(domain, myOfferedPackage);
149 } catch (Exception e) {
150 e.printStackTrace();
151 }
152
153 return new Offer(getAgentID(), firstBid);
154 }
155
156 private Action chooseOffer2() {
157 Domain domain = utilitySpace.getDomain();
158 Issue pie = domain.getIssues().get(0);
159 HashMap<Integer, Value> myOfferedPackage = new HashMap<Integer, Value>();
160 myOfferedPackage.put(pie.getNumber(), personalValue2IssueValue(0.9));
161 Bid firstBid = null;
162 try {
163 firstBid = new Bid(domain, myOfferedPackage);
164 } catch (Exception e) {
165 e.printStackTrace();
166 }
167
168 return new Offer(getAgentID(), firstBid);
169 }
170
171 private Action chooseOffer3() {
172 Domain domain = utilitySpace.getDomain();
173 Issue pie = domain.getIssues().get(0);
174 HashMap<Integer, Value> myOfferedPackage = new HashMap<Integer, Value>();
175 myOfferedPackage.put(pie.getNumber(), personalValue2IssueValue(0.8));
176 Bid firstBid = null;
177 try {
178 firstBid = new Bid(domain, myOfferedPackage);
179 } catch (Exception e) {
180 e.printStackTrace();
181 }
182
183 return new Offer(getAgentID(), firstBid);
184 }
185
186 private Action chooseOffer4() {
187 Domain domain = utilitySpace.getDomain();
188 Issue pie = domain.getIssues().get(0);
189 HashMap<Integer, Value> myOfferedPackage = new HashMap<Integer, Value>();
190 myOfferedPackage.put(pie.getNumber(), personalValue2IssueValue(0.85));
191 Bid firstBid = null;
192 try {
193 firstBid = new Bid(domain, myOfferedPackage);
194 } catch (Exception e) {
195 e.printStackTrace();
196 }
197
198 return new Offer(getAgentID(), firstBid);
199 }
200}
Note: See TracBrowser for help on using the repository browser.