|
@@ -10,7 +10,8 @@ Game::Game()
|
|
|
}
|
|
|
// set the state of game [how to move from state to state ("game logic?")]
|
|
|
state = NOT_STARTED;
|
|
|
- // dice have been initialized with random seed
|
|
|
+ // dice have been initialized with random seed, copy this into entropyPool
|
|
|
+ entropyPool = dice.roll();
|
|
|
};
|
|
|
bool Game::addPlayer(std::string name)
|
|
|
{
|
|
@@ -94,7 +95,9 @@ void Game::round()
|
|
|
score();
|
|
|
// go to next player's turn
|
|
|
activePlayer++;
|
|
|
- activePlayer %= players.size();
|
|
|
+ activePlayer %= players.size();
|
|
|
+ // adding in entropy from human players of THIS round to dice so they are slightly more random
|
|
|
+ dice.diceTropy(entropyPool);
|
|
|
}
|
|
|
|
|
|
// generate text: per player(48boxes, penalty count), locked off rows, dice roll, game end(when it occurs) send it
|
|
@@ -131,29 +134,42 @@ std::string Game::send()
|
|
|
// convert a user string into a turn
|
|
|
struct Turn Game::receive(std::string userInput)
|
|
|
{
|
|
|
- players[0].currentTurnOlok.clear();
|
|
|
- Turn turn;
|
|
|
+ Turn turnInProgress;
|
|
|
// userinput is one, add a penalty
|
|
|
if(1 == userInput.size())
|
|
|
{
|
|
|
- turn.penalty = 1;
|
|
|
+ turnInProgress.penalty = 1;
|
|
|
}
|
|
|
// userinput size is two, add one moves
|
|
|
else if(2 == userInput.size())
|
|
|
{
|
|
|
- turn.moves[0] = translateToMove(userInput);
|
|
|
- turn.numberOfMoves = 1;
|
|
|
+ turnInProgress.moves[0] = translateToMove(userInput);
|
|
|
+ turnInProgress.numberOfMoves = 1;
|
|
|
}
|
|
|
// userinput size is four, add two moves
|
|
|
else if(4 == userInput.size())
|
|
|
{
|
|
|
- turn.moves[0] = translateToMove(userInput.substr(0,2));
|
|
|
- turn.moves[1] = translateToMove(userInput.substr(2,2));
|
|
|
- turn.numberOfMoves = 2;
|
|
|
+ turnInProgress.moves[0] = translateToMove(userInput.substr(0,2));
|
|
|
+ turnInProgress.moves[1] = translateToMove(userInput.substr(2,2));
|
|
|
+ turnInProgress.numberOfMoves = 2;
|
|
|
}
|
|
|
else {fprintf(stdout, "Form an opinion: WRONG!");}
|
|
|
// check the rules to make sure turn is valid
|
|
|
- // add turn to currentTurnOlok if the turn is valid
|
|
|
+ if(true == checkTurn(0, turnInProgress))
|
|
|
+ {
|
|
|
+ // currentTurnOlok can only have one valid turn in it at a time
|
|
|
+ players[0].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]);
|
|
|
+ }
|
|
|
+ // player chose to take a penalty
|
|
|
+ players[0].currentTurnOlok.penaltyCount += turnInProgress.penalty;
|
|
|
+ }
|
|
|
+ // adding time to entropyPool to increase entropy in the system
|
|
|
+ entropyPool += time(NULL);
|
|
|
}
|
|
|
|
|
|
bool Game::isMoveRepresentedInDie(int player, Turn turn)
|