-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbidlist.cpp
More file actions
97 lines (87 loc) · 2.26 KB
/
bidlist.cpp
File metadata and controls
97 lines (87 loc) · 2.26 KB
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
#include "bidlist.h"
#include <algorithm>
#include <assert.h>
BidList::BidList()
{
}
void BidList::create(std::map<unsigned int,TradeGame::Agent*> agents)
{
list.clear();
for(std::map<unsigned int,TradeGame::Agent*>::iterator it=agents.begin(); it!=agents.end(); it++)
{
bool trading = it->second->start();
if(trading)
list.push_back(it->first);
}
std::random_shuffle(list.begin(), list.end());
}
BidList::Iterator BidList::iterate()
{
BidList::Iterator iter(*this);
return iter;
}
//***************Iterator***************//
BidList::Iterator::Iterator(BidList& parent) :
parent(parent),
current(0)
{
}
bool BidList::Iterator::hasNext() const
{
return current < parent.list.size();// && !ended;
}
unsigned int BidList::Iterator::next()
{
return parent.list.at(current++);
}
void BidList::Iterator::remove(unsigned int seller, unsigned int buyer)
{
bool runCorrections = true;
unsigned int newAssigned;
if(parent.list.size() > current+2)
{
unsigned int assignedCurrent = parent.list.at(current);
unsigned int assignedNext = parent.list.at(current+1);
unsigned int assignedNextNext = parent.list.at(current+2);
if(assignedCurrent != seller && assignedCurrent != buyer)
{
newAssigned = assignedCurrent;
}
else if(assignedNext != seller && assignedNext != buyer)
{
newAssigned = assignedNext;
}
else if(assignedNextNext != seller && assignedNextNext != buyer)
{
newAssigned = assignedNextNext;
}
else
assert(false);
}
else
{
runCorrections = false;
}
for(std::vector<unsigned int>::iterator it=parent.list.begin(); it!=parent.list.end(); it++)
{
if(*it == seller || *it == buyer)
{
it = parent.list.erase(it);
it--;
}
}
if(runCorrections)
{
for(std::vector<unsigned int>::iterator it=parent.list.begin(); it!=parent.list.end(); it++)
{
}
for(unsigned int i=0; i<parent.list.size(); i++)
{
if(parent.list.at(i) == newAssigned)
{
current = i;
return;
}
}
}
}