/
testagent.cpp
82 lines (76 loc) · 1.9 KB
/
testagent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "testagent.h"
#include <string>
#include <sstream>
TestAgent::TestAgent()
{
static unsigned int nr = 0;
std::ostringstream buffer;
buffer << "TestAgent" << nr++;
name = buffer.str();
}
bool TestAgent::start()
{
return true;
}
TradeGame::AssetType cycleVar()
{
static bool direction = false;
static int count = 0;
if(count++ % 40 == 0)
{
direction = !direction;
}
static TradeGame::AssetType varType = TradeGame::SILVER;
if(direction)
{
if(varType == TradeGame::SILVER)
varType = TradeGame::GOLD;
else if(varType == TradeGame::GOLD)
varType = TradeGame::PLATINUM;
else if(varType == TradeGame::PLATINUM)
varType = TradeGame::SILVER;
return varType;
}
else
{
if(varType == TradeGame::SILVER)
varType = TradeGame::PLATINUM;
else if(varType == TradeGame::GOLD)
varType = TradeGame::SILVER;
else if(varType == TradeGame::PLATINUM)
varType = TradeGame::GOLD;
return varType;
}
}
TradeGame::Bid TestAgent::inviteBid()
{
static int volume = 1;
TradeGame::Bid bid;
bid.buyingType = cycleVar();
bid.buyingVolume = volume++ % 6;
bid.sellingType = cycleVar();
bid.sellingVolume = volume++ % 6;
return bid;
}
int TestAgent::selectBestMatch(const std::vector<TradeGame::Bid>& bids)
{
unsigned int maxRatio = 0;
int selected = 0;
for(unsigned int i=0; i<bids.size(); i++)
{
const TradeGame::Bid& bid = bids.at(i);
float ratio = float(bid.sellingVolume) / bid.buyingVolume;
if(ratio > maxRatio)
{
maxRatio = ratio;
selected = int(i);
}
}
return selected;
}
void TestAgent::addAssets(int dSilver, int dGold, int dPlatinum)
{
assets.silver += dSilver;
assets.gold += dGold;
assets.platinum += dPlatinum;
}