aboutsummaryrefslogtreecommitdiff
path: root/src/main/game
diff options
context:
space:
mode:
authorCharlie Blake2018-04-05 15:54:20 +0100
committerGitHub2018-04-05 15:54:20 +0100
commit4c4bf8a2e153b0ead77931285704aa7a0d2b7475 (patch)
tree716b8cc644945daaa1d9665f7ffc98a25d4a36d4 /src/main/game
parentMerge pull request #48 from thecharlesblake/wider-testing (diff)
parentAdd cmd line opts to list games and describe rules (diff)
downloadmetasol-4c4bf8a2e153b0ead77931285704aa7a0d2b7475.tar.gz
metasol-4c4bf8a2e153b0ead77931285704aa7a0d2b7475.zip

Merge pull request #49 from thecharlesblake/add-more-games

Add more games

Diffstat (limited to 'src/main/game')
-rw-r--r--src/main/game/game_state.cpp71
-rw-r--r--src/main/game/game_state.legal_moves.cpp50
-rw-r--r--src/main/game/sol_rules.cpp1
-rw-r--r--src/main/game/sol_rules.h3
4 files changed, 90 insertions, 35 deletions
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp
index 23ba50d..897adf1 100644
--- a/src/main/game/game_state.cpp
+++ b/src/main/game/game_state.cpp
@@ -228,17 +228,35 @@ bool game_state::move::is_dominance() const {
/////////////////////////
void game_state::make_move(const move m) {
- // Handles special stock-to-tableau-piles move
- if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) {
- assert(m.from == stock);
- assert(m.to == 255 );
-
- for (pile_ref tab_pr = original_tableau_piles.front();
- tab_pr < pile_ref(original_tableau_piles.front() + m.count);
- tab_pr++) {
- place_card(tab_pr, take_card(stock));
+ // Handles stock moves
+ if (m.from == stock) {
+ // Handles special stock-to-tableau-piles move
+ if (rules.stock_deal_t == sdt::TABLEAU_PILES) {
+ assert(m.from == stock);
+ assert(m.to == 255);
+
+ for (pile_ref tab_pr = original_tableau_piles.front();
+ tab_pr < pile_ref(original_tableau_piles.front() + m.count);
+ tab_pr++) {
+ place_card(tab_pr, take_card(stock));
+ }
+ }
+ // Handles stock-to-waste moves
+ else {
+ if (piles[stock].empty()) {
+ // Re-deal waste back to stock
+ while (!piles[waste].empty()) {
+ place_card(stock, take_card(waste));
+ }
+ } else {
+ assert(m.to == waste);
+ for (int i = 0; i < m.count; i++) {
+ place_card(waste, take_card(stock));
+ }
+ }
}
}
+
// If this is not a built-pile move
else if (m.count == 1 || m.is_dominance()) {
assert(m.from < piles.size());
@@ -249,6 +267,7 @@ void game_state::make_move(const move m) {
update_auto_foundation_moves(m.to);
#endif
}
+
// If this is a built-pile move
else {
assert(m.from < piles.size() );
@@ -270,14 +289,31 @@ void game_state::make_move(const move m) {
void game_state::undo_move(const move m) {
assert(m.from < piles.size());
- // Handles special stock-to-tableau-piles move
- if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) {
- for (pile_ref tab_pr = original_tableau_piles.front() + m.count;
- tab_pr-- > original_tableau_piles.front();
- ) {
- place_card(stock, take_card(tab_pr));
+ // Handles stock moves
+ if (m.from == stock) {
+ // Handles special stock-to-tableau-piles move
+ if (rules.stock_deal_t == sdt::TABLEAU_PILES) {
+ for (pile_ref tab_pr = original_tableau_piles.front() + m.count;
+ tab_pr-- > original_tableau_piles.front();
+ ) {
+ place_card(stock, take_card(tab_pr));
+ }
+ }
+ // Handles stock-to-waste moves
+ else {
+ if (piles[waste].empty()) {
+ // Re-deal waste back to stock
+ while (!piles[stock].empty()) {
+ place_card(waste, take_card(stock));
+ }
+ } else {
+ for (int i = 0; i < m.count; i++) {
+ place_card(stock, take_card(waste));
+ }
+ }
}
}
+
// If this is not a built-pile move
else if (m.count == 1 || m.is_dominance()) {
assert(m.to < piles.size());
@@ -285,7 +321,10 @@ void game_state::undo_move(const move m) {
#ifndef NO_AUTO_FOUNDATIONS
update_auto_foundation_moves(m.from);
#endif
- } else {
+ }
+
+ // If this is a built-pile move
+ else {
assert(m.to < piles.size());
assert(m.count <= rules.max_rank);
// Adds the cards to the 'from' pile
diff --git a/src/main/game/game_state.legal_moves.cpp b/src/main/game/game_state.legal_moves.cpp
index c137b07..24304a1 100644
--- a/src/main/game/game_state.legal_moves.cpp
+++ b/src/main/game/game_state.legal_moves.cpp
@@ -25,17 +25,18 @@ vector<game_state::move> game_state::get_legal_moves(
if (rules.stock_size > 0
&& rules.stock_deal_t == sdt::TABLEAU_PILES
&& !piles[stock].empty()) {
- // Only does this if none of the tableau piles are empty
- bool no_tableau_empty = true;
- for (auto tab_ref : tableau_piles) {
- if (piles[tab_ref].empty()) {
- no_tableau_empty = false;
- break;
- }
- }
- if (no_tableau_empty) {
- moves.emplace_back(get_stock_tableau_move());
- }
+
+ moves.emplace_back(get_stock_tableau_move());
+ }
+
+ // If the stock is empty and we are allowed to re-deal, move the waste
+ // back onto the stock
+ if (rules.stock_size > 0
+ && rules.stock_redeal
+ && rules.stock_deal_t == sdt::WASTE
+ && piles[stock].empty()
+ && !piles[waste].empty()) {
+ moves.emplace_back(stock, waste);
}
// Cycles through each pile which we may be able to remove a card from
@@ -70,7 +71,9 @@ vector<game_state::move> game_state::get_legal_moves(
// Stock cards can only be moved to the waste (assuming there is a waste)
if (rules.stock_size > 0 && rem_ref == stock) {
if (rules.stock_deal_t == sdt::WASTE) {
- moves.emplace_back(stock, waste);
+ uint8_t cards_to_move =
+ min(rules.stock_deal_count, piles[stock].size());
+ moves.emplace_back(stock, waste, cards_to_move);
}
continue;
}
@@ -148,12 +151,19 @@ game_state::move game_state::get_stock_tableau_move() const {
// suit/rank can be moved to a tableau
bool game_state::is_valid_tableau_move(const pile_ref rem_ref,
const pile_ref add_ref) const {
- if (rem_ref == add_ref) return false;
-
- else if (rules.build_pol == pol::NO_BUILD) return false;
-
- else if (piles[add_ref].empty()) {
- return rules.spaces_pol == s_pol::ANY;
+ if (rem_ref == add_ref) {
+ return false;
+ } else if (rules.build_pol == pol::NO_BUILD) {
+ return false;
+ } else if (piles[add_ref].empty()) {
+ switch(rules.spaces_pol) {
+ case sol_rules::spaces_policy::NO_BUILD:
+ return false;
+ case sol_rules::spaces_policy::KINGS:
+ return piles[rem_ref].top_card().get_rank() == 13;
+ case sol_rules::spaces_policy::ANY:
+ return true;
+ }
}
card rem_c = piles[rem_ref].top_card();
@@ -235,7 +245,9 @@ void game_state::get_built_group_moves(vector<move>& moves) const {
// If the pile is empty, and we can move to empty piles, does so
if (piles[add_ref].empty()) {
- if (rules.spaces_pol == s_pol::ANY) {
+ if (rules.spaces_pol == s_pol::ANY ||
+ (rules.spaces_pol == s_pol::KINGS
+ && bg_high.get_rank() == 13)) {
add_empty_built_group_moves(moves, rem_ref, add_ref, bg_high);
}
}
diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp
index 592437d..4cef7c1 100644
--- a/src/main/game/sol_rules.cpp
+++ b/src/main/game/sol_rules.cpp
@@ -26,6 +26,7 @@ sol_rules::sol_rules() :
cells(0),
stock_size(0),
stock_deal_t(sdt::TABLEAU_PILES),
+ stock_deal_count(1),
reserve_size(0),
reserve_stacked(false) {
}
diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h
index 98474fc..0314af5 100644
--- a/src/main/game/sol_rules.h
+++ b/src/main/game/sol_rules.h
@@ -21,6 +21,7 @@ struct sol_rules {
};
enum class spaces_policy {
NO_BUILD,
+ KINGS,
ANY
};
enum class stock_deal_type {
@@ -44,6 +45,8 @@ struct sol_rules {
uint8_t cells;
uint8_t stock_size;
stock_deal_type stock_deal_t;
+ uint8_t stock_deal_count;
+ bool stock_redeal;
uint8_t reserve_size;
bool reserve_stacked;
};