|
@@ -17,7 +17,8 @@ bool Game::addPlayer(std::string name)
|
|
|
{
|
|
|
if(NOT_STARTED == state)
|
|
|
{
|
|
|
- ScoreSheet newplayer(name);
|
|
|
+ // add a new player with a name they choose and a secret
|
|
|
+ ScoreSheet newplayer(name, dice.roll());
|
|
|
players.push_back(newplayer);
|
|
|
fprintf (stdout, "added: %s to the game\n", name.c_str());
|
|
|
return true;
|
|
@@ -128,13 +129,44 @@ std::string Game::send()
|
|
|
}
|
|
|
|
|
|
// kyle's intention is to check off red 12 and blue 5
|
|
|
-// " 1143"
|
|
|
+// " kylesecret,1143"
|
|
|
// emma's intention is to take a penalty
|
|
|
-// "1"
|
|
|
+// "emmasecret,1"
|
|
|
// convert a user string into a turn
|
|
|
struct Turn Game::receive(std::string userInput)
|
|
|
{
|
|
|
Turn turnInProgress;
|
|
|
+ std::string playerSecret, original = userInput;
|
|
|
+ int playerNumber = -1, pos = 0;
|
|
|
+ // look for the position of a comma in userInput
|
|
|
+ for(int i = 0;i < userInput.size();i++)
|
|
|
+ {
|
|
|
+ // a comma is found, set position and stop
|
|
|
+ if(',' == userInput[i])
|
|
|
+ {
|
|
|
+ pos = i; break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // assuming there is a comma and it is not the first character, split userInput into two parts on the comma
|
|
|
+ if(0<pos)
|
|
|
+ {
|
|
|
+ playerSecret = userInput.substr(0,pos-1);
|
|
|
+ userInput = userInput.substr(pos);
|
|
|
+ int secret = stoi(playerSecret);
|
|
|
+ // check each player's secret against submitted secret to find player number
|
|
|
+ for(int i = 0;i < players.size(); i++)
|
|
|
+ {
|
|
|
+ if(secret == players[i].secretNumber)
|
|
|
+ {
|
|
|
+ playerNumber = i; break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(-1 == playerNumber)
|
|
|
+ {
|
|
|
+ fprintf(stdout, "Could not find player: %s", original);
|
|
|
+ return turnInProgress;
|
|
|
+ }
|
|
|
// userinput is one, add a penalty
|
|
|
if(1 == userInput.size())
|
|
|
{
|
|
@@ -155,18 +187,18 @@ struct Turn Game::receive(std::string userInput)
|
|
|
}
|
|
|
else {fprintf(stdout, "Form an opinion: WRONG!");}
|
|
|
// check the rules to make sure turn is valid
|
|
|
- if(true == checkTurn(0, turnInProgress))
|
|
|
+ if(true == checkTurn(playerNumber, turnInProgress))
|
|
|
{
|
|
|
// currentTurnOlok can only have one valid turn in it at a time
|
|
|
- players[0].currentTurnOlok.clear();
|
|
|
+ players[playerNumber].currentTurnOlok.clear();
|
|
|
// check the moves in turn
|
|
|
for(int i = 0;i < turnInProgress.numberOfMoves;i++)
|
|
|
{
|
|
|
// add turn to currentTurnOlok
|
|
|
- players[0].currentTurnOlok.addX(turnInProgress.moves[i]);
|
|
|
+ players[playerNumber].currentTurnOlok.addX(turnInProgress.moves[i]);
|
|
|
}
|
|
|
// player chose to take a penalty
|
|
|
- players[0].currentTurnOlok.penaltyCount += turnInProgress.penalty;
|
|
|
+ players[playerNumber].currentTurnOlok.penaltyCount += turnInProgress.penalty;
|
|
|
}
|
|
|
// adding time to entropyPool to increase entropy in the system
|
|
|
entropyPool += time(NULL);
|