From f91cd251fd40d927254246e9276924af3e046dd1 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 6 Nov 2017 15:35:10 +0000 Subject: Add cells to game state and next state generation --- src/main/game_state.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/main/game_state.cpp') diff --git a/src/main/game_state.cpp b/src/main/game_state.cpp index 29ccdc3..2dd1ca8 100644 --- a/src/main/game_state.cpp +++ b/src/main/game_state.cpp @@ -55,7 +55,7 @@ game_state::game_state(int seed, const sol_rules& s_rules) hole(false, ord::BOTH, pol::ANY_SUIT, true, rules.max_rank) { vector deck = shuffled_deck(seed, rules.max_rank); - // If there is a hole, move the ace to spades to it + // If there is a hole, move the ace of spades to it if (rules.hole) { deck.erase(find(begin(deck), end(deck), card("AS"))); hole.place("AS"); @@ -82,6 +82,14 @@ game_state::game_state(int seed, const sol_rules& s_rules) foundations.push_back(p); } } + + // If there are cell piles, create the relevant cell vectors + if (rules.cells > 0) { + for (int i = 0; i < rules.cells; i++) { + pile p(true, ord::SINGLE_CARD, pol::ANY_SUIT, false); + foundations.push_back(p); + } + } } // Generate a randomly ordered vector of cards @@ -129,6 +137,10 @@ vector game_state::get_next_legal_states() { can_add.push_back(&foundations[i]); } } + for (vector::size_type i = 0; i < cells.size(); i++) { + can_remove.push_back(&cells[i]); + can_add.push_back(&cells[i]); + } if (rules.hole) { can_add.push_back(&hole); } -- cgit v1.2.1 From cbea9f4b5f83f1745ab7ff01b94eb96412f8e035 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 6 Nov 2017 15:40:39 +0000 Subject: Add cell printing --- src/main/game_state.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/main/game_state.cpp') diff --git a/src/main/game_state.cpp b/src/main/game_state.cpp index 2dd1ca8..90a7381 100644 --- a/src/main/game_state.cpp +++ b/src/main/game_state.cpp @@ -181,6 +181,10 @@ ostream& game_state::print(ostream& stream) const { print_header(stream, "Foundations"); print_foundations(stream); } + if (rules.cells) { + print_header(stream, "Cells"); + print_cells(stream); + } if (rules.tableau_pile_count > 0) { print_header(stream, "Tableau Piles"); print_tableau_piles(stream); @@ -208,6 +212,13 @@ void game_state::print_foundations(ostream& stream) const { << foundations[3] << "\n"; } +void game_state::print_cells(ostream& stream) const { + for (pile cell : cells) { + if (!cell.empty()) stream << cells[0] << "\t"; + } + stream << "\n"; +} + void game_state::print_tableau_piles(ostream& stream) const { bool empty_row = false; vector::size_type row_idx = 0; -- cgit v1.2.1 From dfa640b05e1f6bc0c8dcc74ea857159703c10b20 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 6 Nov 2017 16:06:45 +0000 Subject: Fixup cell/foundation mixup and printing errs --- src/main/game_state.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/main/game_state.cpp') diff --git a/src/main/game_state.cpp b/src/main/game_state.cpp index 90a7381..05bfb4f 100644 --- a/src/main/game_state.cpp +++ b/src/main/game_state.cpp @@ -87,7 +87,7 @@ game_state::game_state(int seed, const sol_rules& s_rules) if (rules.cells > 0) { for (int i = 0; i < rules.cells; i++) { pile p(true, ord::SINGLE_CARD, pol::ANY_SUIT, false); - foundations.push_back(p); + cells.push_back(p); } } } @@ -173,6 +173,11 @@ bool game_state::is_solved() const { return false; } } + for (auto p : cells) { + if (!p.empty()) { + return false; + } + } return true; } @@ -214,7 +219,11 @@ void game_state::print_foundations(ostream& stream) const { void game_state::print_cells(ostream& stream) const { for (pile cell : cells) { - if (!cell.empty()) stream << cells[0] << "\t"; + if (cells.empty()) { + stream << "[]" << "\t"; + } else { + stream << cells[0] << "\t"; + } } stream << "\n"; } -- cgit v1.2.1