@@ -24,16 +24,16 @@ class BasicAgent
2424 public var inventorySpace (get , null ): Float ;
2525 public var inventoryFull (get , null ): Bool ;
2626 public var destroyed (default , null ): Bool ;
27-
28- public function new (id : Int , data : AgentData )
27+
28+ public function new (id : Int , data : AgentData )
2929 {
3030 this .id = id ;
3131 className = data .className ;
3232 money = data .money ;
3333 _inventory = new Inventory ();
3434 _inventory .fromData (data .inventory );
3535 _logic = data .logic ;
36-
36+
3737 if (data .lookBack == null )
3838 {
3939 _lookback = 15 ;
@@ -42,11 +42,11 @@ class BasicAgent
4242 {
4343 _lookback = data .lookBack ;
4444 }
45-
45+
4646 _priceBeliefs = new Map <String , Point >();
4747 _observedTradingRange = new Map <String , Array <Float >>();
4848 }
49-
49+
5050 public function destroy (): Void
5151 {
5252 destroyed = true ;
@@ -67,91 +67,91 @@ class BasicAgent
6767 _observedTradingRange = null ;
6868 _logic = null ;
6969 }
70-
70+
7171 public function init (market : Market ): Void
7272 {
7373 var listGoods = market .getGoods_unsafe ();
7474 for (str in listGoods )
7575 {
7676 var trades : Array <Float > = new Array <Float >();
77-
77+
7878 var price : Float = market .getAverageHistoricalPrice (str , _lookback );
7979 trades .push (price * 0.5 );
8080 trades .push (price * 1.5 ); // push two fake trades to generate a range
81-
81+
8282 // set initial price belief & observed trading range
8383 _observedTradingRange .set (str , trades );
8484 _priceBeliefs .set (str , new Point (price * 0.5 , price * 1.5 ));
8585 }
8686 }
87-
87+
8888 public function simulate (market : Market ): Void
8989 {
9090 _logic .perform (this , market );
9191 }
92-
92+
9393 public function generateOffers (bazaar : Market , good : String ): Void
9494 {
9595 // no implemenation -- provide your own in a subclass
9696 }
97-
97+
9898 public function updatePriceModel (bazaar : Market , act : String , good : String , success : Bool , unitPrice : Float = 0 ): Void
9999 {
100100 // no implementation -- provide your own in a subclass
101101 }
102-
102+
103103 public function createBid (bazaar : Market , good : String , limit : Float ): Offer
104104 {
105105 // no implementation -- provide your own in a subclass
106106 return null ;
107107 }
108-
108+
109109 public function createAsk (bazaar : Market , commodity_ : String , limit_ : Float ): Offer
110110 {
111111 // no implementation -- provide your own in a subclass
112112 return null ;
113113 }
114-
114+
115115 public function queryInventory (good : String ): Float
116116 {
117117 return _inventory .query (good );
118118 }
119-
119+
120120 public function changeInventory (good : String , delta : Float ): Void
121121 {
122122 _inventory .change (good , delta );
123123 }
124-
124+
125125 /** ******PRIVATE************/
126-
126+
127127 private var _logic : Logic ;
128128 private var _inventory : Inventory ;
129129 private var _priceBeliefs : Map <String , Point >;
130130 private var _observedTradingRange : Map <String , Array <Float >>;
131131 private var _profit : Float = 0 ; // profit from last round
132132 private var _lookback : Int = 15 ;
133-
133+
134134 private function get_inventorySpace (): Float
135135 {
136136 return _inventory .getEmptySpace ();
137137 }
138-
138+
139139 public function get_inventoryFull (): Bool
140140 {
141141 return _inventory .getEmptySpace () == 0 ;
142142 }
143-
143+
144144 private function get_profit (): Float
145145 {
146146 return money - moneyLastRound ;
147147 }
148-
148+
149149 private function determinePriceOf (commodity_ : String ): Float
150150 {
151151 var belief : Point = _priceBeliefs .get (commodity_ );
152152 return Quick .randomRange (belief .x , belief .y );
153153 }
154-
154+
155155 private function determineSaleQuantity (bazaar : Market , commodity_ : String ): Float
156156 {
157157 var mean : Float = bazaar .getAverageHistoricalPrice (commodity_ ,_lookback );
@@ -160,7 +160,7 @@ class BasicAgent
160160 {
161161 var favorability : Float = Quick .positionInRange (mean , trading_range .x , trading_range .y );
162162 // position_in_range: high means price is at a high point
163-
163+
164164 var amount_to_sell : Float = Math .round (favorability * _inventory .surplus (commodity_ ));
165165 if (amount_to_sell < 1 )
166166 {
@@ -170,17 +170,17 @@ class BasicAgent
170170 }
171171 return 0 ;
172172 }
173-
173+
174174 private function determinePurchaseQuantity (bazaar : Market , commodity_ : String ): Float
175175 {
176176 var mean : Float = bazaar .getAverageHistoricalPrice (commodity_ ,_lookback );
177177 var trading_range : Point = observeTradingRange (commodity_ );
178178 if (trading_range != null )
179179 {
180180 var favorability : Float = Quick .positionInRange (mean , trading_range .x , trading_range .y );
181- favorability = 1 - favorability ;
181+ favorability = 1 - favorability ;
182182 // do 1 - favorability to see how close we are to the low end
183-
183+
184184 var amount_to_buy : Float = Math .round (favorability * _inventory .shortage (commodity_ ));
185185 if (amount_to_buy < 1 )
186186 {
@@ -190,12 +190,12 @@ class BasicAgent
190190 }
191191 return 0 ;
192192 }
193-
193+
194194 private function getPriceBelief (good : String ): Point
195195 {
196196 return _priceBeliefs .get (good );
197197 }
198-
198+
199199 private function observeTradingRange (good : String ): Point
200200 {
201201 var a : Array <Float > = _observedTradingRange .get (good );
@@ -211,4 +211,4 @@ typedef AgentData = {
211211 logicName : String ,
212212 logic : Logic ,
213213 ? lookBack : Int
214- }
214+ }
0 commit comments