Skip to content

Commit 69b3cf1

Browse files
committed
Print states
1 parent 9d9b733 commit 69b3cf1

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

metahanoi.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,35 +52,63 @@ struct SolverRec {
5252
static constexpr state value = move(rec1::final_state, SRC, TARGET);
5353
using rec2 = SolverRec<DISKS - 1, value, inter, TARGET>;
5454
static constexpr state final_state = rec2::final_state;
55+
56+
static std::ostream &print(std::ostream &os, size ndisks) {
57+
rec1::print(os, ndisks);
58+
print_state(os, ndisks, value) << std::endl;
59+
rec2::print(os, ndisks);
60+
return os;
61+
}
5562
};
5663

5764
template <size DISKS, state S, tower TOWER>
5865
struct SolverRec<DISKS, S, TOWER, TOWER> {
5966
static constexpr tower nextSrc = getTower(S, DISKS - 1);
6067
using rec = SolverRec<DISKS - 1, S, nextSrc, TOWER>;
6168
static constexpr state final_state = rec::final_state;
69+
70+
static std::ostream &print(std::ostream &os, size ndisks) {
71+
rec::print(os, ndisks);
72+
return os;
73+
}
6274
};
6375

6476
template <state S, tower SRC, tower TARGET>
6577
struct SolverRec<1, S, SRC, TARGET> {
66-
static constexpr state final_state = move(S, SRC, TARGET);
78+
static constexpr state value = move(S, SRC, TARGET);
79+
static constexpr state final_state = value;
80+
81+
static std::ostream &print(std::ostream &os, size ndisks) {
82+
print_state(os, ndisks, value) << std::endl;
83+
return os;
84+
}
6785
};
6886

6987
template <state S, tower TOWER>
7088
struct SolverRec<1, S, TOWER, TOWER> {
71-
static constexpr state final_state = S;
89+
static constexpr state value = S;
90+
static constexpr state final_state = value;
91+
92+
static std::ostream &print(std::ostream &os, size ndisks) {
93+
return os;
94+
}
7295
};
7396

7497
template <size DISKS, state S, tower TARGET>
7598
struct Solver {
7699
static constexpr tower src = getTower(S, DISKS);
77100
using start = SolverRec<DISKS, S, src, TARGET>;
78101
static constexpr state final_state = start::final_state;
102+
103+
static std::ostream &print(std::ostream &os) {
104+
print_state(std::cout, DISKS, S) << std::endl; // initial state
105+
return start::print(os, DISKS);
106+
}
79107
};
80108

81109
int main() {
82110
using disks = Disks<0, 0, 0, 0, 0>;
83111
using solver = Solver<disks::count, disks::packed, 2>;
84-
print_state(std::cout, disks::count, solver::final_state) << std::endl;
112+
solver::print(std::cout);
85113
return 0;
86114
}

0 commit comments

Comments
 (0)