From 3eff79ed14f1fda1f148a9a4c5c3a1ae4edbee37 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 26 Oct 2017 14:51:13 +0100 Subject: BH Solver with path outputted, based on user input --- src/main/black_hole_state.cpp | 74 ------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 src/main/black_hole_state.cpp (limited to 'src/main/black_hole_state.cpp') diff --git a/src/main/black_hole_state.cpp b/src/main/black_hole_state.cpp deleted file mode 100644 index 4b54bc6..0000000 --- a/src/main/black_hole_state.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// -// Created by thecharlesblake on 10/23/17. -// - -#include - -#include - -#include "card.h -#include "game_state.h" -#include "black_hole_state.h" - -using namespace std; -using namespace rapidjson; - - -black_hole_state::black_hole_state(const Document& doc) - : game_state(doc), solved(false) { - // Assign hole card - assert(doc.HasMember("hole card")); - const Value& json_h_card = doc["hole card"]; - assert(json_h_card.IsArray()); - hole_card = doc["hole card"].GetString(); -}; - -vector black_hole_state::get_next_legal_states() const { - vector next; - - bool all_tableaux_empty = true; - for (int i = 0; i < tableau_piles.size(); i++) { - vector tableau_pile = tableau_piles[i]; - card top_card = tableau_pile.back(); - - if (tableau_pile.empty()) { - continue; - } else { - all_tableaux_empty = false; - } - - if (adjacent(top_card, hole_card)) { - black_hole_state s = *this; - s.move_to_hole(i); - next.push_back(s); - } - } - - // If there are no cards left in play, deal solved - solved = all_tableaux_empty; - - return next; -} - -void black_hole_state::move_to_hole(int tab_idx) { - hole_card = tableau_piles[tab_idx].back(); - tableau_piles[tab_idx].pop_back(); -} - -bool black_hole_state::is_solved() const { - return solved; -} - -ostream& black_hole_state::print(ostream& stream) const { - return game_state::print(stream) << "Hole: " << hole_card << "\n"; -} - -bool black_hole_state::adjacent(const card& a, const card& b) { - int x = a.get_rank(); - int y = b.get_rank(); - - return x == y + 1 - || x + 1 == y - || x == 1 && y == MAX_RANK - || x == MAX_RANK && y == 1; -} \ No newline at end of file -- cgit v1.2.1