aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorthecharlesblake2018-04-04 16:00:47 +0100
committerthecharlesblake2018-04-04 16:00:47 +0100
commitec02b3eaf85f222335463b3e2e6790f7e2691047 (patch)
tree2f6a6473993d6df448f16253950f03c9f5c5031b /src/main
parentAdd pile tests (diff)
downloadmetasol-ec02b3eaf85f222335463b3e2e6790f7e2691047.tar.gz
metasol-ec02b3eaf85f222335463b3e2e6790f7e2691047.zip

Add legal move gen tests and refactor

Diffstat (limited to 'src/main')
-rw-r--r--src/main/game/game_state.h3
-rw-r--r--src/main/game/game_state.legal_moves.cpp12
-rw-r--r--src/main/solver/solver.cpp11
3 files changed, 17 insertions, 9 deletions
diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h
index 409fee9..a49db2c 100644
--- a/src/main/game/game_state.h
+++ b/src/main/game/game_state.h
@@ -30,6 +30,7 @@ public:
struct move {
move(pile_ref, pile_ref, pile::size_type = 1);
bool is_dominance() const;
+ friend bool operator==(const move&, const move&);
const static pile::size_type dominance_flag;
pile_ref from; pile_ref to; pile::size_type count;
@@ -51,7 +52,7 @@ public:
std::vector<move> get_legal_moves(
#ifndef NO_CARD_JUST_MOVED
- move
+ move = move(255, 255, 255)
#endif
);
diff --git a/src/main/game/game_state.legal_moves.cpp b/src/main/game/game_state.legal_moves.cpp
index f0502d1..c137b07 100644
--- a/src/main/game/game_state.legal_moves.cpp
+++ b/src/main/game/game_state.legal_moves.cpp
@@ -22,8 +22,10 @@ vector<game_state::move> game_state::get_legal_moves(
vector<move> moves;
// If we have a stock that can deal to the tableau piles, adds this move
- if (rules.stock_deal_t == sdt::TABLEAU_PILES && !piles[stock].empty()) {
- // Only does this if all the tableau piles are empty
+ if (rules.stock_size > 0
+ && rules.stock_deal_t == sdt::TABLEAU_PILES
+ && !piles[stock].empty()) {
+ // Only does this if none of the tableau piles are empty
bool no_tableau_empty = true;
for (auto tab_ref : tableau_piles) {
if (piles[tab_ref].empty()) {
@@ -394,3 +396,9 @@ bool game_state::dominance_blocks_foundation_move(pile_ref target_pile) {
return blocked;
}
+
+bool operator==(const game_state::move& a, const game_state::move& b) {
+ return (a.from == b.from )
+ && (a.to == b.to )
+ && (a.count == b.count);
+}
diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp
index 474800c..2fca763 100644
--- a/src/main/solver/solver.cpp
+++ b/src/main/solver/solver.cpp
@@ -61,14 +61,14 @@ solver::sol_state solver::run_with_cutoff(
if (cutoff_depth && depth >= *cutoff_depth) {
cutoff_triggered = true;
- states_exhausted = revert_to_last_node_with_children();//TODO-
+ states_exhausted = revert_to_last_node_with_children();
} else {
// If there is a dominance move available, adds it to the search tree
// and repeats. Doesn't cache the state.
optional<game_state::move> dominance_move = state.get_dominance_move();
if (dominance_move) {
// Adds the dominance move as a child of the current search node
- add_child(*dominance_move);//TODO+
+ add_child(*dominance_move);
} else {
// Caches the current state
bool is_new_state = cache.insert(state);
@@ -78,14 +78,14 @@ solver::sol_state solver::run_with_cutoff(
// If there are none, reverts to the last node with children
if (next_moves.empty()) {
- states_exhausted = revert_to_last_node_with_children();//TODO-
+ states_exhausted = revert_to_last_node_with_children();
} else {
- add_children(next_moves);//TODO+
+ add_children(next_moves);
}
}
// If the state is not a new one, reverts to the last node with children
else {
- states_exhausted = revert_to_last_node_with_children();//TODO-
+ states_exhausted = revert_to_last_node_with_children();
}
}
}
@@ -175,7 +175,6 @@ void solver::print_solution() const {
if (states_searched > 1) {
while (!n->children.empty()) {
- // TODO print move as well
state_copy.make_move(n->move);
cout << state_copy << "\n";
n = &n->children.back();