aboutsummaryrefslogtreecommitdiff
path: root/src/main/game/search-state/game_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/game/search-state/game_state.cpp')
-rw-r--r--src/main/game/search-state/game_state.cpp103
1 files changed, 64 insertions, 39 deletions
diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp
index 7870b1b..276d582 100644
--- a/src/main/game/search-state/game_state.cpp
+++ b/src/main/game/search-state/game_state.cpp
@@ -257,14 +257,11 @@ void game_state::make_move(const move m) {
case move::mtype::built_group:
make_built_group_move(m);
break;
- case move::mtype::stock_to_waste:
- make_stock_to_waste_move(m);
+ case move::mtype::stock_k_plus:
+ make_stock_k_plus_move(m);
break;
- case move::mtype::stock_to_tableau:
- make_stock_to_tableau_move(m);
- break;
- case move::mtype::redeal:
- make_redeal_move();
+ case move::mtype::stock_to_all_tableau:
+ make_stock_to_all_tableau_move(m);
break;
case move::mtype::null:
assert(false);
@@ -285,14 +282,11 @@ void game_state::undo_move(const move m) {
case move::mtype::built_group:
undo_built_group_move(m);
break;
- case move::mtype::stock_to_waste:
- undo_stock_to_waste_move(m);
- break;
- case move::mtype::stock_to_tableau:
- undo_stock_to_tableau_move(m);
+ case move::mtype::stock_k_plus:
+ undo_stock_k_plus_move(m);
break;
- case move::mtype::redeal:
- undo_redeal_move();
+ case move::mtype::stock_to_all_tableau:
+ undo_stock_to_all_tableau_move(m);
break;
case move::mtype::null:
assert(false);
@@ -382,23 +376,71 @@ void game_state::undo_built_group_move(move m) {
}
}
-void game_state::make_stock_to_waste_move(const move m) {
+void game_state::make_stock_k_plus_move(const move m) {
assert(rules.stock_deal_t == sdt::WASTE);
+ assert(m.count < piles[stock].size() + piles[waste].size());
+ assert(!rules.stock_redeal || m.to != waste);
+#ifndef NDEBUG
+ auto sz_before = piles[stock].size() + piles[waste].size();
+#endif
+ // if redeal -> stock tableau move implies s+w-=1
- for (int i = 0; i < m.count; i++) {
- place_card(waste, take_card(stock));
+ // Index of the card to be moved
+ auto count = m.count % (piles[stock].size() + piles[waste].size());
+
+ for (int i = 0; i <= count; i++) {
+ if (i < count) place_card(waste, take_card(stock));
+ else place_card(m.to, take_card(stock));
+
+ if (rules.stock_redeal) {
+ // If the stock is empty, flips it
+ // (invariant: no search state has an empty stock if rules.stock_size > 0 && rules.stock_redeal)
+ if (piles[stock].empty())
+ while (!piles[waste].empty())
+ place_card(stock, take_card(waste));
+ }
}
+
+#ifndef NDEBUG
+ auto sz_after = piles[stock].size() + piles[waste].size();
+ assert(sz_before == sz_after + 1);
+#endif
+ assert(!(rules.stock_size > 0 && rules.stock_redeal && piles[stock].empty() && !piles[waste].empty()));
+ assert(piles[stock].size() <= rules.stock_size);
}
-void game_state::undo_stock_to_waste_move(const move m) {
+void game_state::undo_stock_k_plus_move(move m) {
assert(rules.stock_deal_t == sdt::WASTE);
+ assert(m.count < piles[stock].size() + piles[waste].size() + 1);
+ assert(!rules.stock_redeal || m.to != waste);
+#ifndef NDEBUG
+ auto sz_after = piles[stock].size() + piles[waste].size();
+#endif
+
+ auto count = m.count % (piles[stock].size() + piles[waste].size() + 1);
- for (int i = 0; i < m.count; i++) {
- place_card(stock, take_card(waste));
+ for (int i = count; i >= 0; i--) {
+ if (rules.stock_redeal) {
+ // If the waste is empty, flips it
+ // (invariant: no search state has an empty stock if rules.stock_size > 0 && rules.stock_redeal)
+ if (piles[waste].empty())
+ while (!piles[stock].empty())
+ place_card(waste, take_card(stock));
+ }
+
+ if (i < count) place_card(stock, take_card(waste));
+ else place_card(stock, take_card(m.to ));
}
+
+#ifndef NDEBUG
+ auto sz_before = piles[stock].size() + piles[waste].size();
+ assert(sz_before == sz_after + 1);
+#endif
+ assert(!(rules.stock_size > 0 && rules.stock_redeal && piles[stock].empty() && !piles[waste].empty()));
+ assert(piles[stock].size() <= rules.stock_size);
}
-void game_state::make_stock_to_tableau_move(const move m) {
+void game_state::make_stock_to_all_tableau_move(move m) {
assert(rules.stock_deal_t == sdt::TABLEAU_PILES);
for (pile::ref tab_pr = original_tableau_piles.front();
@@ -408,7 +450,7 @@ void game_state::make_stock_to_tableau_move(const move m) {
}
}
-void game_state::undo_stock_to_tableau_move(const move m) {
+void game_state::undo_stock_to_all_tableau_move(move m) {
assert(rules.stock_deal_t == sdt::TABLEAU_PILES);
for (pile::ref tab_pr = original_tableau_piles.front() + m.count;
@@ -418,23 +460,6 @@ void game_state::undo_stock_to_tableau_move(const move m) {
}
}
-void game_state::make_redeal_move() {
- assert(piles[stock].empty());
-
- // Re-deal waste back to stock
- while (!piles[waste].empty()) {
- place_card(stock, take_card(waste));
- }
-}
-
-void game_state::undo_redeal_move() {
- assert(piles[waste].empty());
-
- while (!piles[stock].empty()) {
- place_card(waste, take_card(stock));
- }
-}
-
// 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) {