aboutsummaryrefslogtreecommitdiff
path: root/src/main/game/search-state/game_state.cpp
diff options
context:
space:
mode:
authorCharlie Blake2018-06-28 14:19:31 +0100
committerCharlie Blake2018-06-28 14:19:31 +0100
commitc84d8ccf133bc49c44c185dac7b49a46b8878ec1 (patch)
tree6552511569ab94e28036c03ce5e889630d8df045 /src/main/game/search-state/game_state.cpp
parentAdd kplus unit tests (diff)
downloadmetasol-c84d8ccf133bc49c44c185dac7b49a46b8878ec1.tar.gz
metasol-c84d8ccf133bc49c44c185dac7b49a46b8878ec1.zip

Implement to pass unit tests

Diffstat (limited to 'src/main/game/search-state/game_state.cpp')
-rw-r--r--src/main/game/search-state/game_state.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp
index 7870b1b..d974c26 100644
--- a/src/main/game/search-state/game_state.cpp
+++ b/src/main/game/search-state/game_state.cpp
@@ -385,16 +385,39 @@ void game_state::undo_built_group_move(move m) {
void game_state::make_stock_to_waste_move(const move m) {
assert(rules.stock_deal_t == sdt::WASTE);
- 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));
+ }
}
}
void game_state::undo_stock_to_waste_move(const move m) {
assert(rules.stock_deal_t == sdt::WASTE);
- for (int i = 0; i < m.count; i++) {
- place_card(stock, take_card(waste));
+ auto count = m.count % (piles[stock].size() + piles[waste].size() + 1);
+
+ 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 ));
}
}