// Saint Bonaventure University Programming Contest // February 15, 2008 // Problem #2 - Land of Sweets // Team Name: SOLUTION #include "apstring.h" #include "apvector.h" #include "CandyGame.h" #include void takeTurn(CandyGame & cg, apvector & players, int who); void moveForward(CandyGame & cg, apvector & players, int who, const apstring & myCard); bool isColor(const apstring & c); int main(void) { int numPlayers; apstring seed; cin >> numPlayers >> seed; CandyGame cg(seed); // cg.printBoard(); // cg.printDeck(); apvector players(numPlayers); for (int i=0; i= cg.boardSize()-1) break; whichPlayer = (whichPlayer+1) % numPlayers; } if (turn == numPlayers*50) cout << "No one wins." << endl; else cout << "Player " << (whichPlayer+1) << " wins." << endl; } void takeTurn(CandyGame & cg, apvector & players, int who) { apstring myCard = cg.nextCard(); // cout << "Player " << (who+1) << " draws a " << myCard << "."; bool twoColors = false; if (myCard[0] == 'd') { twoColors = true; myCard = myCard.substr(7, myCard.length()); } if (isColor(myCard)) { moveForward(cg, players, who, myCard); if (twoColors) moveForward(cg, players, who, myCard); } else players[who] = cg.findSquare(myCard, 0); // cout << "and advances to (" << players[who] << ")" << endl; } void moveForward(CandyGame & cg, apvector & players, int who, const apstring & myCard) { int pos; pos = cg.findSquare(myCard, players[who]); if (pos == -1) players[who] = cg.boardSize()+1; else players[who] = pos; } bool isColor(const apstring & c) { return (c == "red") || (c == "yellow") || (c == "blue") || (c == "green") || (c == "orange") || (c == "purple"); }