From bba8775ce7c63783303240470d4a4b8404c9498b Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 11 Nov 2017 11:36:27 +0000 Subject: Add src file directory structure --- src/main/game/sol_rules.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/main/game/sol_rules.cpp (limited to 'src/main/game/sol_rules.cpp') diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp new file mode 100644 index 0000000..f47cf44 --- /dev/null +++ b/src/main/game/sol_rules.cpp @@ -0,0 +1,116 @@ +// +// Created by thecharlesblake on 10/28/17. +// + +#include +#include +#include +#include + +#include "sol_rules.h" + +using namespace std; + +// Static + +typedef sol_rules::build_policy pol; + +vector sol_rules::valid_sol_strs = { + "black-hole", + "simple-black-hole", + "spanish-patience", + "simple-spanish-patience", + "free-cell", + "simple-free-cell", + "canfield", + "simple-canfield" +}; + +bool sol_rules::is_suit(pol bp) { + return suit_val(bp) != -1; +} +int 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; + } +} + +// Non-static + +sol_rules::sol_rules(std::string sol_type) { + valid_sol vs = valid_sol_enum(sol_type); + + // Default game values + build_ord = build_order::DESCENDING; + build_pol = build_policy::ANY_SUIT; + max_rank = 13; + hole = false; + foundations = true; + cells = 0; + reserve_size = 0; + stock_size = 0; + + // Game-specific values + switch(vs) { + case valid_sol::BLACK_HOLE: + tableau_pile_count = 17; + build_ord = build_order::NO_BUILD; + hole = true; + foundations = false; + cells = 0; + break; + case valid_sol::SIMPLE_BLACK_HOLE: + tableau_pile_count = 9; + build_ord = build_order::NO_BUILD; + max_rank = 7; + hole = true; + foundations = false; + break; + case valid_sol::SPANISH_PATIENCE: + tableau_pile_count = 13; + break; + case valid_sol::SIMPLE_SPANISH_PATIENCE: + tableau_pile_count = 5; + max_rank = 5; + break; + case valid_sol::FREE_CELL: + tableau_pile_count = 8; + cells = 4; + break; + case valid_sol::SIMPLE_FREE_CELL: + tableau_pile_count = 3; + max_rank = 3; + cells = 1; + break; + case valid_sol::CANFIELD: + tableau_pile_count = 4; + build_pol = build_policy::RED_BLACK; + reserve_size = 14; + stock_size = 34; + break; + case valid_sol::SIMPLE_CANFIELD: + tableau_pile_count = 3; + build_pol = build_policy::RED_BLACK; + max_rank = 3; + reserve_size = 3; + stock_size = 6; + break; + default: + assert(false); + } +} + +sol_rules::valid_sol sol_rules::valid_sol_enum(const std::string& s) { + auto sol_type_it = + find(valid_sol_strs.begin(), valid_sol_strs.end(), s); + + assert(sol_type_it != valid_sol_strs.end()); + + long idx = sol_type_it - valid_sol_strs.begin(); + + return sol_rules::valid_sol(idx); +} \ No newline at end of file -- cgit v1.2.1 From b2173ab5118fb2c5700197ae8b295d1577aca3e9 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sun, 12 Nov 2017 10:17:10 +0000 Subject: Clean up sol_rules class --- src/main/game/sol_rules.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/main/game/sol_rules.cpp') diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp index f47cf44..df5b939 100644 --- a/src/main/game/sol_rules.cpp +++ b/src/main/game/sol_rules.cpp @@ -11,7 +11,9 @@ using namespace std; -// Static +//////////// +// Static // +//////////// typedef sol_rules::build_policy pol; @@ -39,12 +41,16 @@ int sol_rules::suit_val(pol bp) { } } -// Non-static +//////////////// +// Non-static // +//////////////// sol_rules::sol_rules(std::string sol_type) { valid_sol vs = valid_sol_enum(sol_type); // Default game values + + // tableau_pile_count = no obvious default build_ord = build_order::DESCENDING; build_pol = build_policy::ANY_SUIT; max_rank = 13; -- cgit v1.2.1 From 44f14e06c347db7eea68cad9c4ece8972b89ebed Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sun, 12 Nov 2017 11:33:59 +0000 Subject: Clean up deal from shuffled deck --- src/main/game/sol_rules.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/game/sol_rules.cpp') diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp index df5b939..fd32c72 100644 --- a/src/main/game/sol_rules.cpp +++ b/src/main/game/sol_rules.cpp @@ -102,8 +102,8 @@ sol_rules::sol_rules(std::string sol_type) { tableau_pile_count = 3; build_pol = build_policy::RED_BLACK; max_rank = 3; - reserve_size = 3; - stock_size = 6; + reserve_size = 2; + stock_size = 2; break; default: assert(false); -- cgit v1.2.1 From 076a6b129e6b35779ea946a5738357e9348c7f7e Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sun, 12 Nov 2017 22:41:27 +0000 Subject: Refactor game state --- src/main/game/sol_rules.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/game/sol_rules.cpp') diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp index fd32c72..003528c 100644 --- a/src/main/game/sol_rules.cpp +++ b/src/main/game/sol_rules.cpp @@ -99,9 +99,9 @@ sol_rules::sol_rules(std::string sol_type) { stock_size = 34; break; case valid_sol::SIMPLE_CANFIELD: - tableau_pile_count = 3; + tableau_pile_count = 2; build_pol = build_policy::RED_BLACK; - max_rank = 3; + max_rank = 2; reserve_size = 2; stock_size = 2; break; -- cgit v1.2.1