diff options
| -rw-r--r-- | CMakeLists.txt | 8 | ||||
| -rw-r--r-- | src/main/game/global_cache.cpp | 36 | ||||
| -rw-r--r-- | src/main/game/global_cache.h | 11 |
3 files changed, 3 insertions, 52 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d5eef74..01ef9b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,6 +131,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -DBOOST_LOG_DYN_LINK -pthread -Wstrict-null-sentinel -Werror") 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") +#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -g -Wl,-O1") # uncomment for profiling ############################################################################### ## target definitions ######################################################### @@ -174,12 +175,7 @@ set_target_properties(solvitaire-no-suit-symmetry PROPERTIES COMPILE_FLAGS -DNO_ add_executable(solvitaire-no-symmetry ${main} ${sources}) target_link_libraries(solvitaire-no-symmetry LINK_PUBLIC ${Boost_LIBRARIES}) set_target_properties(solvitaire-no-symmetry PROPERTIES COMPILE_FLAGS "-DNO_SUIT_SYMMETRY -DNO_PILE_SYMMETRY") - -# add a separete executable for the 'no reduced state' version of the solver -add_executable(solvitaire-no-reduced-state ${main} ${sources}) -target_link_libraries(solvitaire-no-reduced-state LINK_PUBLIC ${Boost_LIBRARIES}) -set_target_properties(solvitaire-no-reduced-state PROPERTIES COMPILE_FLAGS -DNO_REDUCED_STATE) - + # add a separete executable for the 'no auto foundations' version of the solver add_executable(solvitaire-no-auto-foundations ${main} ${sources}) target_link_libraries(solvitaire-no-auto-foundations LINK_PUBLIC ${Boost_LIBRARIES}) diff --git a/src/main/game/global_cache.cpp b/src/main/game/global_cache.cpp index 44d4bb7..f2320ef 100644 --- a/src/main/game/global_cache.cpp +++ b/src/main/game/global_cache.cpp @@ -23,20 +23,9 @@ cached_game_state::cached_game_state(const game_state& gs) { data.reserve(52+18); // Enough for each card and up to 18 piles if (gs.rules.hole) { -#ifdef NO_REDUCED_STATE - add_pile(gs.hole, gs); -#else add_card(gs.piles[gs.hole].top_card(), gs); -#endif } - // No need to add foundations for reduced state, as they are implicit in the - // other piles -#ifdef NO_REDUCED_STATE - for (game_state::pile_ref pr : gs.foundations) - add_pile(pr, gs); -#endif - for (game_state::pile_ref pr : gs.cells) { add_pile(pr, gs); } @@ -69,21 +58,13 @@ cached_game_state::cached_game_state(const game_state& gs) { void cached_game_state::add_pile(game_state::pile_ref pr, const game_state& gs) { -#ifdef NO_REDUCED_STATE - data.emplace_back(pile()); -#endif for (card c : gs.piles[pr].pile_vec) { add_card(c, gs); } } void cached_game_state::add_card(card c, const game_state& gs) { - -#ifdef NO_REDUCED_STATE - auto& target = data.back().pile_vec; -#else auto& target = data; -#endif // If the game is a 'hole-based' game, or suit-reduction is on, reduces // the cached suit of the card where possible @@ -114,9 +95,7 @@ void cached_game_state::add_card(card c, const game_state& gs) { } void cached_game_state::add_card_divider() { -#ifndef NO_REDUCED_STATE data.emplace_back(0, 0); -#endif } bool operator==(const cached_game_state& a, const cached_game_state& b) { @@ -135,27 +114,12 @@ hasher::hasher(const game_state& gs) : init_gs(gs) { size_t hasher::operator()(const cached_game_state& cgs) const { size_t seed = 0; -#ifdef NO_REDUCED_STATE - for (const pile& d : cgs.data) { -#else for (card d : cgs.data) { -#endif combine(seed, hash_value(d)); } return seed; } -#ifdef NO_REDUCED_STATE -size_t hasher::hash_value(pile const& p) const { - std::size_t seed = 0; - - for(auto first = begin(p.pile_vec); first != end(p.pile_vec); ++first) { - combine(seed, hash_value(*first)); - } - return seed; -} -#endif - std::size_t hasher::combine(std::size_t& seed, std::size_t value) const { return seed ^= value + 0x9e3779b9 + (seed<<6) + (seed>>2); } diff --git a/src/main/game/global_cache.h b/src/main/game/global_cache.h index 4658e52..b3164ea 100644 --- a/src/main/game/global_cache.h +++ b/src/main/game/global_cache.h @@ -14,13 +14,7 @@ #include "game_state.h" struct cached_game_state { - typedef std::vector< -#ifdef NO_REDUCED_STATE - pile -#else - card -#endif - > state_data; + typedef std::vector<card> state_data; typedef state_data::size_type size_type; explicit cached_game_state(const game_state&); @@ -37,9 +31,6 @@ struct hasher { std::size_t operator() (const cached_game_state&) const; std::size_t hash_value(const card&) const; -#ifdef NO_REDUCED_STATE - std::size_t hash_value(const pile&) const; -#endif std::size_t combine(std::size_t&, std::size_t) const; const game_state& init_gs; |
