aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthecharlesblake2017-12-27 00:04:32 +0000
committerthecharlesblake2017-12-27 00:04:32 +0000
commitf8931f348ef456d9fac78b5cadad280f81dfcfc6 (patch)
treeb3df3f6bda5dfd0c6e7bfdeefc62a1eacd6295f4
parentAdd basic outline for spanish patience testing (diff)
downloadmetasol-f8931f348ef456d9fac78b5cadad280f81dfcfc6.tar.gz
metasol-f8931f348ef456d9fac78b5cadad280f81dfcfc6.zip

First sp test working

-rw-r--r--CMakeLists.txt14
-rw-r--r--src/main/game/game_state.cpp38
-rw-r--r--src/main/game/sol_rules.cpp5
-rw-r--r--src/main/input-output/command_line_helper.cpp6
-rw-r--r--src/main/input-output/deal_parser.cpp17
-rw-r--r--src/main/input-output/deal_parser.h4
-rw-r--r--src/main/solver/solver.cpp4
-rw-r--r--src/main/solver/solver.h4
-rw-r--r--src/test/resources/SPTestName.json7
-rw-r--r--src/test/spanish_patience_test.cpp6
-rw-r--r--src/test/test_helper.cpp18
-rw-r--r--src/test/test_helper.h2
12 files changed, 72 insertions, 53 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b0761c8..fada2d9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,7 +10,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
## source files ###############################################################
###############################################################################
-set(sources src/main/main.cpp src/main/input-output/command_line_helper.cpp
+set(main src/main/main.cpp)
+set(sources src/main/input-output/command_line_helper.cpp
src/main/input-output/command_line_helper.h src/main/input-output/log_helper.h src/main/game/card.h
src/main/game/card.cpp src/main/input-output/deal_parser.h src/main/input-output/deal_parser.cpp
src/main/solver/solver.cpp src/main/solver/solver.h src/main/game/game_state.cpp
@@ -82,7 +83,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -DBOOST_LOG_DYN_LINK -pthread
-Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept \
-Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow \
-Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Werror")
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g")
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -s -DNDEBUG -Wl,-O1")
###############################################################################
@@ -95,10 +96,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
# add the data to the target, so it becomes visible in some IDE
-add_executable(solvitaire ${sources})
-
-# this lets me include files relative to the root src dir with a <> pair
-target_include_directories(solvitaire PUBLIC src/main)
+add_executable(solvitaire ${main} ${sources})
target_link_libraries(solvitaire LINK_PUBLIC ${Boost_LIBRARIES} -lprofiler)
@@ -107,13 +105,13 @@ target_link_libraries(solvitaire LINK_PUBLIC ${Boost_LIBRARIES} -lprofiler)
## testing ####################################################################
###############################################################################
-add_executable(unit_tests ${sources_test})
+add_executable(unit_tests ${sources_test} ${sources})
# this allows us to use our executable as a link library
# therefore we can inherit all compiler options and library dependencies
set_target_properties(solvitaire PROPERTIES ENABLE_EXPORTS on)
-target_link_libraries(unit_tests gtest_main)
+target_link_libraries(unit_tests gtest_main ${Boost_LIBRARIES})
ENABLE_TESTING()
ADD_TEST(NAME unit_tests
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp
index 01a17fb..b851f2a 100644
--- a/src/main/game/game_state.cpp
+++ b/src/main/game/game_state.cpp
@@ -28,6 +28,25 @@ game_state::game_state(const sol_rules& s_rules) :
stock(pile::stock_factory()),
waste(pile::waste_factory()),
hole(pile::hole_factory(s_rules.max_rank)) {
+
+ // Creates the tableau piles
+ for (unsigned int i = 0; i < rules.tableau_pile_count; i++) {
+ tableau_piles.push_back(pile::tableau_factory(rules.build_ord));
+ }
+
+ // If there are foundation piles, create the relevant pile vectors
+ if (rules.foundations) {
+ for (int i = 0; i < 4; i++) {
+ foundations.push_back(pile::foundation_factory(pol(i)));
+ }
+ }
+
+ // If there are cell piles, create the relevant cell vectors
+ if (rules.cells > 0) {
+ for (unsigned int i = 0; i < rules.cells; i++) {
+ cells.push_back(pile::cell_factory());
+ }
+ }
}
// Construct an initial game state from a JSON doc
@@ -64,11 +83,6 @@ game_state::game_state(const sol_rules& s_rules, int seed) :
}
}
- // Creates the tableau piles
- for (unsigned int i = 0; i < rules.tableau_pile_count; i++) {
- tableau_piles.push_back(pile::tableau_factory(rules.build_ord));
- }
-
// Deal to the tableau piles (row-by-row)
unsigned int t = 0;
while (!deck.empty()) {
@@ -78,20 +92,6 @@ game_state::game_state(const sol_rules& s_rules, int seed) :
// Add the randomly generated card to the tableau piles
tableau_piles[t++ % rules.tableau_pile_count].place(c);
}
-
- // If there are foundation piles, create the relevant pile vectors
- if (rules.foundations) {
- for (int i = 0; i < 4; i++) {
- foundations.push_back(pile::foundation_factory(pol(i)));
- }
- }
-
- // If there are cell piles, create the relevant cell vectors
- if (rules.cells > 0) {
- for (unsigned int i = 0; i < rules.cells; i++) {
- cells.push_back(pile::cell_factory());
- }
- }
}
// Generate a randomly ordered vector of cards
diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp
index 66543de..91b00c1 100644
--- a/src/main/game/sol_rules.cpp
+++ b/src/main/game/sol_rules.cpp
@@ -5,13 +5,12 @@
#include <string>
#include <vector>
#include <algorithm>
-#include <input-output/log_helper.h>
#include "rapidjson/error/en.h"
-#include "util/util.h"
#include "sol_rules.h"
-#include "input-output/sol_preset_types.h"
+#include "../util/util.h"
+#include "../input-output/sol_preset_types.h"
using namespace std;
using namespace boost;
diff --git a/src/main/input-output/command_line_helper.cpp b/src/main/input-output/command_line_helper.cpp
index 49bb300..97751a4 100644
--- a/src/main/input-output/command_line_helper.cpp
+++ b/src/main/input-output/command_line_helper.cpp
@@ -6,11 +6,11 @@
#include <vector>
#include <boost/program_options.hpp>
-#include <input-output/sol_preset_types.h>
#include "command_line_helper.h"
-#include "game/sol_rules.h"
-#include "input-output/log_helper.h"
+#include "../game/sol_rules.h"
+#include "log_helper.h"
+#include "sol_preset_types.h"
using namespace std;
diff --git a/src/main/input-output/deal_parser.cpp b/src/main/input-output/deal_parser.cpp
index 3ad973f..fecc7d9 100644
--- a/src/main/input-output/deal_parser.cpp
+++ b/src/main/input-output/deal_parser.cpp
@@ -24,17 +24,16 @@ void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document&
const Value& json_tab_piles = doc["tableau piles"];
assert(json_tab_piles.IsArray());
- for (auto& json_tab : json_tab_piles.GetArray()) {
- pile tableau_pile(true, gs.rules.build_ord, pol::ANY_SUIT, false);
-
- for (auto& json_card : json_tab.GetArray()) {
- tableau_pile.place(card(json_card.GetString()));
- }
+ if (gs.tableau_piles.size() != gs.rules.tableau_pile_count) {
+ util::json_parse_err("Incorrect number of tableau piles");
+ }
- gs.tableau_piles.push_back(tableau_pile);
+ for (auto p = std::make_pair(begin(json_tab_piles.GetArray()), begin(gs.tableau_piles));
+ p.second != end(gs.tableau_piles);
+ ++p.first, ++p.second) {
- if (gs.tableau_piles.size() != gs.rules.tableau_pile_count) {
- util::json_parse_err("Incorrect number of tableau piles");
+ for (auto& json_card : p.first->GetArray()) {
+ p.second->place(card(json_card.GetString()));
}
}
}
diff --git a/src/main/input-output/deal_parser.h b/src/main/input-output/deal_parser.h
index e8b817f..93d30fc 100644
--- a/src/main/input-output/deal_parser.h
+++ b/src/main/input-output/deal_parser.h
@@ -11,8 +11,8 @@
#include <rapidjson/document.h>
#include <rapidjson/schema.h>
-#include "game/card.h"
-#include "game/sol_rules.h"
+#include "../game/card.h"
+#include "../game/sol_rules.h"
class game_state;
diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp
index 02b9c20..c487c29 100644
--- a/src/main/solver/solver.cpp
+++ b/src/main/solver/solver.cpp
@@ -7,10 +7,8 @@
#include <iostream>
#include <algorithm>
-#include <gperftools/profiler.h>
-
#include "solver.h"
-#include "input-output/log_helper.h"
+#include "../input-output/log_helper.h"
using namespace std;
using namespace boost;
diff --git a/src/main/solver/solver.h b/src/main/solver/solver.h
index 73e5e24..bb5f8cf 100644
--- a/src/main/solver/solver.h
+++ b/src/main/solver/solver.h
@@ -14,8 +14,8 @@
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/sequenced_index.hpp>
-#include "game/game_state.h"
-#include "game/sol_rules.h"
+#include "../game/game_state.h"
+#include "../game/sol_rules.h"
class solver {
public:
diff --git a/src/test/resources/SPTestName.json b/src/test/resources/SPTestName.json
new file mode 100644
index 0000000..6d1586c
--- /dev/null
+++ b/src/test/resources/SPTestName.json
@@ -0,0 +1,7 @@
+{
+ "tableau piles": [
+ ["2S", "AS", "AD"],
+ ["2D", "2H", "AH"],
+ ["2C", "AC"]
+ ]
+} \ No newline at end of file
diff --git a/src/test/spanish_patience_test.cpp b/src/test/spanish_patience_test.cpp
index f75fc8b..4168193 100644
--- a/src/test/spanish_patience_test.cpp
+++ b/src/test/spanish_patience_test.cpp
@@ -6,6 +6,10 @@
#include "test_helper.h"
+typedef test_helper th;
+
+const static std::string type = "simple-spanish-patience";
+
TEST(SpanishPatience, SPTestName) {
- EXPECT_TRUE(test_helper::is_solvable("i", "simple-spanish-patience"));
+ EXPECT_TRUE(th::is_solvable("SPTestName", type));
}
diff --git a/src/test/test_helper.cpp b/src/test/test_helper.cpp
index 5e08bc3..2e08829 100644
--- a/src/test/test_helper.cpp
+++ b/src/test/test_helper.cpp
@@ -2,8 +2,22 @@
// Created by thecharlesblake on 12/26/17.
//
+#include <rapidjson/document.h>
+
#include "test_helper.h"
+#include "../main/game/game_state.h"
+#include "../main/solver/solver.h"
+#include "../main/util/util.h"
+
+using namespace rapidjson;
+using namespace std;
+
+bool test_helper::is_solvable(const std::string& input_file, const std::string& preset_type) {
+ const Document in_doc = util::get_file_json("resources/" + input_file + ".json");
+ const sol_rules rules = sol_rules::from_preset(preset_type);
+
+ game_state gs(rules, in_doc);
+ solver sol(gs, rules);
-bool test_helper::is_solvable(std::string, std::string) {
- return false;
+ return sol.run() ? true : false;
}
diff --git a/src/test/test_helper.h b/src/test/test_helper.h
index 38bdfc0..5b8e755 100644
--- a/src/test/test_helper.h
+++ b/src/test/test_helper.h
@@ -9,7 +9,7 @@
class test_helper {
public:
- static bool is_solvable(std::string, std::string);
+ static bool is_solvable(const std::string&, const std::string&);
};