source: src/main/java/agents/anac/y2010/AgentSmith/BidHistory.java@ 345

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

Initial import : Genius 9.0.0

File size: 2.5 KB
Line 
1package agents.anac.y2010.AgentSmith;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import genius.core.Bid;
7
8/*
9 * The storage point for the bidhistory of the agent and the opponent
10 */
11
12public class BidHistory {
13
14 private List<Bid> fMyBids;
15 private List<Bid> fOpponentBids;
16 private List<IBidHistoryListener> fListeners;
17
18 public BidHistory() {
19 fMyBids = new ArrayList<Bid>();
20 fOpponentBids = new ArrayList<Bid>();
21 fListeners = new ArrayList<IBidHistoryListener>();
22 }
23
24 /*
25 * Add our own bid to the list
26 */
27 public void addMyBid(Bid pBid) {
28 if (pBid == null)
29 throw new IllegalArgumentException("vBid can't be null.");
30 fMyBids.add(pBid);
31 for (IBidHistoryListener listener : fListeners) {
32 listener.myBidAdded(this, pBid);
33 }
34 }
35
36 /*
37 * returns the size (number) of offers already made
38 */
39 public int getMyBidCount() {
40 return fMyBids.size();
41 }
42
43 /*
44 * returns a bid from the list
45 */
46 public Bid getMyBid(int pIndex) {
47 return fMyBids.get(pIndex);
48 }
49
50 /*
51 * returns the last offer made
52 */
53 public Bid getMyLastBid() {
54 Bid result = null;
55 if(getMyBidCount() > 0){
56 result = fMyBids.get(getMyBidCount()-1);
57 }
58 return result;
59 }
60
61 /*
62 * returns true if a bid has already been made before
63 */
64 public boolean isInsideMyBids(Bid a){
65 boolean result = false;
66 for(int i = 0; i < getMyBidCount(); i++){
67 if(a.equals(getMyBid(i))){
68 result = true;
69 }
70 }
71 return result;
72 }
73
74 /*
75 * add the bid the oppponent to his list
76 */
77 public void addOpponentBid(Bid pBid) {
78 if (pBid == null)
79 throw new IllegalArgumentException("vBid can't be null.");
80 fOpponentBids.add(pBid);
81 for (IBidHistoryListener listener : fListeners) {
82 listener.opponentBidAdded(this, pBid);
83 }
84 }
85
86 /*
87 * returns the number of bids the opponent has made
88 */
89 public int getOpponentBidCount() {
90 return fOpponentBids.size();
91 }
92
93 /*
94 * returns the bid at a given index
95 */
96 public Bid getOpponentBid(int pIndex) {
97 return fOpponentBids.get(pIndex);
98 }
99
100 /*
101 * returns the opponents' last bid
102 */
103 public Bid getOpponentLastBid() {
104 Bid result = null;
105 if(getOpponentBidCount() > 0){
106 result = fOpponentBids.get(getOpponentBidCount()-1);
107 }
108 return result;
109 }
110
111 /*
112 * add a given listener to the list
113 */
114 public void addListener(IBidHistoryListener pListener) {
115 fListeners.add(pListener);
116 }
117
118 /*
119 * remove a given listener from the list
120 */
121 public void removeListener(IBidHistoryListener pListener) {
122 fListeners.remove(pListener);
123 }
124
125}
Note: See TracBrowser for help on using the repository browser.