source: src/main/java/agents/anac/y2014/Gangster/ExtendedBidDetails.java@ 340

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

Initial import : Genius 9.0.0

File size: 4.6 KB
Line 
1package agents.anac.y2014.Gangster;
2
3import java.util.Comparator;
4
5import genius.core.Bid;
6import genius.core.bidding.BidDetails;
7
8/**
9 * appart from the bid also stores our utility, the closest bid from the opponent and the distance to this closest bid.
10 *
11 *
12 * @author ddejonge
13 *
14 */
15class ExtendedBidDetails{
16
17 static int numCreated = 0;
18
19 int bidID; //this is needed as a tie-breaker for the camparators, because we can't put two objects in a TreeSet which compare equally.
20 //IDEA: instead of using a counter to identify this object, we could use the underlying Bid to identify it. In that way we prevent storing identical bids multiple times.
21
22 BidDetails bidDetails;
23
24 Bid closestOpponentBid = null;
25 int distanceToOpponent = Integer.MAX_VALUE; //Distance between my bid and the closest opponent bid.
26
27 Bid ourClosestBid = null;
28 int diversity = Integer.MAX_VALUE;
29
30
31 public ExtendedBidDetails(BidDetails bidDetails) {
32 this.bidDetails = bidDetails;
33 this.bidID = numCreated++;
34 }
35
36
37 /**
38 * checks if the given bid is the closest one and if yes, sets it as the closest bid, and sets the distance.
39 *
40 * @param opponentBid
41 * @throws Exception
42 */
43 void setClosestOpponentBidMaybe(Bid opponentBid) throws Exception{
44
45 int dist = Utils.calculateManhattanDistance(bidDetails.getBid(), opponentBid);
46 if(dist < this.distanceToOpponent){
47 this.distanceToOpponent = dist;
48 this.closestOpponentBid = opponentBid;
49 }
50
51 }
52
53
54 /**
55 * Sets the given bid as the closest one, and sets the distance.
56 * WARNING: doesn't check if it really is the closest bid!
57 *
58 * @param opponentBid
59 * @throws Exception
60 */
61 void setClosestOpponentBid(Bid opponentBid, int distance) throws Exception{
62 this.distanceToOpponent = distance;
63 closestOpponentBid = opponentBid;
64 }
65
66
67
68 void setOurClosestBidMaybe(Bid ourBid) throws Exception{
69
70 int dist = Utils.calculateManhattanDistance(this.bidDetails.getBid(), ourBid);
71 if(dist < this.diversity){
72 this.diversity = dist;
73 this.ourClosestBid = ourBid;
74 }
75
76 }
77
78
79 void setOurClosestBid(Bid ourBid, int diversity) throws Exception{
80 this.diversity = diversity;
81 this.ourClosestBid = ourBid;
82 }
83
84 double getMyUndiscountedUtil(){
85 return this.bidDetails.getMyUndiscountedUtil();
86 }
87
88
89 static ExtendedBidDetails dominator(ExtendedBidDetails b1, ExtendedBidDetails b2){
90
91 if(b1.bidDetails.getMyUndiscountedUtil() > b2.bidDetails.getMyUndiscountedUtil() && b1.distanceToOpponent < b2.distanceToOpponent){
92 return b1;
93 }
94
95 if(b2.bidDetails.getMyUndiscountedUtil() > b1.bidDetails.getMyUndiscountedUtil() && b2.distanceToOpponent < b1.distanceToOpponent){
96 return b2;
97 }
98
99 return null;
100 }
101
102
103 public static Comparator<ExtendedBidDetails> UtilityComparator = new Comparator<ExtendedBidDetails>() {
104
105 public int compare(ExtendedBidDetails bid1, ExtendedBidDetails bid2) {
106
107 int diff = Double.compare(bid1.getMyUndiscountedUtil(), bid2.getMyUndiscountedUtil());
108 if(diff == 0){
109 //this is needed as a tie-breaker for the camparators, because we can't put two objects in a TreeSet which compare equally.
110 return bid1.bidDetails.getBid().toString().compareTo(bid2.bidDetails.getBid().toString());
111 }
112
113 return diff;
114 }
115
116 };
117
118 public static Comparator<ExtendedBidDetails> DistanceComparator = new Comparator<ExtendedBidDetails>() {
119 public int compare(ExtendedBidDetails bid1, ExtendedBidDetails bid2) {
120
121 int diff = bid1.distanceToOpponent - bid2.distanceToOpponent;
122 if(diff == 0){
123 //this is needed as a tie-breaker for the camparators, because we can't put two objects in a TreeSet which compare equally.
124 return bid1.bidDetails.getBid().toString().compareTo(bid2.bidDetails.getBid().toString());
125 }
126 return diff;
127 }
128 };
129
130 public static Comparator<ExtendedBidDetails> DiversityComparator = new Comparator<ExtendedBidDetails>() {
131 public int compare(ExtendedBidDetails bid1, ExtendedBidDetails bid2) {
132
133 int diff = bid1.diversity - bid2.diversity;
134 if(diff == 0){
135 //this is needed as a tie-breaker for the camparators, because we can't put two objects in a TreeSet which compare equally.
136 return bid1.bidDetails.getBid().toString().compareTo(bid2.bidDetails.getBid().toString());
137 }
138 return diff;
139 }
140 };
141
142
143 public static Comparator<ExtendedBidDetails> IDComparator = new Comparator<ExtendedBidDetails>() {
144 public int compare(ExtendedBidDetails bid1, ExtendedBidDetails bid2) {
145 return bid1.bidDetails.getBid().toString().compareTo(bid2.bidDetails.getBid().toString());
146 }
147 };
148
149
150 public boolean equals(Object o){
151
152 if(o instanceof ExtendedBidDetails){
153 return this.bidDetails.getBid().toString().equals(((ExtendedBidDetails)o).bidDetails.getBid().toString());
154 }
155
156 return false;
157 }
158}
Note: See TracBrowser for help on using the repository browser.