-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cc
More file actions
55 lines (43 loc) · 1.47 KB
/
Copy pathGame.cc
File metadata and controls
55 lines (43 loc) · 1.47 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
//////// STUDENTS DO NOT NEED TO READ BELOW THIS LINE ////////
#include "Game.hh"
void Game::run (vector<string> names, istream& is, ostream& os, int seed) {
cerr << "info: seed " << seed << endl;
cerr << "info: loading game" << endl;
Board b(is, seed);
cerr << "info: loaded game" << endl;
int np = b.num_players();
int nr = b.num_rounds();
_my_assert(np == (int)names.size(), "Wrong number of players.");
vector<Player*> players;
for (int pl = 0; pl < np; ++pl) {
string name = names[pl];
b.names[pl] = name;
cerr << "info: loading player " << name << endl;
players.push_back(Registry::new_player(name));
players[pl]->me_ = pl;
players[pl]->set_random_seed(seed + pl + 1);
*static_cast<Settings*>(players[pl]) = (Settings)b;
}
cerr << "info: players loaded" << endl;
os << "Game" << endl << endl;
os << "Seed " << seed << endl << endl;
b.print_settings(os);
b.print_names(os);
b.print_state(os);
for (int round = 0; round < nr; ++round) {
cerr << "info: start round " << round << endl;
vector<Action> actions(np);
for (int pl = 0; pl < np; ++pl) {
cerr << "info: start player " << pl << endl;
players[pl]->reset(b);
players[pl]->play();
actions[pl] = *players[pl];
cerr << "info: end player " << pl << endl;
}
b.next(actions, os);
b.print_state(os);
cerr << "info: end round " << round << endl;
}
b.print_results();
cerr << "info: game played" << endl;
}