blob: c6278e2efae7c89172ff0e1a5120a76800a0f0d1 (
plain) (
blame)
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
|
//
// Created by thecharlesblake on 10/23/17.
//
#include <vector>
#include <ostream>
#include <rapidjson/document.h>
#include "game_state.h"
using namespace std;
using namespace rapidjson;
game_state::game_state(const Document& doc) {
const Value& json_tab_piles = doc["tableau piles"];
assert(json_tab_piles.IsArray());
for (auto& json_tab : json_tab_piles.GetArray()) {
vector<card> tableau_pile;
for (auto& json_card : json_tab.GetArray()) {
tableau_pile.push_back(card(json_card.GetString()));
}
tableau_piles.push_back(tableau_pile);
}
}
ostream& game_state::print(ostream& stream) const {
bool empty_row = false;
int row_idx = 0;
while (!empty_row) {
empty_row = true;
for (auto tableau_pile : tableau_piles) {
if (tableau_pile.size() > row_idx) {
empty_row = false;
stream << tableau_pile[row_idx];
}
stream << "\t";
}
stream << "\n";
row_idx++;
}
return stream;
}
ostream& operator <<(ostream& stream, const game_state& gs) {
return gs.print(stream);
}
|