#include using namespace std; class Move { public: Move(int sh, int sc, int th, int tc) ; int getSource() const; int getSourceCoins() const; int getTarget() const; int getTargetCoins() const; friend ostream & operator << (ostream &out, const Move &move); int a; int b; int c; int d; }; Move::Move(int sh, int sc, int th, int tc) { a=sh; b=sc; c=th; d=tc; } int Move::getSource() const {return a;} int Move::getSourceCoins() const {return b;} int Move::getTarget() const {return c;} int Move::getTargetCoins() const {return d;} ostream & operator << (ostream &out, const Move &move) { out<<"takes "<0) out<=heapsum || move.c<0 || move.c>=heapsum)throw logic_error("invalid heap"); else if(move.b<=0 || move.d<0 || heap[move.a]=move.b) throw logic_error("invalid coin quantity"); else { heap[move.a]-=move.b; heap[move.c]+=move.d; } } bool State::winning() const { bool win=true; for(int i=0; i=heapsum) throw logic_error("invalid heap"); else return heap[h]; } ostream & operator << (ostream &out, const State &state) { out << state.heap[0]; for (int i = 1; i < state.heapsum; i++) out << ", " << state.heap[i]; return out; }