From 9ae4c039b998943dbe771772ee06dfbcad3d6b8a Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 27 Jan 2018 00:14:42 +0000 Subject: Alter printing to work when pile refs are changed --- src/main/game/game_state.cpp | 11 +++++++---- src/main/game/game_state.h | 6 ++++++ src/main/input-output/output/state_printer.cpp | 6 +++--- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') 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(piles.size() - 1)); + original_cells.push_back(static_cast(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(piles.size() - 1)); + original_reserve.push_back(static_cast(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(piles.size() - 1)); + original_tableau_piles.push_back(static_cast(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 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 original_tableau_piles; + std::vector original_cells; + std::vector original_reserve; + // The core piles std::vector 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) { -- cgit v1.2.1