|
@@ -1,5 +1,7 @@
|
|
|
#include "game.h"
|
|
|
Game::Game() {
|
|
|
+ // initialize the number of columns that each "color" will contain
|
|
|
+ lastColumnIndex = CHECKBOXES - 1;
|
|
|
// set up lockOut
|
|
|
for(int i = 0; i<white1;i++){
|
|
|
lockOut.push_back(false);
|
|
@@ -31,19 +33,13 @@ void Game::score()
|
|
|
players[i].score = 0;
|
|
|
// calculate penalty amount
|
|
|
players[i].score -= players[i].cumulativeOlok.penaltyCount*PENALTY_VALUE;
|
|
|
- // check each color(row) on ScoreSheet
|
|
|
+ // count the Xs of each "color" and give me a score
|
|
|
for(int j = 0;j <white1;j++)
|
|
|
{
|
|
|
- int count = 0;
|
|
|
- // check each box in row
|
|
|
- for(int k =0;k <CHECKBOXES;k++)
|
|
|
- {
|
|
|
- if(true == players[i].cumulativeOlok.grid[j][k])
|
|
|
- {
|
|
|
- count++;
|
|
|
- }
|
|
|
- }
|
|
|
- players[i].score += pointsGuide[count];
|
|
|
+ // determine if player qualifies for the lockout point (this is a rule)
|
|
|
+ int lockoutPoint = players[i].cumulativeOlok.getLastIndex(j) == lastColumnIndex;
|
|
|
+ // use pointsGuide to get the score for this user's "color" row
|
|
|
+ players[i].score += pointsGuide[players[i].cumulativeOlok.getXCount(j) + lockoutPoint];
|
|
|
}
|
|
|
}
|
|
|
// **CHECK IF GAME IS DONE**
|
|
@@ -87,21 +83,7 @@ void Game::turn(ScoreSheet activePlayer)
|
|
|
// save data from currentTurnOlok into cumulativeOlok
|
|
|
for(int i = 0; i <players.size();i++)
|
|
|
{
|
|
|
- // find changes in currentTurnOlok and transfer to cumulativeOlok
|
|
|
- for(int j = 0;j < players[i].currentTurnOlok.grid.size();j++)
|
|
|
- {
|
|
|
- for(int k = 0;k < players[i].currentTurnOlok.grid[j].size();k++)
|
|
|
- {
|
|
|
- // check for true values in currentTurnOlok's grid
|
|
|
- if(true == players[i].currentTurnOlok.grid[j][k])
|
|
|
- {
|
|
|
- // transfer true values from currentTurnOlok's grid to cumulativeOlok's grid
|
|
|
- players[i].cumulativeOlok.grid[j][k] = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // player selects to add penalty, increase the penalty count
|
|
|
- players[i].cumulativeOlok.penaltyCount += players[i].currentTurnOlok.penaltyCount;
|
|
|
+ players[i].cumulativeOlok.addOlok(players[i].currentTurnOlok);
|
|
|
}
|
|
|
// score the cards
|
|
|
score();
|
|
@@ -120,18 +102,7 @@ std::string Game::send()
|
|
|
// look at each scoresheet
|
|
|
for(int i = 0; i < players.size(); i++)
|
|
|
{
|
|
|
- // check each row on the grid on the scoresheet
|
|
|
- for(int j = 0; j < players[i].cumulativeOlok.grid.size(); j++)
|
|
|
- {
|
|
|
- // check each box on the row and then store output
|
|
|
- for(int k = 0; k < players[i].cumulativeOlok.grid[j].size();k++)
|
|
|
- {
|
|
|
- // look at checkbox value, add it to output
|
|
|
- output.push_back(players[i].cumulativeOlok.grid[j][k] ? 'T' : 'F');
|
|
|
- }
|
|
|
- }
|
|
|
- // add penalty count to output
|
|
|
- output.push_back(players[i].cumulativeOlok.penaltyCount + '0');
|
|
|
+ output.append(players[i].cumulativeOlok.toString());
|
|
|
}
|
|
|
// add locked off row to output
|
|
|
for(int i = 0; i < lockOut.size();i++)
|
|
@@ -160,4 +131,23 @@ void Game::receive(std::string userInput)
|
|
|
|
|
|
// convert userInput into number
|
|
|
// user number to change the boolean on corresponding spot on ScoreSheet
|
|
|
+}
|
|
|
+void Game::addX(int player, int color, int index)
|
|
|
+{
|
|
|
+ // TODO: check that index and color match rolled die
|
|
|
+ // player can add an x to olok in last column if there are 5 x
|
|
|
+ if(lastColumnIndex == index)
|
|
|
+ {
|
|
|
+ if(5 >= players[player].cumulativeOlok.getXCount(color))
|
|
|
+ {
|
|
|
+ players[player].currentTurnOlok.addX(color, index);
|
|
|
+ }
|
|
|
+ else{fprintf(stdout, "Player[%d] %s tried to check off column 12 without minimum X\n", player, players[player].savedName);}
|
|
|
+ }
|
|
|
+ // player can add an x to olok from left to right
|
|
|
+ if(players[player].cumulativeOlok.getLastIndex(color) > index)
|
|
|
+ {
|
|
|
+ fprintf(stdout,"Player[%d] %s not following left to right rule X\n", player, players[player].savedName);
|
|
|
+ }
|
|
|
+ else{players[player].currentTurnOlok.addX(color, index);}
|
|
|
}
|