source: src/main/java/parties/in4010/q12015/group15/OMStrategy.java@ 126

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

Initial import : Genius 9.0.0

File size: 2.5 KB
Line 
1package parties.in4010.q12015.group15;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import genius.core.Bid;
7import genius.core.bidding.BidDetails;
8import genius.core.utility.AdditiveUtilitySpace;
9
10/**
11 * This strategy uses Opponent Modeling to find a best bid out of a range of
12 * bids. It tries to find the bid closest to the utility for the opponents from
13 * their last offers but also with good utility for us. Our utility is valued
14 * more important than the utility of our opponents.
15 *
16 */
17public class OMStrategy {
18
19 private OpponentModel om;
20 private AdditiveUtilitySpace utilitySpace;
21 private List<Bid> bidsOffered = new ArrayList<>();
22
23 public OMStrategy(OpponentModel om, AdditiveUtilitySpace utilitySpace) {
24 this.om = om;
25 this.utilitySpace = utilitySpace;
26 }
27
28 /**
29 * @param a
30 * range of bids to choose from
31 * @return the best bid out of the list of bids
32 */
33 public Bid getBestBid(List<BidDetails> bids) {
34 System.out.println("----- OMS -----");
35 double highestEvaluation = Integer.MIN_VALUE;
36 Bid bestBid = null;
37 for (BidDetails bid : bids) {
38 System.out.println("OMS bid: " + bid.getBid());
39 if (bidsOffered.contains(bid.getBid())) { // Don't offer same bid
40 // twice
41 System.out.println("Has offered bid before: " + bid.getBid());
42 continue;
43 }
44
45 double evaluation = 0;
46 try {
47 double totalWeights = 0;
48 for (String opponent : om.getOpponents()) {
49 double opponentUtilityForBid = om.getBidEvaluation(
50 opponent, bid.getBid());
51 double lastUtilityFromOpponentBid = om
52 .getLastBidEvaluation(opponent);
53 double utilDiff = Math.abs(opponentUtilityForBid
54 - lastUtilityFromOpponentBid);
55
56 double weight = 1 + om
57 .getAverageBidUtilityChangeForAgent(opponent); // Put
58 // higher
59 // weights
60 // to
61 // non-conceders
62 totalWeights += weight;
63 evaluation -= weight * utilDiff;
64 }
65 evaluation += totalWeights
66 * utilitySpace.getUtility(bid.getBid()); // Add our
67 // utility
68 if (evaluation > highestEvaluation) {
69 highestEvaluation = evaluation;
70 bestBid = bid.getBid();
71 }
72 } catch (Exception e) {
73 System.out
74 .println("OMS Could not calculate highest evaluation from OM");
75 e.printStackTrace();
76 }
77
78 }
79
80 System.out.println("Highest bid evaluation: " + highestEvaluation);
81 System.out.println("for bid: " + bestBid);
82 bidsOffered.add(bestBid);
83 return bestBid;
84 }
85}
Note: See TracBrowser for help on using the repository browser.