#include #include #include struct stack_item { int from; int to; int remove; }; stack_item stack[13]; int start; int board[16] = { 1, 1,1, 1,1,1, 1,1,1,1, 1,1,1,1,1}; int Start() { int pos; cout << "Where's the blank at? (1-15) : "; cin >> pos; return pos-1; } void Menu(int& from, int& to) { cout << setiosflags (ios::right) << setw(19) << board[0] << endl; cout << setw(18) << board[1] << ' ' << board[2] << endl; cout << setw(17) << board[3] << ' ' << board[4] << ' ' << board[5] << endl; cout << setw(16) << board[6] << ' ' << board[7] << ' ' << board[8] << ' ' << board[9] << endl; cout << setw(15) << board[10] << ' ' << board[11] << ' ' << board[12] << ' ' << board[13] << ' ' << board[14] << endl << endl; cout << "Move from (1 - 15, 0 to quit, -1 to backup) : "; cin >> from; if (from != 0 && from != -1) { cout << "Move to (1 - 15) : "; cin >> to; } } void Score(int pegs,int moves) { cout << pegs << " pegs left. "; switch (pegs) { case 1 : {cout << "Excellent! You solved the puzzle!\n"; ofstream fout("winners", ios::app); cout << "Enter your name : "; char name[80]; cin.ignore (80,'\n'); cin.getline (name,80,'\n'); fout << name << endl; fout << "Blank was initially at : " << stack[0].to+1 << endl; int i; for (i=0; i 1) { Menu(from, to); if (from == 0) { Score(pegs, moves); exit(1); } if (from == -1) backup(moves,pegs); else if (Check_Move(from, to, remove)) Make_Move(from, to,remove,moves,pegs); else cout << "Invalid move!\n"; } Score(pegs, moves); }