olok.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "olok.h"
  2. Olok::Olok()
  3. {
  4. clear();
  5. }
  6. void Olok::clear()
  7. {
  8. // clear the grid to be rebuilt as empty
  9. grid.clear();
  10. // make 11 boxes for each colored row (not the white ones)
  11. for(int j = 0; j<white1; j++)
  12. {
  13. RowColor tempRow;
  14. tempRow.color = j;
  15. tempRow.direction = j < (white1/2) ? RIGHT_TO_LEFT : LEFT_TO_RIGHT;
  16. // make 11 numbers for each row based on direction
  17. for (int i = 0; i<CHECKBOXES; i++)
  18. {
  19. tempRow.number.push_back(RIGHT_TO_LEFT == tempRow.direction ? (DICE_SUM_MIN+i) : (DICE_SUM_MAX+i));
  20. }
  21. grid.push_back(tempRow);
  22. for (int i = 0; i<CHECKBOXES; i++)
  23. {
  24. grid[j].row.push_back(false);
  25. }
  26. }
  27. // clear penalty count
  28. penaltyCount = 0;
  29. }
  30. // get checked off box count for a specific color
  31. int Olok::getXCount(int color)
  32. {
  33. for(int i = 0; i < grid.size(); i++)
  34. {
  35. if(color != grid[i].color){continue;}
  36. return grid[i].xCount;
  37. }
  38. return 0;
  39. }
  40. // add checked off box to a specific index on a color
  41. void Olok::addX(struct Move move)
  42. {
  43. int color = move.color, index = move.index;
  44. for(int i = 0; i < grid.size(); i++)
  45. {
  46. if(color != grid[i].color){continue;}
  47. grid[i].row[index] = true;
  48. grid[i].lastIndex = index;
  49. }
  50. }
  51. // check for last value of index
  52. int Olok::getLastIndex(int color)
  53. {
  54. for(int i = 0; i < grid.size(); i++)
  55. {
  56. if(color != grid[i].color){continue;}
  57. return grid[i].lastIndex;
  58. }
  59. return CHECKBOXES;
  60. }
  61. // add any Xs from input Olok into this Olok
  62. void Olok::addOlok(Olok o)
  63. {
  64. // find changes in currentTurnOlok and transfer to cumulativeOlok
  65. for(int j = 0;j <o.grid.size();j++)
  66. {
  67. // loop over all Xs in a color
  68. for(int k = 0;k <o.grid[j].row.size();k++)
  69. {
  70. // check for true values in currentTurnOlok's grid
  71. if(true ==o.grid[j].row[k])
  72. {
  73. // transfer true values from currentTurnOlok's grid to cumulativeOlok's grid
  74. grid[j].row[k] = true;
  75. }
  76. }
  77. }
  78. // player selects to add penalty, increase the penalty count
  79. penaltyCount += o.penaltyCount;
  80. }
  81. std::string Olok::toString(void)
  82. {
  83. std::string output;
  84. // check each row on the grid on the scoresheet
  85. for(int j = 0; j < grid.size(); j++)
  86. {
  87. // check each box on the row and then store output
  88. for(int k = 0; k < grid[j].row.size();k++)
  89. {
  90. // look at checkbox value, add it to output
  91. output.push_back(grid[j].row[k] ? 'T' : 'F');
  92. }
  93. }
  94. // add penalty count to output
  95. output.push_back(penaltyCount + '0');
  96. return output;
  97. }
  98. // check to see if color matches one of the RowColor(s) on grid
  99. boolean Olok::isColor(int color)
  100. {
  101. for(int i = 0; i < grid.size(); i++)
  102. {
  103. if(color != grid[i].color){continue;}
  104. return true;
  105. }
  106. return false;
  107. }