/* Mankala. Wednesday, October 28, 2007. Stephen Clement */ #include #include void displayboard(const vector &mankalaboard) /* Prereq: a mankala board! Must be of size 14. * Postreq: board is displayed. */ { cout << " " << mankalaboard[12] << " " << mankalaboard[11] << " " << mankalaboard[10] << " " << mankalaboard[9] << " " << mankalaboard[8] << " " << mankalaboard[7] << endl; cout << mankalaboard[13] << " " << mankalaboard[6] << endl; cout << " " << mankalaboard[0] << " " << mankalaboard[1] << " " << mankalaboard[2] << " " << mankalaboard[3] << " " << mankalaboard[4] << " " << mankalaboard[5] << endl; cout << " " << "A B C D E F" << endl; } int getinput(const vector &mankalaboard) { int locationtomove; char chartomove; do { cout << "Which pit of pieces would you like to move (A-F)? "; cin >> chartomove; if (chartomove < 'A' && chartomove > 'F') { cout << "Input not in the range A-F. Try again." << endl; } locationtomove = (int('F')-int(chartomove)); if (mankalaboard[locationtomove] == 0) { cout << "Sorry, no pieces exist at that location. Try another spot." << endl; } } while (chartomove < 'A' && chartomove > 'F'); return(locationtomove); } void makemove(vector &mankalaboard, const int &locationtomove, bool &anothermove) { int destination = (locationtomove+1); for (int i = mankalaboard[locationtomove]; i > 0; i--) { mankalaboard[destination]++; destination++; if (destination = 14) { destination = 0; } } // now do they get another turn? should any other pieces be moved? if ((destination < 6) && (mankalaboard[destination] == 1)) { // FIXME! } if ((player == 1 && destination == 6) || (player == 2 && destination == 13)) { anothermove = true; } else { anothermove = false; } } bool checkgameover(const vector &mankalaboard) { return(false); } int main() { // set variables const int startingstones = 3; vector mankalaboard(14); char playagain; bool gameover, anothermove; int player; int locationtomove; // INSERT INSTRUCTIONS HERE! do { // initialization: for (int i = 0; i < mankalaboard.length(); i++) { mankalaboard[i] = startingstones; } mankalaboard[6] = 0; mankalaboard[13] = 0; player = 1; gameover = false; do { // implement multiple players! do { displayboard(mankalaboard); locationtomove = getinput(mankalaboard); makemove(mankalaboard, locationtomove, anothermove); if (anothermove == true) { cout << "You get to make another move." << endl; } while (anothermove == false); gameover = checkgameover(mankalaboard); } while (gameover == false); if (mankalaboard[6] > mankalaboard[13]) { cout << "Player 1 wins!"; } else if (mankalaboard[13] > mankalaboard[6]) { cout << "Player 2 wins!"; } else { cout << "Tie!"; } cout << endl << endl; cout << "Play again (Y/N)? "; cin >> playagain; } while (playagain == 'Y' || playagain == 'y'); cout << "Thanks for playing!" << endl; return(0); }