-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgent.cs
123 lines (109 loc) · 3.64 KB
/
Agent.cs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
namespace econrpg
{
public class Agent
{
private static int numberOfAgents = 0;
private static List<Agent> agents = new List<Agent>();
private Role role;
private Inventory inventory;
private int id;
public static List<Agent> AgentsList
{
get { return agents; }
}
public Agent()
{
this.id = numberOfAgents;
this.role = Role.GetRandomRole();
inventory = new Inventory(this.id, role.getProductionRules());
numberOfAgents++;
agents.Add(this);
}
public override String ToString()
{
return this.id + "," + this.role.Name;
}
// public static void printAgentsInventory()
// {
// foreach (Agent agent in agents)
// {
// agent.printInventory();
// }
// }
public static Agent getAgentById(int agentId)
{
return agents.Find(x => x.id == agentId);
}
public static void writeAgentsStatsByRound(int round, String roundTime)
{
foreach (Agent agent in agents)
{
foreach (InventoryItem item in agent.getInventoryItems())
{
StorageStatic.writeLine(new AgentStats
{
Round = round,
Role = agent.getCurrentRoleName(),
Money = agent.getMoney(),
AgentId = agent.Id,
RoundTime = roundTime,
CommodityId = item.getCommodityId(),
InventoryLevel = item.getInventoryLevel(),
lowerPriceBelief = item.getPriceBeliefs()[0],
upperPricerBelief = item.getPriceBeliefs()[1]
});
}
}
}
public int Id
{
get { return this.id; }
}
private List<InventoryItem> getInventoryItems()
{
return this.inventory.InventoryItems;
}
public double getMoney()
{
return this.inventory.Money;
}
public String getCurrentRoleName()
{
return this.role.Name;
}
public Role getCurrentRole()
{
return this.role;
}
// public void printInventory()
// {
// Console.WriteLine("\nThis is the Agente number " + this.id);
// Console.WriteLine("The role of this agent is " + this.role);
// this.inventory.printInventory(this.role.GetRoleCommodities());
// }
public ProductionRule performProduction()
{
return this.role.production(this.inventory);
}
public List<Offer> runProductionAndOffers()
{
ProductionRule productionRuleDone = this.performProduction();
List<Offer> items = this.inventory.generateOffers(productionRuleDone);
if (items.Count == 0) Console.WriteLine("The agent " + this.id + " did not trade.");
return items;
}
public void receiveOfferResult(Offer offer)
{
if (offer.type == "ask")
{
this.inventory.decreaseInventoryItemLevel(offer.commodityId, offer.filledAmount);
this.inventory.increaseMoney(offer.wallet);
}
else
{
this.inventory.increaseInventoryItemLevel(offer.commodityId, offer.filledAmount);
this.inventory.decreaseMoney(offer.wallet);
}
}
}
}