From 9c018b08ed775eda03e4507e33a20742659683ea Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 14:03:54 +0100 Subject: Refactor game generation to make more generic --- src/main/game_state.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/main/game_state.h') diff --git a/src/main/game_state.h b/src/main/game_state.h index ff92247..88e8937 100644 --- a/src/main/game_state.h +++ b/src/main/game_state.h @@ -17,6 +17,7 @@ class game_state { public: game_state(const rapidjson::Document&, std::string); game_state(int seed, std::string); + std::vector get_next_legal_states() const; bool is_solved() const; std::ostream& print(std::ostream&) const; @@ -24,9 +25,10 @@ public: friend std::ostream& operator<< (std::ostream&, const game_state&); private: + static std::vector shuffled_deck(int, int); + void move_to_hole(int); bool adjacent(const card& a, const card& b) const; - bool simple; std::vector > tableau_piles; int max_rank; -- cgit v1.2.1 From 6a5a840f678aa78659b51ec647dcced4544c4a0b Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 15:29:17 +0100 Subject: Modify game state generation to work across sols --- src/main/game_state.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/game_state.h') diff --git a/src/main/game_state.h b/src/main/game_state.h index 88e8937..ebcc15f 100644 --- a/src/main/game_state.h +++ b/src/main/game_state.h @@ -12,11 +12,12 @@ #include #include "card.h" +#include "sol_rules.h" class game_state { public: - game_state(const rapidjson::Document&, std::string); - game_state(int seed, std::string); + game_state(const rapidjson::Document&); + game_state(int seed, const sol_rules&); std::vector get_next_legal_states() const; bool is_solved() const; @@ -31,7 +32,6 @@ private: bool adjacent(const card& a, const card& b) const; std::vector > tableau_piles; - int max_rank; card hole_card; mutable bool solved; }; -- cgit v1.2.1 From c2e0bbad760bb95b7967d6df065c46e1aac1270d Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 15:50:45 +0100 Subject: Add generic state printing --- src/main/game_state.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/main/game_state.h') diff --git a/src/main/game_state.h b/src/main/game_state.h index ebcc15f..974fd2a 100644 --- a/src/main/game_state.h +++ b/src/main/game_state.h @@ -30,8 +30,14 @@ private: void move_to_hole(int); bool adjacent(const card& a, const card& b) const; + void print_header(std::ostream&, const char*) const; + void print_foundations(std::ostream&) const; + void print_tableau_piles(std::ostream&) const; + void print_hole(std::ostream&) const; std::vector > tableau_piles; + std::vector foundations; + sol_rules rules; card hole_card; mutable bool solved; }; -- cgit v1.2.1 From c3e6f892599f145c14317e5712263b3e5562b785 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 22:21:03 +0100 Subject: Add generic solving and pile class --- src/main/game_state.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main/game_state.h') diff --git a/src/main/game_state.h b/src/main/game_state.h index 974fd2a..c5d4f96 100644 --- a/src/main/game_state.h +++ b/src/main/game_state.h @@ -13,6 +13,7 @@ #include "card.h" #include "sol_rules.h" +#include "pile.h" class game_state { public: @@ -35,11 +36,10 @@ private: void print_tableau_piles(std::ostream&) const; void print_hole(std::ostream&) const; - std::vector > tableau_piles; - std::vector foundations; + std::vector tableau_piles; + std::vector foundations; + pile hole; sol_rules rules; - card hole_card; - mutable bool solved; }; -- cgit v1.2.1 From 578f9c9f92d05b5907b91f07a4c732839d4dfca5 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 6 Nov 2017 14:14:38 +0000 Subject: Add counting of states searched --- src/main/game_state.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/main/game_state.h') diff --git a/src/main/game_state.h b/src/main/game_state.h index c5d4f96..311c97f 100644 --- a/src/main/game_state.h +++ b/src/main/game_state.h @@ -17,20 +17,23 @@ class game_state { public: + // Create a game state representation from a JSON doc game_state(const rapidjson::Document&); + // Do the same from a 'rules' object game_state(int seed, const sol_rules&); - std::vector get_next_legal_states() const; + std::vector get_next_legal_states(); + // NOTE: will only be evaluated after get_next_legal_states() is called bool is_solved() const; + std::ostream& print(std::ostream&) const; + friend bool operator==(const game_state&, const game_state&); friend std::ostream& operator<< (std::ostream&, const game_state&); private: static std::vector shuffled_deck(int, int); - void move_to_hole(int); - bool adjacent(const card& a, const card& b) const; void print_header(std::ostream&, const char*) const; void print_foundations(std::ostream&) const; void print_tableau_piles(std::ostream&) const; @@ -38,8 +41,8 @@ private: std::vector tableau_piles; std::vector foundations; - pile hole; sol_rules rules; + pile hole; }; -- cgit v1.2.1