aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharlie Blake2018-07-11 12:30:46 +0100
committerCharlie Blake2018-07-11 12:30:46 +0100
commitbb9732850beb1baadf232ae33305ca32090b0c80 (patch)
treed49e933b9cb99dee1d69d6dddf309026cb6375c6 /src
parentAdd random deal for sequences (diff)
downloadmetasol-bb9732850beb1baadf232ae33305ca32090b0c80.tar.gz
metasol-bb9732850beb1baadf232ae33305ca32090b0c80.zip

Add sequence state printing and fix small bugs

Diffstat (limited to 'src')
-rw-r--r--src/main/game/card.cpp1
-rw-r--r--src/main/game/search-state/game_state.cpp30
-rw-r--r--src/main/input-output/output/state_printer.cpp19
-rw-r--r--src/main/input-output/output/state_printer.h3
-rw-r--r--src/main/solver/solver.cpp9
5 files changed, 39 insertions, 23 deletions
diff --git a/src/main/game/card.cpp b/src/main/game/card.cpp
index 60aaa74..1d18029 100644
--- a/src/main/game/card.cpp
+++ b/src/main/game/card.cpp
@@ -83,6 +83,7 @@ card::rank_t card::get_rank() const {
std::string card::to_string() const {
if (face_down) return "##";
+ if (card_rank == 0) return "__";
string s;
switch(card_rank) {
diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp
index fdfb1ce..0139262 100644
--- a/src/main/game/search-state/game_state.cpp
+++ b/src/main/game/search-state/game_state.cpp
@@ -158,6 +158,21 @@ game_state::game_state(const sol_rules& s_rules, int seed, streamliner_options s
}
}
+ // Deals to the sequence piles
+ if (rules.sequence_count > 0) {
+ for (int t = 0; !deck.empty(); t++) {
+ card c = deck.back();
+ if (c.get_rank() == 1) c = card(); // Inserts gaps where aces would be
+
+ // Adds the randomly generated card to the tableau piles
+ auto s = t % sequences.size();
+
+ pile::ref seq_pile = sequences[s];
+ place_card(seq_pile, c);
+ deck.pop_back();
+ }
+ }
+
// This only occurs during testing
if (rules.tableau_pile_count == 0) return;
@@ -195,21 +210,6 @@ game_state::game_state(const sol_rules& s_rules, int seed, streamliner_options s
if (!p.empty())
p[0].turn_face_up();
- // Deals to the sequence piles
- if (rules.sequence_count > 0) {
- for (int t = 0; !deck.empty(); t++) {
- card c = deck.back();
- if (c.get_rank() == 1) c = card(); // Inserts gaps where aces would be
-
- // Adds the randomly generated card to the tableau piles
- auto s = t % sequences.size();
-
- pile::ref seq_pile = sequences[s];
- place_card(seq_pile, c);
- deck.pop_back();
- }
- }
-
// The size of all piles must equal the deck size
int piles_sz = 0;
for (auto& p : piles) piles_sz += p.size();
diff --git a/src/main/input-output/output/state_printer.cpp b/src/main/input-output/output/state_printer.cpp
index 67702e2..f673319 100644
--- a/src/main/input-output/output/state_printer.cpp
+++ b/src/main/input-output/output/state_printer.cpp
@@ -43,6 +43,10 @@ ostream& state_printer::print(ostream& stream, const game_state& gs) {
state_printer::print_header(stream, "Hole Card");
state_printer::print_top_of_pile(stream, gs.hole, gs);
}
+ if (gs.rules.sequence_count > 0) {
+ state_printer::print_header(stream, "Sequences");
+ state_printer::print_sequences(stream, gs.sequences, gs);
+ }
return stream << "===================================";
}
@@ -90,6 +94,21 @@ void state_printer::print_piles(ostream& stream,
}
}
+void state_printer::print_sequences(ostream& stream,
+ const vector<pile::ref>& seq_rs,
+ const game_state& gs) {
+ for (auto s : seq_rs) {
+ stream << "\n";
+ auto& pile = gs.piles[s];
+ for (auto i = pile.size(); i --> 0 ;) {
+ print_card(stream, pile[i]);
+ stream << " ";
+ }
+ stream << "\n";
+ }
+ stream << "\n";
+}
+
void state_printer::print_top_of_piles(ostream& stream,
const vector<pile::ref>& vp,
const game_state& gs) {
diff --git a/src/main/input-output/output/state_printer.h b/src/main/input-output/output/state_printer.h
index 7d4a702..7e01aea 100644
--- a/src/main/input-output/output/state_printer.h
+++ b/src/main/input-output/output/state_printer.h
@@ -19,6 +19,9 @@ private:
static void print_piles(std::ostream&,
const std::vector<pile::ref>&,
const game_state&);
+ static void print_sequences(std::ostream&,
+ const std::vector<pile::ref>&,
+ const game_state&);
static void print_top_of_piles(std::ostream&,
const std::vector<pile::ref>&,
const game_state&);
diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp
index 6b0c980..3bfd6bd 100644
--- a/src/main/solver/solver.cpp
+++ b/src/main/solver/solver.cpp
@@ -58,7 +58,6 @@ solver::sol_state solver::run(boost::optional<atomic<bool> &> terminate_solver)
if (current_node->mv.type == move::mtype::dominance) {
LOG_DEBUG("(dominance move)");
}
- state_printer::print_move(clog, current_node->mv);
LOG_DEBUG(state);
#endif
@@ -137,18 +136,12 @@ bool solver::revert_to_last_node_with_children(optional<lru_cache::item_list::it
if (current_node->mv.type != move::mtype::dominance) {
if (cache.get_states_removed_from_cache() == 0) {
- if (!cache.contains(state)) {
- state_printer::print_move(clog, current_node->mv);
- LOG_DEBUG("-------");
- LOG_DEBUG(state);
- assert(false);
- }
+ assert(cache.contains(state));
}
LOG_DEBUG("(undo move)");
} else {
LOG_DEBUG("(undo dominance move)");
}
- state_printer::print_move(clog, current_node->mv);
LOG_DEBUG(state);
#endif