@@ -52,35 +52,63 @@ struct SolverRec {
52
52
static constexpr state value = move(rec1::final_state, SRC, TARGET);
53
53
using rec2 = SolverRec<DISKS - 1 , value, inter, TARGET>;
54
54
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
+ }
55
62
};
56
63
57
64
template <size DISKS, state S, tower TOWER>
58
65
struct SolverRec <DISKS, S, TOWER, TOWER> {
59
66
static constexpr tower nextSrc = getTower(S, DISKS - 1 );
60
67
using rec = SolverRec<DISKS - 1 , S, nextSrc, TOWER>;
61
68
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
+ }
62
74
};
63
75
64
76
template <state S, tower SRC, tower TARGET>
65
77
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
+ }
67
85
};
68
86
69
87
template <state S, tower TOWER>
70
88
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
+ }
72
95
};
73
96
74
97
template <size DISKS, state S, tower TARGET>
75
98
struct Solver {
76
99
static constexpr tower src = getTower(S, DISKS);
77
100
using start = SolverRec<DISKS, S, src, TARGET>;
78
101
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
+ }
79
107
};
80
108
81
109
int main () {
82
110
using disks = Disks<0 , 0 , 0 , 0 , 0 >;
83
111
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) ;
85
113
return 0 ;
86
114
}
0 commit comments