aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorthecharlesblake2018-01-27 00:14:42 +0000
committerthecharlesblake2018-01-27 00:14:42 +0000
commit9ae4c039b998943dbe771772ee06dfbcad3d6b8a (patch)
treeaf4a7f84a7d8945cb9e679f9111a3c11de73190d /src
parentFix simple hash bug (diff)
downloadmetasol-9ae4c039b998943dbe771772ee06dfbcad3d6b8a.tar.gz
metasol-9ae4c039b998943dbe771772ee06dfbcad3d6b8a.zip

Alter printing to work when pile refs are changed

Diffstat (limited to 'src')
-rw-r--r--src/main/game/game_state.cpp11
-rw-r--r--src/main/game/game_state.h6
-rw-r--r--src/main/input-output/output/state_printer.cpp6
3 files changed, 16 insertions, 7 deletions
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp
index 8f45a38..bcab777 100644
--- a/src/main/game/game_state.cpp
+++ b/src/main/game/game_state.cpp
@@ -48,6 +48,7 @@ game_state::game_state(const sol_rules& s_rules) : rules(s_rules) {
for (uint8_t i = 0; i < rules.cells; i++) {
piles.emplace_back();
cells.push_back(static_cast<pile_ref>(piles.size() - 1));
+ original_cells.push_back(static_cast<pile_ref>(piles.size() - 1));
}
}
@@ -70,6 +71,7 @@ game_state::game_state(const sol_rules& s_rules) : rules(s_rules) {
for (uint8_t i = 0; i < pile_count; i++) {
piles.emplace_back();
reserve.push_back(static_cast<pile_ref>(piles.size() - 1));
+ original_reserve.push_back(static_cast<pile_ref>(piles.size() - 1));
}
}
@@ -77,6 +79,7 @@ game_state::game_state(const sol_rules& s_rules) : rules(s_rules) {
for (uint8_t i = 0; i < rules.tableau_pile_count; i++) {
piles.emplace_back();
tableau_piles.push_back(static_cast<pile_ref>(piles.size() - 1));
+ original_tableau_piles.push_back(static_cast<pile_ref>(piles.size() - 1));
}
}
@@ -210,8 +213,8 @@ void game_state::make_move(const move m) {
// Handles special stock-to-tableau-piles move
if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) {
- for (pile_ref tab_pr = tableau_piles.front();
- tab_pr < tableau_piles.front() + m.count;
+ for (pile_ref tab_pr = original_tableau_piles.front();
+ tab_pr < original_tableau_piles.front() + m.count;
tab_pr++) {
piles[tab_pr].place(piles[stock].take());
}
@@ -239,8 +242,8 @@ void game_state::undo_move(const move m) {
// Handles special stock-to-tableau-piles move
if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) {
- for (pile_ref tab_pr = tableau_piles.front() + m.count;
- tab_pr-- > tableau_piles.front();
+ for (pile_ref tab_pr = original_tableau_piles.front() + m.count;
+ tab_pr-- > original_tableau_piles.front();
) {
piles[stock].place(piles[tab_pr].take());
}
diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h
index 8434bf7..e8e2f96 100644
--- a/src/main/game/game_state.h
+++ b/src/main/game/game_state.h
@@ -77,6 +77,12 @@ private:
std::vector<pile_ref> foundations;
pile_ref hole;
+ // Stores the original pile refs of the commutative piles so that they can
+ // be printed in the order the user expects
+ std::vector<pile_ref> original_tableau_piles;
+ std::vector<pile_ref> original_cells;
+ std::vector<pile_ref> original_reserve;
+
// The core piles
std::vector<pile> piles;
};
diff --git a/src/main/input-output/output/state_printer.cpp b/src/main/input-output/output/state_printer.cpp
index 1d1c182..0fdacae 100644
--- a/src/main/input-output/output/state_printer.cpp
+++ b/src/main/input-output/output/state_printer.cpp
@@ -15,11 +15,11 @@ ostream& state_printer::print(ostream& stream, const game_state& gs) {
}
if (gs.rules.cells) {
state_printer::print_header(stream, "Cells");
- state_printer::print_piles(stream, gs.cells, gs);
+ state_printer::print_piles(stream, gs.original_cells, gs);
}
if (gs.rules.tableau_pile_count > 0) {
state_printer::print_header(stream, "Tableau Piles");
- state_printer::print_piles(stream, gs.tableau_piles, gs);
+ state_printer::print_piles(stream, gs.original_tableau_piles, gs);
}
if (gs.rules.reserve_size > 0) {
if (gs.rules.reserve_stacked) {
@@ -27,7 +27,7 @@ ostream& state_printer::print(ostream& stream, const game_state& gs) {
} else {
state_printer::print_header(stream, "Reserve");
}
- state_printer::print_piles(stream, gs.reserve, gs);
+ state_printer::print_piles(stream, gs.original_reserve, gs);
}
if (gs.rules.stock_size > 0) {
if (gs.rules.stock_deal_t == sdt::WASTE) {