Permalink
Browse files

Print states

  • Loading branch information...
rom1v committed Mar 27, 2015
1 parent 9d9b733 commit 69b3cf1202c634dc788ba1c694f4a6f3d3064b92
Showing with 31 additions and 3 deletions.
  1. +31 −3 metahanoi.cpp
@@ -52,35 +52,63 @@ struct SolverRec {
static constexpr state value = move(rec1::final_state, SRC, TARGET);
using rec2 = SolverRec<DISKS - 1, value, inter, TARGET>;
static constexpr state final_state = rec2::final_state;

static std::ostream &print(std::ostream &os, size ndisks) {
rec1::print(os, ndisks);
print_state(os, ndisks, value) << std::endl;
rec2::print(os, ndisks);
return os;
}
};

template <size DISKS, state S, tower TOWER>
struct SolverRec<DISKS, S, TOWER, TOWER> {
static constexpr tower nextSrc = getTower(S, DISKS - 1);
using rec = SolverRec<DISKS - 1, S, nextSrc, TOWER>;
static constexpr state final_state = rec::final_state;

static std::ostream &print(std::ostream &os, size ndisks) {
rec::print(os, ndisks);
return os;
}
};

template <state S, tower SRC, tower TARGET>
struct SolverRec<1, S, SRC, TARGET> {
static constexpr state final_state = move(S, SRC, TARGET);
static constexpr state value = move(S, SRC, TARGET);
static constexpr state final_state = value;

static std::ostream &print(std::ostream &os, size ndisks) {
print_state(os, ndisks, value) << std::endl;
return os;
}
};

template <state S, tower TOWER>
struct SolverRec<1, S, TOWER, TOWER> {
static constexpr state final_state = S;
static constexpr state value = S;
static constexpr state final_state = value;

static std::ostream &print(std::ostream &os, size ndisks) {
return os;
}
};

template <size DISKS, state S, tower TARGET>
struct Solver {
static constexpr tower src = getTower(S, DISKS);
using start = SolverRec<DISKS, S, src, TARGET>;
static constexpr state final_state = start::final_state;

static std::ostream &print(std::ostream &os) {
print_state(std::cout, DISKS, S) << std::endl; // initial state
return start::print(os, DISKS);
}
};

int main() {
using disks = Disks<0, 0, 0, 0, 0>;
using solver = Solver<disks::count, disks::packed, 2>;
print_state(std::cout, disks::count, solver::final_state) << std::endl;
solver::print(std::cout);
return 0;
}

0 comments on commit 69b3cf1

Please sign in to comment.