diff options
| author | thecharlesblake | 2018-01-03 12:30:14 +0000 |
|---|---|---|
| committer | thecharlesblake | 2018-01-03 12:30:14 +0000 |
| commit | 77a7aeba7854d15b140cc6dc3c69b15ed5f3b936 (patch) | |
| tree | 70b3b8315646ed38000a1627ec3f3efe20f31f92 /src/main/game/sol_rules.cpp | |
| parent | Update idea to python3 (diff) | |
| download | metasol-77a7aeba7854d15b140cc6dc3c69b15ed5f3b936.tar.gz metasol-77a7aeba7854d15b140cc6dc3c69b15ed5f3b936.zip | |
Major refactor, putting pile logic into game_state
Much of the logic that was in the pile class was beginning to seem out of place. A lot of the rules have fairly arbitrary interactons between piles, which weren’t best represented in the pile classes themselves, which were getting unweildy and inefficient. Hence, much of this logic has been moved to the game state class.
Diffstat (limited to 'src/main/game/sol_rules.cpp')
| -rw-r--r-- | src/main/game/sol_rules.cpp | 35 |
1 files changed, 6 insertions, 29 deletions
diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp index 87d556f..a1567f7 100644 --- a/src/main/game/sol_rules.cpp +++ b/src/main/game/sol_rules.cpp @@ -22,25 +22,6 @@ using namespace rapidjson; typedef sol_rules::build_policy pol; -bool sol_rules::is_suit(pol bp) { - switch (bp) { - case pol::CLUBS : - case pol::DIAMONDS : - case pol::HEARTS : - case pol::SPADES : return true; - default : return false; - } -} -card::suit_t sol_rules::suit_val(pol bp) { - switch (bp) { - case pol::CLUBS : return card::suit_t::Clubs; - case pol::DIAMONDS : return card::suit_t::Diamonds; - case pol::HEARTS : return card::suit_t::Hearts; - case pol::SPADES : return card::suit_t::Spades; - default: assert(false); return card::suit_t::Spades; - } -} - const sol_rules sol_rules::from_file(const string rules_file) { sol_rules sr = get_default(); Document d = util::get_file_json(rules_file); @@ -96,8 +77,8 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { if (d["tableau piles"]["build order"].IsString()) { string bo_str = d["tableau piles"]["build order"].GetString(); - if (bo_str == "no-build") { - sr.build_ord = build_order::NO_BUILD; + if (bo_str == "ascending") { + sr.build_ord = build_order::ASCENDING; } else if (bo_str == "descending") { sr.build_ord = build_order::DESCENDING; } else { @@ -117,6 +98,10 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { sr.build_pol = build_policy::ANY_SUIT; } else if (bp_str == "red-black") { sr.build_pol = build_policy::RED_BLACK; + } else if (bp_str == "same-suit") { + sr.build_pol = build_policy::SAME_SUIT; + } else if (bp_str == "no-build") { + sr.build_pol = build_policy::NO_BUILD; } else { util::json_parse_err("[tableau piles][build policy] is invalid"); } @@ -180,14 +165,6 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) { } } - if (d.HasMember("reserve size")) { - if (d["reserve size"].IsInt()) { - sr.reserve_size = static_cast<uint8_t>(d["reserve size"].GetInt()); - } else { - util::json_parse_err("[reserve size] must be an integer"); - } - } - if (d.HasMember("stock size")) { if (d["stock size"].IsInt()) { sr.stock_size = static_cast<uint8_t>(d["stock size"].GetInt()); |
