aboutsummaryrefslogtreecommitdiff
path: root/src/main/game/search-state/game_state.cpp
diff options
context:
space:
mode:
authorCharlie Blake2018-07-15 01:16:38 +0100
committerCharlie Blake2018-07-18 16:04:06 +0100
commitdf6b4405801f762cc536ed441c673e4bd1675620 (patch)
tree62bbba8f7dd114ccd39f0e935b1bc4fbd74250dd /src/main/game/search-state/game_state.cpp
parentAdd accordion top pile state caching (diff)
downloadmetasol-df6b4405801f762cc536ed441c673e4bd1675620.tar.gz
metasol-df6b4405801f762cc536ed441c673e4bd1675620.zip

Add accordion move making

Diffstat (limited to 'src/main/game/search-state/game_state.cpp')
-rw-r--r--src/main/game/search-state/game_state.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp
index b1a8e5e..0388d9c 100644
--- a/src/main/game/search-state/game_state.cpp
+++ b/src/main/game/search-state/game_state.cpp
@@ -184,8 +184,8 @@ game_state::game_state(const sol_rules& s_rules, int seed, streamliner_options s
// Deals to the accordion
if (rules.accordion_size > 0) {
- for (unsigned int i = 0; i < rules.accordion_size; i++) {
- place_card(accordion[i], deck.back());
+ for (auto pr : accordion) {
+ place_card(pr, deck.back());
deck.pop_back();
}
}
@@ -305,6 +305,9 @@ void game_state::make_move(const move m) {
case move::mtype::sequence:
make_sequence_move(m);
break;
+ case move::mtype::accordion:
+ make_accordion_move(m);
+ break;
case move::mtype::null:
assert(false);
break;
@@ -333,6 +336,9 @@ void game_state::undo_move(const move m) {
case move::mtype::sequence:
undo_sequence_move(m);
break;
+ case move::mtype::accordion:
+ undo_accordion_move(m);
+ break;
case move::mtype::null:
assert(false);
break;
@@ -377,10 +383,8 @@ void game_state::undo_regular_move(const move m) {
}
void game_state::make_built_group_move(move m) {
- assert(rules.move_built_group);
assert(m.from < piles.size() );
assert(m.to < piles.size() );
- assert(m.count <= rules.max_rank);
// Adds the cards to the 'to' pile
for (auto pile_idx = m.count; pile_idx-- > 0;) {
@@ -400,9 +404,7 @@ void game_state::make_built_group_move(move m) {
}
void game_state::undo_built_group_move(move m) {
- assert(rules.move_built_group);
assert(m.to < piles.size());
- assert(m.count <= rules.max_rank);
if (m.reveal_move) {
assert(!piles[m.from].empty());
@@ -540,6 +542,16 @@ void game_state::undo_sequence_move(const move m) {
piles[from_seq_ref][from_card_idx] = to_card;
}
+void game_state::make_accordion_move(move m) {
+ make_built_group_move(m);
+ accordion.remove(m.from);
+}
+
+void game_state::undo_accordion_move(move m) {
+ accordion.insert(upper_bound(begin(accordion), end(accordion), m.from), m.from);
+ undo_built_group_move(m);
+}
+
// Places a card on a pile and if it is on a tableau, cell or reserve pile,
// reorders the pile refs so that the largest pile is first
void game_state::place_card(pile::ref pr, card c) {
@@ -595,9 +607,9 @@ bool game_state::is_solved() const {
} else if (rules.foundations_present) {
for (auto f : foundations) {
if (piles[f].size() != rules.max_rank) {
- solved = false;
- }
-}
+ solved = false;
+ }
+ }
} else if (rules.sequence_count > 0) {
for (pile::ref i = 0; i < sequences.size() && solved; i++) {
for (pile::ref j = piles[sequences[i]].size(); j-- > 2;) {
@@ -608,6 +620,8 @@ bool game_state::is_solved() const {
}
if (piles[sequences[i]].top_card() != "AS") solved = false;
}
+ } else if (rules.accordion_size > 0) {
+ return accordion.size() == 1;
} else {
assert(false);
}