From c5064699ca59935cda93be77555ad77650bd00e1 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 3 Oct 2017 23:40:54 +0100 Subject: Create proper CMake build (install & resources) --- src/main/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/main.cpp (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp new file mode 100644 index 0000000..f253cbe --- /dev/null +++ b/src/main/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello, World!" << std::endl; + return 0; +} \ No newline at end of file -- cgit v1.2.1 From 43591b71e8d69e2184cf1eafb8de05988b8dab53 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 4 Oct 2017 11:53:16 +0100 Subject: Add conan.io to project & add Boost to Hello World --- src/main/main.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index f253cbe..0c9e38a 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -1,6 +1,15 @@ +#include #include +#include + +int main() +{ + std::string hello( "Hello, world!\n" ); + + BOOST_FOREACH( char ch, hello ) + { + std::cout << ch; + } -int main() { - std::cout << "Hello, World!" << std::endl; return 0; } \ No newline at end of file -- cgit v1.2.1 From a70e9a857ece06da65d7ce7c6d271dcd39968d55 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 11 Oct 2017 11:00:50 +0100 Subject: Add basic logging to project --- src/main/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index 0c9e38a..54bc493 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -1,9 +1,19 @@ #include #include #include +#include + +namespace logging = boost::log; int main() { + +#ifndef NDEBUG + BOOST_LOG_TRIVIAL(debug) << "Log debug"; +#endif + BOOST_LOG_TRIVIAL(info) << "Log info"; + BOOST_LOG_TRIVIAL(warning) << "Log warning"; + std::string hello( "Hello, world!\n" ); BOOST_FOREACH( char ch, hello ) -- cgit v1.2.1 From 6132bc9f3a8b7ce9dc1a17dd027166170697943b Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 11 Oct 2017 11:30:29 +0100 Subject: Add logging macros --- src/main/main.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index 54bc493..3b4b00b 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -3,16 +3,21 @@ #include #include -namespace logging = boost::log; +#if defined NDEBUG + #define LOG_DEBUG(msg) +#else + #define LOG_DEBUG(msg) BOOST_LOG_TRIVIAL(debug) << msg +#endif +#define LOG_INFO(msg) BOOST_LOG_TRIVIAL(info) << msg +#define LOG_WARNING(msg) BOOST_LOG_TRIVIAL(warning) << msg +#define LOG_ERROR(msg) BOOST_LOG_ERROR(error) << msg int main() { -#ifndef NDEBUG - BOOST_LOG_TRIVIAL(debug) << "Log debug"; -#endif - BOOST_LOG_TRIVIAL(info) << "Log info"; - BOOST_LOG_TRIVIAL(warning) << "Log warning"; + LOG_DEBUG("Log debug"); + LOG_INFO("Log info"); + LOG_WARNING("Log warning"); std::string hello( "Hello, world!\n" ); -- cgit v1.2.1 From c04bec7b528aa3fe953f6a9b838c771d02c4f3b8 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 12 Oct 2017 11:19:23 +0100 Subject: Basic Black Hole solver --- src/main/main.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 99 insertions(+), 8 deletions(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index 3b4b00b..1b75252 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -1,6 +1,10 @@ #include #include -#include +#include +#include +#include +#include +#include "Card.h" #include #if defined NDEBUG @@ -12,19 +16,106 @@ #define LOG_WARNING(msg) BOOST_LOG_TRIVIAL(warning) << msg #define LOG_ERROR(msg) BOOST_LOG_ERROR(error) << msg +using namespace std; + +bool search(vector* >, Card* hole); + int main() { + const int topRank = 4; + + vector* > tableaux; - LOG_DEBUG("Log debug"); - LOG_INFO("Log info"); - LOG_WARNING("Log warning"); + vector shuffleCards; + for (int r = 1; r <= topRank; r++) { + for (int s = 0; s < 4; s++) { + string suit; + if (s == 0) { + suit = "D"; + } else if (s == 1) { + suit = "S"; + } else if (s == 2) { + suit = "H"; + } else { + suit = "C"; + } + + Card* c = new Card(r, suit); + shuffleCards.push_back(c); + } + } - std::string hello( "Hello, world!\n" ); + auto rng = std::default_random_engine(2); // 3 has solution + std::shuffle(std::begin(shuffleCards), std::end(shuffleCards), rng); - BOOST_FOREACH( char ch, hello ) - { - std::cout << ch; + for (int i = 0; i < topRank * 2; i++) { + vector* tab = new vector(); + for (int j = 0; j < 2; j++) { + int idx = i + (topRank * 2 * j); + if (shuffleCards[idx]->suit == "S" && shuffleCards[idx]->rank == 1) { + continue; + } else { + tab->push_back(shuffleCards[idx]); + } + } + tableaux.push_back(tab); } + Card c(2, string("H")); + LOG_DEBUG(c); + + cout << (search(tableaux, new Card(1, "S")) ? "Solution Found" : "No Solution"); + return 0; +} + +bool search(vector* > tableaux, Card* hole) { + // If the tableaux are all empty, return true + + // Seaches through each tableau. If the top card is one away from + // the hole card, puts it in the hole and recurses. + // If that fails then put the card back and repeat for the next foundation + // If it succeeds, return true + + // If we get to the end of the function, return false + +#ifndef NDEBUG + string stateRep; + for (unsigned int i = 0; i < 2; i++) { + for (auto tableau : tableaux) { + if (tableau->size() > i) { + cout << *(*tableau)[i]; + } + cout << "\t"; + } + cout << "\n"; + } + cout << "Hole: " << *hole << "\n"; +#endif + + bool allTableauxEmpty = true; + for (unsigned int i = 0; i < tableaux.size(); i++) { + auto tableau = tableaux[i]; + + if (tableau->empty()) { + continue; + } else { + allTableauxEmpty = false; + } + + Card* topCard = tableau->back(); + if (topCard->rank == hole->rank + 1 || topCard->rank == hole->rank - 1) { + tableau->pop_back(); + + bool success = search(tableaux, topCard); + + if (success) { + return true; + } else { + tableau->push_back(topCard); + } + } + } + + return allTableauxEmpty; } \ No newline at end of file -- cgit v1.2.1