aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharlie Blake2018-07-19 17:28:49 +0100
committerCharlie Blake2018-07-19 17:28:49 +0100
commit0261d129cfc015ca02b9d3db0d421cf1e1afbf77 (patch)
tree5aa6d6b946a62b4d0821aa7975c16462465862eb /src
parentAdd random gen for Canfield (diff)
downloadmetasol-0261d129cfc015ca02b9d3db0d421cf1e1afbf77.tar.gz
metasol-0261d129cfc015ca02b9d3db0d421cf1e1afbf77.zip

Add whole pile legal moves gen

Diffstat (limited to 'src')
-rw-r--r--src/main/game/search-state/game_state.h2
-rw-r--r--src/main/game/search-state/game_state.legal_moves.cpp42
2 files changed, 42 insertions, 2 deletions
diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h
index 963f524..2b89d86 100644
--- a/src/main/game/search-state/game_state.h
+++ b/src/main/game/search-state/game_state.h
@@ -112,6 +112,8 @@ private:
void add_built_group_moves(std::vector<move>&) const;
void add_built_group_moves(std::vector<move>&, pile::ref, pile::size_type) const;
+ void add_whole_pile_moves(std::vector<move>&) const;
+ void add_whole_pile_moves(std::vector<move>&, pile::ref, pile::size_type) const;
pile::size_type get_built_group_height(pile::ref) const;
bool is_next_built_group_card(card, card) const;
void add_empty_built_group_moves(std::vector<move>&, pile::ref, pile::ref, pile::size_type, bool) const;
diff --git a/src/main/game/search-state/game_state.legal_moves.cpp b/src/main/game/search-state/game_state.legal_moves.cpp
index 99a37d6..7c3ee88 100644
--- a/src/main/game/search-state/game_state.legal_moves.cpp
+++ b/src/main/game/search-state/game_state.legal_moves.cpp
@@ -98,8 +98,16 @@ vector<move> game_state::get_legal_moves(move parent_move) {
if (rules.stock_size > 0 && rules.stock_deal_t == sdt::WASTE && !piles[stock].empty())
add_stock_to_tableau_moves(moves);
- if (rules.move_built_group != bgt::NO)
- add_built_group_moves(moves);
+ switch (rules.move_built_group) {
+ case sol_rules::built_group_type::YES:
+ add_built_group_moves(moves);
+ break;
+ case sol_rules::built_group_type::WHOLE_PILE:
+ add_whole_pile_moves(moves);
+ break;
+ case sol_rules::built_group_type::NO:
+ break;
+ }
// Tableau to tableau moves
for (auto t_from : tableau_piles) {
@@ -369,6 +377,36 @@ void game_state::add_built_group_moves(vector<move>& moves, pile::ref rem_ref, p
}
}
+void game_state::add_whole_pile_moves(vector<move>& moves) const {
+ assert(rules.built_group_pol != pol::NO_BUILD);
+
+ // Cycles through each pile to see if it contains a whole-pile built group
+ for (auto rem_ref : tableau_piles) {
+ auto built_group_height = get_built_group_height(rem_ref);
+
+ if (built_group_height == piles[rem_ref].size()) {
+ add_whole_pile_moves(moves, rem_ref, built_group_height);
+ }
+ }
+}
+
+void game_state::add_whole_pile_moves(vector<move>& moves, pile::ref rem_ref, pile::size_type built_group_height) const {
+ // We have found a built group. Cycles through each pile to see if it can be added
+ for (auto add_ref : tableau_piles) {
+ if (add_ref == rem_ref) continue;
+
+ card bg_high = piles[rem_ref][built_group_height - 1];
+
+ if (piles[add_ref].empty()) {
+ if (rules.spaces_pol == s_pol::ANY || rules.spaces_pol == s_pol::KINGS && bg_high.get_rank() == 13) {
+ moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height);
+ }
+ } else if (is_next_built_group_card(piles[add_ref].top_card(), bg_high)) {
+ moves.emplace_back(move::mtype::built_group, rem_ref, add_ref, built_group_height);
+ }
+ }
+}
+
// Finds the size of the built group at the top of a pile
pile::size_type game_state::get_built_group_height(pile::ref ref) const {
pile::size_type i = 1;