aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorthecharlesblake2017-12-29 17:21:50 +0000
committerthecharlesblake2017-12-29 17:21:50 +0000
commit8e03459171278f31f6aa7b7f227c5760c3f4788f (patch)
tree5aa9c6f4a4dda01b89b00d3722fd3f7d7027cebb /src/main
parentMake card representation efficient (diff)
downloadmetasol-8e03459171278f31f6aa7b7f227c5760c3f4788f.tar.gz
metasol-8e03459171278f31f6aa7b7f227c5760c3f4788f.zip

Make rules representation efficient

Diffstat (limited to 'src/main')
-rw-r--r--src/main/game/sol_rules.cpp30
-rw-r--r--src/main/game/sol_rules.h24
2 files changed, 32 insertions, 22 deletions
diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp
index 91b00c1..353c8db 100644
--- a/src/main/game/sol_rules.cpp
+++ b/src/main/game/sol_rules.cpp
@@ -23,15 +23,21 @@ using namespace rapidjson;
typedef sol_rules::build_policy pol;
bool sol_rules::is_suit(pol bp) {
- return suit_val(bp) != -1;
+ switch (bp) {
+ case pol::CLUBS :
+ case pol::DIAMONDS :
+ case pol::HEARTS :
+ case pol::SPADES : return true;
+ default : return false;
+ }
}
-int sol_rules::suit_val(pol bp) {
+card::suit_t sol_rules::suit_val(pol bp) {
switch (bp) {
- case pol::CLUBS: return 0;
- case pol::DIAMONDS: return 1;
- case pol::HEARTS: return 2;
- case pol::SPADES: return 3;
- default: return -1;
+ 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;
}
}
@@ -80,7 +86,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) {
if (d["tableau piles"].HasMember("count")) {
if (d["tableau piles"]["count"].IsInt()) {
- sr.tableau_pile_count = d["tableau piles"]["count"].GetInt();
+ sr.tableau_pile_count = static_cast<uint8_t>(d["tableau piles"]["count"].GetInt());
} else {
util::json_parse_err("[tableau piles][count] must be an integer");
}
@@ -127,7 +133,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) {
if (d.HasMember("max rank")) {
if (d["max rank"].IsInt()) {
- sr.max_rank = d["max rank"].GetInt();
+ sr.max_rank = static_cast<card::rank_t>(d["max rank"].GetInt());
} else {
util::json_parse_err("[max rank] must be an integer");
}
@@ -151,7 +157,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) {
if (d.HasMember("cells")) {
if (d["cells"].IsInt()) {
- sr.cells = d["cells"].GetInt();
+ sr.cells = static_cast<uint8_t>(d["cells"].GetInt());
} else {
util::json_parse_err("[cells] must be an integer");
}
@@ -159,7 +165,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) {
if (d.HasMember("reserve size")) {
if (d["reserve size"].IsInt()) {
- sr.reserve_size = d["reserve size"].GetInt();
+ sr.reserve_size = static_cast<uint8_t>(d["reserve size"].GetInt());
} else {
util::json_parse_err("[reserve size] must be an integer");
}
@@ -167,7 +173,7 @@ void sol_rules::modify_sol_rules(sol_rules& sr, Document& d) {
if (d.HasMember("stock size")) {
if (d["stock size"].IsInt()) {
- sr.stock_size = d["stock size"].GetInt();
+ sr.stock_size = static_cast<uint8_t>(d["stock size"].GetInt());
} else {
util::json_parse_err("[stock size] must be an integer");
}
diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h
index 17dd74a..a2f8fe9 100644
--- a/src/main/game/sol_rules.h
+++ b/src/main/game/sol_rules.h
@@ -11,6 +11,8 @@
#include <boost/optional.hpp>
#include <rapidjson/document.h>
+#include "card.h"
+
class sol_rules {
public:
enum class valid_sol {
@@ -28,7 +30,8 @@ public:
DESCENDING,
ASCENDING,
BOTH,
- SINGLE_CARD
+ SINGLE_CARD,
+ ANY
};
enum class build_policy {
CLUBS,
@@ -37,24 +40,25 @@ public:
SPADES,
ANY_SUIT,
SAME_SUIT,
- RED_BLACK
+ RED_BLACK,
+ N_A
};
+ static bool is_suit(build_policy);
+ static card::suit_t suit_val(build_policy);
+
static const sol_rules from_preset(const std::string);
static const sol_rules from_file(const std::string);
- static bool is_suit(build_policy);
- static int suit_val(build_policy);
-
- unsigned int tableau_pile_count;
+ uint8_t tableau_pile_count;
build_order build_ord;
build_policy build_pol;
- unsigned int max_rank;
+ card::rank_t max_rank;
bool hole;
bool foundations;
- unsigned int cells;
- unsigned int reserve_size;
- unsigned int stock_size;
+ uint8_t cells;
+ uint8_t reserve_size;
+ uint8_t stock_size;
private:
static sol_rules get_default();