aboutsummaryrefslogtreecommitdiff
path: root/src/main/game_state.cpp
diff options
context:
space:
mode:
authorCharlie Blake2017-11-07 10:00:41 +0000
committerGitHub2017-11-07 10:00:41 +0000
commit45a4fa8ddeaa707e63e0dc88fcb7e561c5ecf9d9 (patch)
tree2b0301e9198a6d56afb60055ef6aeb68b466e047 /src/main/game_state.cpp
parentMerge pull request #16 from thecharlesblake/docs (diff)
parentFixup cell/foundation mixup and printing errs (diff)
downloadmetasol-45a4fa8ddeaa707e63e0dc88fcb7e561c5ecf9d9.tar.gz
metasol-45a4fa8ddeaa707e63e0dc88fcb7e561c5ecf9d9.zip

Merge pull request #17 from thecharlesblake/free-cell

Free cell

Diffstat (limited to 'src/main/game_state.cpp')
-rw-r--r--src/main/game_state.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/main/game_state.cpp b/src/main/game_state.cpp
index 29ccdc3..05bfb4f 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<card> 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);
+ cells.push_back(p);
+ }
+ }
}
// Generate a randomly ordered vector of cards
@@ -129,6 +137,10 @@ vector<game_state> game_state::get_next_legal_states() {
can_add.push_back(&foundations[i]);
}
}
+ for (vector<pile>::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);
}
@@ -161,6 +173,11 @@ bool game_state::is_solved() const {
return false;
}
}
+ for (auto p : cells) {
+ if (!p.empty()) {
+ return false;
+ }
+ }
return true;
}
@@ -169,6 +186,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);
@@ -196,6 +217,17 @@ void game_state::print_foundations(ostream& stream) const {
<< foundations[3] << "\n";
}
+void game_state::print_cells(ostream& stream) const {
+ for (pile cell : cells) {
+ if (cells.empty()) {
+ stream << "[]" << "\t";
+ } else {
+ stream << cells[0] << "\t";
+ }
+ }
+ stream << "\n";
+}
+
void game_state::print_tableau_piles(ostream& stream) const {
bool empty_row = false;
vector<card>::size_type row_idx = 0;