Skip to content

Commit efcbf04

Browse files
committed
Merge pull request #14 from paultcochrane/pr/purge-trailing-whitespace
Purge trailing whitespace in source code
2 parents b80372d + 71a5f2e commit efcbf04

30 files changed

+442
-442
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
bazaarBot
22
=========
33

4-
A simple agent-based free market simulator engine.
4+
A simple agent-based free market simulator engine.
55

6-
This engine consists of various "Agents" trading commodities, with emergent free-floating prices that rise and fall according to the laws of supply and demand.
6+
This engine consists of various "Agents" trading commodities, with emergent free-floating prices that rise and fall according to the laws of supply and demand.
77

88
The eventual goal is to create an open-source "Economics engine" for games and simulations, much like contemporary open-source "Physics engines."
99

1010
Based on "[Emergent Economies for Role Playing Games](http://larc.unt.edu/techreports/LARC-2010-03.pdf)" by Jonathon Doran and Ian Parberry.
1111

1212
Source: [Procedural Content Generation](http://larc.unt.edu/ian/research/content/)
13-
13+
1414
Building the example project
1515
---------------------------
1616

bazaarbot/Agent.hx

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ import flash.geom.Point;
88

99
/**
1010
* An agent that performs the basic logic from the Doran & Parberry article
11-
* @author
11+
* @author
1212
*/
1313
class Agent extends BasicAgent
1414
{
1515
public static inline var SIGNIFICANT:Float = 0.25; //25% more or less is "significant"
1616
public static inline var SIG_IMBALANCE:Float = 0.33;
1717
public static inline var LOW_INVENTORY:Float = 0.1; //10% of ideal inventory = "LOW"
1818
public static inline var HIGH_INVENTORY:Float = 2.0; //200% of ideal inventory = "HIGH"
19-
19+
2020
public static inline var MIN_PRICE:Float = 0.01; //lowest possible price
21-
22-
public function new(id:Int, data:AgentData)
21+
22+
public function new(id:Int, data:AgentData)
2323
{
2424
super(id, data);
2525
}
26-
27-
override public function createBid(bazaar:Market, good:String, limit:Float):Offer
26+
27+
override public function createBid(bazaar:Market, good:String, limit:Float):Offer
2828
{
2929
var bidPrice:Float = determinePriceOf(good);
3030
var ideal:Float = determinePurchaseQuantity(bazaar, good);
31-
31+
3232
//can't buy more than limit
3333
var quantityToBuy:Float = ideal > limit ? limit : ideal;
3434
if (quantityToBuy > 0)
@@ -37,12 +37,12 @@ class Agent extends BasicAgent
3737
}
3838
return null;
3939
}
40-
41-
override public function createAsk(bazaar:Market, commodity_:String, limit_:Float):Offer
40+
41+
override public function createAsk(bazaar:Market, commodity_:String, limit_:Float):Offer
4242
{
4343
var ask_price:Float = determinePriceOf(commodity_);
4444
var ideal:Float = determineSaleQuantity(bazaar, commodity_);
45-
45+
4646
//can't sell less than limit
4747
var quantity_to_sell:Float = ideal < limit_ ? limit_ : ideal;
4848
if (quantity_to_sell > 0)
@@ -51,8 +51,8 @@ class Agent extends BasicAgent
5151
}
5252
return null;
5353
}
54-
55-
override public function generateOffers(bazaar:Market, commodity:String):Void
54+
55+
override public function generateOffers(bazaar:Market, commodity:String):Void
5656
{
5757
var offer:Offer;
5858
var surplus:Float = _inventory.surplus(commodity);
@@ -69,7 +69,7 @@ class Agent extends BasicAgent
6969
var shortage:Float = _inventory.shortage(commodity);
7070
var space:Float = _inventory.getEmptySpace();
7171
var unit_size:Float = _inventory.getCapacityFor(commodity);
72-
72+
7373
if (shortage > 0 && space >= unit_size)
7474
{
7575
var limit:Float = 0;
@@ -81,7 +81,7 @@ class Agent extends BasicAgent
8181
{
8282
limit = Math.floor(space / shortage);
8383
}
84-
84+
8585
if (limit > 0)
8686
{
8787
offer = createBid(bazaar, commodity, limit);
@@ -93,26 +93,26 @@ class Agent extends BasicAgent
9393
}
9494
}
9595
}
96-
97-
override public function updatePriceModel(bazaar:Market, act:String, good:String, success:Bool, unitPrice:Float = 0):Void
96+
97+
override public function updatePriceModel(bazaar:Market, act:String, good:String, success:Bool, unitPrice:Float = 0):Void
9898
{
9999
var observed_trades:Array<Float>;
100-
100+
101101
if (success)
102102
{
103103
//Add this to my list of observed trades
104104
observed_trades = _observedTradingRange.get(good);
105105
observed_trades.push(unitPrice);
106106
}
107-
107+
108108
var public_mean_price:Float = bazaar.getAverageHistoricalPrice(good, 1);
109-
109+
110110
var belief:Point = getPriceBelief(good);
111111
var mean:Float = (belief.x + belief.y) / 2;
112112
var wobble:Float = 0.05;
113-
113+
114114
var delta_to_mean:Float = mean - public_mean_price;
115-
115+
116116
if (success)
117117
{
118118
if (act == "buy" && delta_to_mean > SIGNIFICANT) //overpaid
@@ -125,19 +125,19 @@ class Agent extends BasicAgent
125125
belief.x -= delta_to_mean / 2; //SHIFT towards mean
126126
belief.y -= delta_to_mean / 2;
127127
}
128-
128+
129129
belief.x += wobble * mean; //increase the belief's certainty
130130
belief.y -= wobble * mean;
131131
}
132132
else
133133
{
134134
belief.x -= delta_to_mean / 2; //SHIFT towards the mean
135135
belief.y -= delta_to_mean / 2;
136-
136+
137137
var special_case:Bool = false;
138138
var stocks:Float = queryInventory(good);
139139
var ideal:Float = _inventory.ideal(good);
140-
140+
141141
if (act == "buy" && stocks < LOW_INVENTORY * ideal)
142142
{
143143
//very low on inventory AND can't buy
@@ -150,34 +150,34 @@ class Agent extends BasicAgent
150150
wobble *= 2; //ask more liberally
151151
special_case = true;
152152
}
153-
153+
154154
if (!special_case)
155155
{
156156
//Don't know what else to do? Check supply vs. demand
157157
var asks:Float = bazaar.history.asks.average(good,1);
158158
var bids:Float = bazaar.history.bids.average(good,1);
159-
159+
160160
//supply_vs_demand: 0=balance, 1=all supply, -1=all demand
161161
var supply_vs_demand:Float = (asks - bids) / (asks + bids);
162-
162+
163163
//too much supply, or too much demand
164164
if (supply_vs_demand > SIG_IMBALANCE || supply_vs_demand < -SIG_IMBALANCE)
165165
{
166166
//too much supply: lower price
167167
//too much demand: raise price
168-
168+
169169
var new_mean = public_mean_price * (1 - supply_vs_demand);
170170
delta_to_mean = mean - new_mean;
171-
171+
172172
belief.x -= delta_to_mean / 2; //SHIFT towards anticipated new mean
173173
belief.y -= delta_to_mean / 2;
174174
}
175175
}
176-
176+
177177
belief.x -= wobble * mean; //decrease the belief's certainty
178178
belief.y += wobble * mean;
179179
}
180-
180+
181181
if (belief.x < MIN_PRICE)
182182
{
183183
belief.x = MIN_PRICE;
@@ -187,4 +187,4 @@ class Agent extends BasicAgent
187187
belief.y = MIN_PRICE;
188188
}
189189
}
190-
}
190+
}

bazaarbot/Economy.hx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import bazaarbot.agent.BasicAgent;
88

99
class Economy
1010
{
11-
public function new()
11+
public function new()
1212
{
1313
_markets = [];
1414
}
15-
15+
1616
public function addMarket(m:Market)
1717
{
1818
if (_markets.indexOf(m) == -1)
@@ -21,7 +21,7 @@ class Economy
2121
m.signalBankrupt.add(onBankruptcy);
2222
}
2323
}
24-
24+
2525
public function getMarket(name:String):Market
2626
{
2727
for (m in _markets)
@@ -30,21 +30,21 @@ class Economy
3030
}
3131
return null;
3232
}
33-
33+
3434
public function simulate(rounds:Int)
3535
{
3636
for (m in _markets)
3737
{
3838
m.simulate(rounds);
3939
}
4040
}
41-
41+
4242
/***PRIVATE***/
43-
43+
4444
private function onBankruptcy(m:Market, a:BasicAgent):Void
4545
{
4646
//no implemenation -- provide your own in a subclass
4747
}
48-
48+
4949
private var _markets:Array<Market>;
50-
}
50+
}

bazaarbot/Good.hx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package bazaarbot;
22

33
/**
44
* ...
5-
* @author
5+
* @author
66
*/
7-
7+
88
class Good
99
{
1010
public var id:String = ""; //string id of good
1111
public var size:Float = 1.0; //inventory size taken up
12-
13-
public function new(id_:String,size_:Float)
12+
13+
public function new(id_:String,size_:Float)
1414
{
1515
id = id_;
1616
size = size_;
@@ -21,4 +21,4 @@ class Good
2121
return new Good(id, size);
2222
}
2323
}
24-
24+

0 commit comments

Comments
 (0)