nitrodog96

yahtzee wip

Sep 11th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 38.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <sstream>
  6.  
  7. int countChar(std::string s, char c)
  8. {
  9.     int count = 0;
  10.     for(unsigned i = 0; i < s.size(); i++)
  11.     {
  12.         if(s[i] == c)
  13.         {
  14.             count++;
  15.         }
  16.     }
  17.     return count;
  18. }
  19.  
  20. int main() {
  21.     srand((unsigned) time(0));
  22.     bool upSecOccupied[6] = {false, false, false, false, false,
  23.                              false}; //aces twos threes fours fives sixes; 35 bonus if 63+
  24.     bool loSecOccupied[7] = {false, false, false, false, false, false,
  25.                              false}; //3kind 4kind fullhouse smstr lgstr yahtzee chance
  26.     int upSecScore[6] = {};
  27.     int loSecScore[7] = {};
  28.     int yahtzeeCount = 0;
  29.  
  30.     std::string keptDice;
  31.     int numDiceKept = 0;
  32.  
  33.     int firstRoll;
  34.     int seconRoll;
  35.     int thirdRoll;
  36.     int fourtRoll;
  37.     int fifthRoll;
  38.  
  39.     std::string scoreSection;
  40.     bool upSecCanScore[6] = {false, false, false, false, false, false};
  41.     bool loSecCanScore[7] = {false, false, false, false, false, false, false};
  42.  
  43.     std::string output = "You rolled: ";
  44.  
  45.     for (int i = 1; i <= 13; i++) //i = turn number
  46.     {
  47.         keptDice = "";
  48.         numDiceKept = 0;
  49.         firstRoll = 0;
  50.         seconRoll = 0;
  51.         thirdRoll = 0;
  52.         fourtRoll = 0;
  53.         fifthRoll = 0;
  54.  
  55.         for(int index = 0; index < 7; index++)
  56.         {
  57.             if(index < 6)
  58.             {
  59.                 upSecCanScore[index] = false;
  60.             }
  61.             loSecCanScore[index] = false;
  62.         }
  63.  
  64.         std::cout << "Starting a new turn." << std::endl;
  65.         for (int j = 1; j <= 3; j++) //j = number of rolls
  66.         {
  67.             output = "You rolled: ";
  68.             if(numDiceKept < 5)
  69.             {
  70.                 numDiceKept = 0;
  71.                 std::cout << std::to_string(i) + "-" + std::to_string(j) << std::endl;
  72.                 std::string diceToKeep;
  73.  
  74.                 if (countChar(keptDice, '1') == 0) {
  75.                     firstRoll = rand() % 6 + 1;
  76.                 }
  77.                 if (countChar(keptDice, '2') == 0) {
  78.                     seconRoll = rand() % 6 + 1;
  79.                 }
  80.                 if (countChar(keptDice, '3') == 0) {
  81.                     thirdRoll = rand() % 6 + 1;
  82.                 }
  83.                 if (countChar(keptDice, '4') == 0) {
  84.                     fourtRoll = rand() % 6 + 1;
  85.                 }
  86.                 if (countChar(keptDice, '5') == 0) {
  87.                     fifthRoll = rand() % 6 + 1;
  88.                 }
  89.  
  90.                 output += std::to_string(firstRoll);
  91.                 output += ", ";
  92.                 output += std::to_string(seconRoll);
  93.                 output += ", ";
  94.                 output += std::to_string(thirdRoll);
  95.                 output += ", ";
  96.                 output += std::to_string(fourtRoll);
  97.                 output += ", ";
  98.                 output += std::to_string(fifthRoll);
  99.                 output += ".";
  100.                 std::cout << output << std::endl;
  101.  
  102.                 if (j < 3) {
  103.                     std::cout << "Please input the numerical positions (1 to 5) of the dice you would like to keep." << std::endl;
  104.                     std::cout << "If you would not like to keep any, please input a dash." << std::endl;
  105.                     std::cin >> diceToKeep;
  106.                     bool keepFirst = (countChar(diceToKeep, '1') != 0);
  107.                     bool keepSecon = (countChar(diceToKeep, '2') != 0);
  108.                     bool keepThird = (countChar(diceToKeep, '3') != 0);
  109.                     bool keepFourt = (countChar(diceToKeep, '4') != 0);
  110.                     bool keepFifth = (countChar(diceToKeep, '5') != 0);
  111.  
  112.                     if(keepFirst)
  113.                     {
  114.                         keptDice += "1";
  115.                         numDiceKept++;
  116.                     }
  117.                     if(keepSecon)
  118.                     {
  119.                         keptDice += "2";
  120.                         numDiceKept++;
  121.                     }
  122.                     if(keepThird)
  123.                     {
  124.                         keptDice += "3";
  125.                         numDiceKept++;
  126.                     }
  127.                     if(keepFourt)
  128.                     {
  129.                         keptDice += "4";
  130.                         numDiceKept++;
  131.                     }
  132.                     if(keepFifth)
  133.                     {
  134.                         keptDice += "5";
  135.                         numDiceKept++;
  136.                     }
  137.                 }
  138.             }
  139.         }
  140.  
  141.         std::cout << "Pick a section to score in. Sections that you cannot score in will not be displayed." << std::endl;
  142.         if (!upSecOccupied[0]) {
  143.             upSecCanScore[0] = true;
  144.             std::cout << "Aces: One pt per \"1\" rolled." << std::endl;
  145.         }
  146.         if (!upSecOccupied[1]) {
  147.             upSecCanScore[1] = true;
  148.             std::cout << "Twos: Two pts per \"2\" rolled." << std::endl;
  149.         }
  150.         if (!upSecOccupied[2]) {
  151.             upSecCanScore[2] = true;
  152.             std::cout << "Threes: Three pts per \"3\" rolled." << std::endl;
  153.         }
  154.         if (!upSecOccupied[3]) {
  155.             upSecCanScore[3] = true;
  156.             std::cout << "Fours: Four pts per \"4\" rolled." << std::endl;
  157.         }
  158.         if (!upSecOccupied[4]) {
  159.             upSecCanScore[4] = true;
  160.             std::cout << "Fives: Five pts per \"5\" rolled." << std::endl;
  161.         }
  162.         if (!upSecOccupied[5]) {
  163.             upSecCanScore[5] = true;
  164.             std::cout << "Sixes: Six pts per \"6\" rolled." << std::endl;
  165.         }
  166.  
  167.         if((countChar(output, '1') >= 3 ||
  168.             countChar(output, '2') >= 3 ||
  169.             countChar(output, '3') >= 3 ||
  170.             countChar(output, '4') >= 3 ||
  171.             countChar(output, '5') >= 3 ||
  172.             countChar(output, '6') >= 3) &&
  173.            !loSecOccupied[0])
  174.         {
  175.             loSecCanScore[0] = true;
  176.             std::cout << "Three-of-a-kind: Add total of all dice." << std::endl;
  177.         }
  178.  
  179.         if((countChar(output, '1') >= 4 ||
  180.             countChar(output, '2') >= 4 ||
  181.             countChar(output, '3') >= 4 ||
  182.             countChar(output, '4') >= 4 ||
  183.             countChar(output, '5') >= 4 ||
  184.             countChar(output, '6') >= 4) &&
  185.            !loSecOccupied[1])
  186.         {
  187.             loSecCanScore[1] = true;
  188.             std::cout << "Four-of-a-kind: Add total of all dice." << std::endl;
  189.         }
  190.  
  191.         if(!loSecOccupied[2]) {
  192.             if(countChar(output, '1') == 3)
  193.             {
  194.                 if (//countChar(output, '1') == 2 ||
  195.                         countChar(output, '2') == 2 ||
  196.                         countChar(output, '3') == 2 ||
  197.                         countChar(output, '4') == 2 ||
  198.                         countChar(output, '5') == 2 ||
  199.                         countChar(output, '6') == 2) {
  200.                     loSecCanScore[2] = true;
  201.                     std::cout << "Full-House: 25 pts." << std::endl;
  202.                 }
  203.             }
  204.             else if(countChar(output, '2') == 3)
  205.             {
  206.                 if(countChar(output, '1') == 2 ||
  207.                    //countChar(output, '2') == 2 ||
  208.                    countChar(output, '3') == 2 ||
  209.                    countChar(output, '4') == 2 ||
  210.                    countChar(output, '5') == 2 ||
  211.                    countChar(output, '6') == 2)
  212.                 {
  213.                     loSecCanScore[2] = true;
  214.                     std::cout << "Full-House: 25 pts." << std::endl;
  215.                 }
  216.             }
  217.             else if(countChar(output, '3') == 3)
  218.             {
  219.                 if(countChar(output, '1') == 2 ||
  220.                    countChar(output, '2') == 2 ||
  221.                    //countChar(output, '3') == 2 ||
  222.                    countChar(output, '4') == 2 ||
  223.                    countChar(output, '5') == 2 ||
  224.                    countChar(output, '6') == 2)
  225.                 {
  226.                     loSecCanScore[2] = true;
  227.                     std::cout << "Full-House: 25 pts." << std::endl;
  228.                 }
  229.             }
  230.             else if(countChar(output, '4') == 3)
  231.             {
  232.                 if(countChar(output, '1') == 2 ||
  233.                    countChar(output, '2') == 2 ||
  234.                    countChar(output, '3') == 2 ||
  235.                    //countChar(output, '4') == 2 ||
  236.                    countChar(output, '5') == 2 ||
  237.                    countChar(output, '6') == 2)
  238.                 {
  239.                     loSecCanScore[2] = true;
  240.                     std::cout << "Full-House: 25 pts." << std::endl;
  241.                 }
  242.             }
  243.             else if(countChar(output, '5') == 3)
  244.             {
  245.                 if(countChar(output, '1') == 2 ||
  246.                    countChar(output, '2') == 2 ||
  247.                    countChar(output, '3') == 2 ||
  248.                    countChar(output, '4') == 2 ||
  249.                    //countChar(output, '5') == 2 ||
  250.                    countChar(output, '6') == 2)
  251.                 {
  252.                     loSecCanScore[2] = true;
  253.                     std::cout << "Full-House: 25 pts." << std::endl;
  254.                 }
  255.             }
  256.             else if (countChar(output, '6') == 3)
  257.             {
  258.                 if(countChar(output, '1') == 2 ||
  259.                    countChar(output, '2') == 2 ||
  260.                    countChar(output, '3') == 2 ||
  261.                    countChar(output, '4') == 2 ||
  262.                    countChar(output, '5') == 2)
  263.                     //countChar(output, '6') == 2)
  264.                 {
  265.                     loSecCanScore[2] = true;
  266.                     std::cout << "Full-House: 25 pts." << std::endl;
  267.                 }
  268.             }
  269.         }
  270.         //sm str
  271.         if(!loSecOccupied[3])
  272.         {
  273.             bool oneToFou = countChar(output, '1') >= 1 && countChar(output, '2') >= 1 && countChar(output, '3') >= 1 && countChar(output, '4') >= 1;
  274.             bool twoToFiv = countChar(output, '2') >= 1 && countChar(output, '3') >= 1 && countChar(output, '4') >= 1 && countChar(output, '5') >= 1;
  275.             bool thrToSix = countChar(output, '3') >= 1 && countChar(output, '4') >= 1 && countChar(output, '5') >= 1 && countChar(output, '6') >= 1;
  276.             if(oneToFou || twoToFiv || thrToSix)
  277.             {
  278.                 loSecCanScore[3] = true;
  279.                 std::cout << "Small-Straight: 30 pts." << std::endl;
  280.             }
  281.         }
  282.         //lg str
  283.         if(!loSecOccupied[4])
  284.         {
  285.             bool oneToFiv = countChar(output, '1') == 1 && countChar(output, '2') == 1 && countChar(output, '3') == 1 && countChar(output, '4') == 1 && countChar(output, '5') == 1;
  286.             bool twoToSix = countChar(output, '2') == 1 && countChar(output, '3') == 1 && countChar(output, '4') == 1 && countChar(output, '5') == 1 && countChar(output, '6') == 1;
  287.             if(oneToFiv || twoToSix)
  288.             {
  289.                 loSecCanScore[4] = true;
  290.                 std::cout << "Large-Straight: 40 pts." << std::endl;
  291.             }
  292.         }
  293.  
  294.         if(countChar(output, '1') == 5 ||
  295.            countChar(output, '2') == 5 ||
  296.            countChar(output, '3') == 5 ||
  297.            countChar(output, '4') == 5 ||
  298.            countChar(output, '5') == 5 ||
  299.            countChar(output, '6') == 5)
  300.         {
  301.             if(loSecOccupied[5])
  302.             {
  303.                 //bonus yahtzee
  304.             }
  305.             else
  306.             {
  307.                 loSecCanScore[5] = true;
  308.                 std::cout << "Yahtzee: 50 pts." << std::endl;
  309.             }
  310.         }
  311.  
  312.         //chance
  313.         if(!loSecOccupied[6])
  314.         {
  315.             loSecCanScore[6] = true;
  316.             std::cout << "Chance: Score total of all five dice." << std::endl;
  317.         }
  318.         //pick their section to score
  319.         if((!upSecCanScore[0] && !upSecCanScore[1] && !upSecCanScore[2] && !upSecCanScore[3] && !upSecCanScore[4] && !upSecCanScore[5]) &&
  320.            (!loSecCanScore[0] && !loSecCanScore[1] && !loSecCanScore[2] && !loSecCanScore[3] && !loSecCanScore[4] && !loSecCanScore[5] && !loSecCanScore[6]))
  321.         {
  322.             //check bonus yahtzees
  323.             //pick one to blank out
  324.  
  325.             std::string blankOutput = "Choose one of the following to blank out for zero points:";
  326.             std::string blankInput;
  327.  
  328.             if(!upSecOccupied[0])
  329.             {
  330.                 blankOutput += "Aces, ";
  331.             }
  332.             if(!upSecOccupied[1])
  333.             {
  334.                 blankOutput += "Twos, ";
  335.             }
  336.             if(!upSecOccupied[2])
  337.             {
  338.                 blankOutput += "Threes, ";
  339.             }
  340.             if(!upSecOccupied[3])
  341.             {
  342.                 blankOutput += "Fours, ";
  343.             }
  344.             if(!upSecOccupied[4])
  345.             {
  346.                 blankOutput += "Fives, ";
  347.             }
  348.             if(!upSecOccupied[5])
  349.             {
  350.                 blankOutput += "Sixes, ";
  351.             }
  352.             if(!loSecOccupied[0])
  353.             {
  354.                 blankOutput += "Three-of-a-Kind, ";
  355.             }
  356.             if(!loSecOccupied[1])
  357.             {
  358.                 blankOutput += "Four-of-a-Kind, ";
  359.             }
  360.             if(!loSecOccupied[2])
  361.             {
  362.                 blankOutput += "Full House, ";
  363.             }
  364.             if(!loSecOccupied[3])
  365.             {
  366.                 blankOutput += "Small-Straight, ";
  367.             }
  368.             if(!loSecOccupied[4])
  369.             {
  370.                 blankOutput += "Large-Straight, ";
  371.             }
  372.             if(!loSecOccupied[5])
  373.             {
  374.                 blankOutput += "Yahtzee, ";
  375.             }
  376.             if(!loSecOccupied[6])
  377.             {
  378.                 blankOutput += "Chance";
  379.             }
  380.  
  381.             std::cout << blankOutput << std::endl;
  382.             std::cin >> blankInput;
  383.  
  384.             bool validChoice = !((((upSecCanScore[0] && scoreSection == "Aces") ||
  385.                                    (upSecCanScore[1] && scoreSection == "Twos") ||
  386.                                    (upSecCanScore[2] && scoreSection == "Threes") ||
  387.                                    (upSecCanScore[3] && scoreSection == "Fours") ||
  388.                                    (upSecCanScore[4] && scoreSection == "Fives") ||
  389.                                    (upSecCanScore[5] && scoreSection == "Sixes")) ||
  390.                                   ((loSecCanScore[0] && scoreSection == "Three-of-a-Kind") ||
  391.                                    (loSecCanScore[1] && scoreSection == "Four-of-a-Kind") ||
  392.                                    (loSecCanScore[2] && scoreSection == "Full-House") ||
  393.                                    (loSecCanScore[3] && scoreSection == "Small-Straight") ||
  394.                                    (loSecCanScore[4] && scoreSection == "Large-Straight") ||
  395.                                    (loSecCanScore[5] && scoreSection == "Yahtzee") ||
  396.                                    (loSecCanScore[6] && scoreSection == "Chance"))) ||
  397.                                    (scoreSection != "Aces" &&
  398.                                     scoreSection != "Twos" &&
  399.                                     scoreSection != "Threes" &&
  400.                                     scoreSection != "Fours" &&
  401.                                     scoreSection != "Fives" &&
  402.                                     scoreSection != "Sixes" &&
  403.                                     scoreSection != "Three-of-a-Kind" &&
  404.                                     scoreSection != "Four-of-a-Kind" &&
  405.                                     scoreSection != "Full-House" &&
  406.                                     scoreSection != "Small-Straight" &&
  407.                                     scoreSection != "Large-Straight" &&
  408.                                     scoreSection != "Yahtzee" &&
  409.                                     scoreSection != "Chance"));
  410.  
  411.             while(!validChoice)
  412.             {
  413.                 std::cout << "Your choice was invalid. Try again." << std::endl;
  414.                 blankOutput = "Choose one of the following to blank out for zero points: ";
  415.  
  416.                 if(!upSecOccupied[0])
  417.                 {
  418.                     blankOutput += "Aces, ";
  419.                 }
  420.                 if(!upSecOccupied[1])
  421.                 {
  422.                     blankOutput += "Twos, ";
  423.                 }
  424.                 if(!upSecOccupied[2])
  425.                 {
  426.                     blankOutput += "Threes, ";
  427.                 }
  428.                 if(!upSecOccupied[3])
  429.                 {
  430.                     blankOutput += "Fours, ";
  431.                 }
  432.                 if(!upSecOccupied[4])
  433.                 {
  434.                     blankOutput += "Fives, ";
  435.                 }
  436.                 if(!upSecOccupied[5])
  437.                 {
  438.                     blankOutput += "Sixes, ";
  439.                 }
  440.                 if(!loSecOccupied[0])
  441.                 {
  442.                     blankOutput += "Three-of-a-Kind, ";
  443.                 }
  444.                 if(!loSecOccupied[1])
  445.                 {
  446.                     blankOutput += "Four-of-a-Kind, ";
  447.                 }
  448.                 if(!loSecOccupied[2])
  449.                 {
  450.                     blankOutput += "Full House, ";
  451.                 }
  452.                 if(!loSecOccupied[3])
  453.                 {
  454.                     blankOutput += "Small-Straight, ";
  455.                 }
  456.                 if(!loSecOccupied[4])
  457.                 {
  458.                     blankOutput += "Large-Straight, ";
  459.                 }
  460.                 if(!loSecOccupied[5])
  461.                 {
  462.                     blankOutput += "Yahtzee, ";
  463.                 }
  464.                 if(!loSecOccupied[6])
  465.                 {
  466.                     blankOutput += "Chance";
  467.                 }
  468.  
  469.                 std::cout << blankOutput << std::endl;
  470.                 std::cin >> blankInput;
  471.  
  472.                 validChoice = !((((upSecCanScore[0] && scoreSection == "Aces") ||
  473.                                        (upSecCanScore[1] && scoreSection == "Twos") ||
  474.                                        (upSecCanScore[2] && scoreSection == "Threes") ||
  475.                                        (upSecCanScore[3] && scoreSection == "Fours") ||
  476.                                        (upSecCanScore[4] && scoreSection == "Fives") ||
  477.                                        (upSecCanScore[5] && scoreSection == "Sixes")) ||
  478.                                       ((loSecCanScore[0] && scoreSection == "Three-of-a-Kind") ||
  479.                                        (loSecCanScore[1] && scoreSection == "Four-of-a-Kind") ||
  480.                                        (loSecCanScore[2] && scoreSection == "Full-House") ||
  481.                                        (loSecCanScore[3] && scoreSection == "Small-Straight") ||
  482.                                        (loSecCanScore[4] && scoreSection == "Large-Straight") ||
  483.                                        (loSecCanScore[5] && scoreSection == "Yahtzee") ||
  484.                                        (loSecCanScore[6] && scoreSection == "Chance"))) ||
  485.                                      (scoreSection != "Aces" &&
  486.                                       scoreSection != "Twos" &&
  487.                                       scoreSection != "Threes" &&
  488.                                       scoreSection != "Fours" &&
  489.                                       scoreSection != "Fives" &&
  490.                                       scoreSection != "Sixes" &&
  491.                                       scoreSection != "Three-of-a-Kind" &&
  492.                                       scoreSection != "Four-of-a-Kind" &&
  493.                                       scoreSection != "Full-House" &&
  494.                                       scoreSection != "Small-Straight" &&
  495.                                       scoreSection != "Large-Straight" &&
  496.                                       scoreSection != "Yahtzee" &&
  497.                                       scoreSection != "Chance"));
  498.             }
  499.  
  500.             std::cout << blankInput << std::endl;
  501.  
  502.             if(blankInput == "Aces")
  503.             {
  504.                 upSecOccupied[0] = true;
  505.                 upSecScore[0] = 0;
  506.             }
  507.             if(blankInput == "Twos")
  508.             {
  509.                 upSecOccupied[1] = true;
  510.                 upSecScore[1] = 0;
  511.             }
  512.             if(blankInput == "Thres")
  513.             {
  514.                 upSecOccupied[2] = true;
  515.                 upSecScore[2] = 0;
  516.             }
  517.             if(blankInput == "Fours")
  518.             {
  519.                 upSecOccupied[3] = true;
  520.                 upSecScore[3] = 0;
  521.             }
  522.             if(blankInput == "Fives")
  523.             {
  524.                 upSecOccupied[4] = true;
  525.                 upSecScore[4] = 0;
  526.             }
  527.             if(blankInput == "Sixes")
  528.             {
  529.                 upSecOccupied[5] = true;
  530.                 upSecScore[5] = 0;
  531.             }
  532.         }
  533.         else
  534.         {
  535.             std::cout << "Choose one of the above options, without spaces." << std::endl;
  536.             std::cin >> scoreSection;
  537.             //This works, don't look at it for too long.
  538.             bool validChoice = !((((!upSecCanScore[0] && scoreSection == "Aces") ||
  539.                                    (!upSecCanScore[1] && scoreSection == "Twos") ||
  540.                                    (!upSecCanScore[2] && scoreSection == "Threes") ||
  541.                                    (!upSecCanScore[3] && scoreSection == "Fours") ||
  542.                                    (!upSecCanScore[4] && scoreSection == "Fives") ||
  543.                                    (!upSecCanScore[5] && scoreSection == "Sixes")) ||
  544.                                   ((!loSecCanScore[0] && scoreSection == "Three-of-a-Kind") ||
  545.                                    (!loSecCanScore[1] && scoreSection == "Four-of-a-Kind") ||
  546.                                    (!loSecCanScore[2] && scoreSection == "Full-House") ||
  547.                                    (!loSecCanScore[3] && scoreSection == "Small-Straight") ||
  548.                                    (!loSecCanScore[4] && scoreSection == "Large-Straight") ||
  549.                                    (!loSecCanScore[5] && scoreSection == "Yahtzee") ||
  550.                                    (!loSecCanScore[6] && scoreSection == "Chance"))) ||
  551.                                  (scoreSection != "Aces" &&
  552.                                   scoreSection != "Twos" &&
  553.                                   scoreSection != "Threes" &&
  554.                                   scoreSection != "Fours" &&
  555.                                   scoreSection != "Fives" &&
  556.                                   scoreSection != "Sixes" &&
  557.                                   scoreSection != "Three-of-a-Kind" &&
  558.                                   scoreSection != "Four-of-a-Kind" &&
  559.                                   scoreSection != "Full-House" &&
  560.                                   scoreSection != "Small-Straight" &&
  561.                                   scoreSection != "Large-Straight" &&
  562.                                   scoreSection != "Yahtzee" &&
  563.                                   scoreSection != "Chance"));
  564.             while(!validChoice)
  565.             {
  566.                 std::string invalidOutput = "Your choice was invalid. Please input one of the following (case-sensitive, no spaces): ";
  567.                 if(upSecCanScore[0])
  568.                 {
  569.                     invalidOutput += "Aces, ";
  570.                 }
  571.                 if(upSecCanScore[1])
  572.                 {
  573.                     invalidOutput += "Twos, ";
  574.                 }
  575.                 if(upSecCanScore[2])
  576.                 {
  577.                     invalidOutput += "Threes, ";
  578.                 }
  579.                 if(upSecCanScore[3])
  580.                 {
  581.                     invalidOutput += "Fours, ";
  582.                 }
  583.                 if(upSecCanScore[4])
  584.                 {
  585.                     invalidOutput += "Fives, ";
  586.                 }
  587.                 if(upSecCanScore[5])
  588.                 {
  589.                     invalidOutput += "Sixes, ";
  590.                 }
  591.                 if(loSecCanScore[0])
  592.                 {
  593.                     invalidOutput += "Three-of-a-Kind, ";
  594.                 }
  595.                 if(loSecCanScore[1])
  596.                 {
  597.                     invalidOutput += "Four-of-a-Kind, ";
  598.                 }
  599.                 if(loSecCanScore[2])
  600.                 {
  601.                     invalidOutput += "Full-House, ";
  602.                 }
  603.                 if(loSecCanScore[3])
  604.                 {
  605.                     invalidOutput += "Small-Straight, ";
  606.                 }
  607.                 if(loSecCanScore[4])
  608.                 {
  609.                     invalidOutput += "Large-Straight, ";
  610.                 }
  611.                 if(loSecCanScore[5])
  612.                 {
  613.                     invalidOutput += "Yahtzee, ";
  614.                 }
  615.                 if(loSecCanScore[6])
  616.                 {
  617.                     invalidOutput += "Chance";
  618.                 }
  619.  
  620.                 std::cin >> scoreSection;
  621.                 validChoice = ((((!upSecCanScore[0] && scoreSection == "Aces") ||
  622.                                  (!upSecCanScore[1] && scoreSection == "Twos") ||
  623.                                  (!upSecCanScore[2] && scoreSection == "Threes") ||
  624.                                  (!upSecCanScore[3] && scoreSection == "Fours") ||
  625.                                  (!upSecCanScore[4] && scoreSection == "Fives") ||
  626.                                  (!upSecCanScore[5] && scoreSection == "Sixes")) ||
  627.                                 ((!loSecCanScore[0] && scoreSection == "Three-of-a-Kind") ||
  628.                                  (!loSecCanScore[1] && scoreSection == "Four-of-a-Kind") ||
  629.                                  (!loSecCanScore[2] && scoreSection == "FullHouse") ||
  630.                                  (!loSecCanScore[3] && scoreSection == "SmallStraight") ||
  631.                                  (!loSecCanScore[4] && scoreSection == "LargeStraight") ||
  632.                                  (!loSecCanScore[5] && scoreSection == "Yahtzee") ||
  633.                                  (!loSecCanScore[6] && scoreSection == "Chance"))) ||
  634.                                (scoreSection != "Aces" &&
  635.                                 scoreSection != "Twos" &&
  636.                                 scoreSection != "Threes" &&
  637.                                 scoreSection != "Fours" &&
  638.                                 scoreSection != "Fives" &&
  639.                                 scoreSection != "Sixes" &&
  640.                                 scoreSection != "Three-of-a-Kind" &&
  641.                                 scoreSection != "Four-of-a-Kind" &&
  642.                                 scoreSection != "Full-House" &&
  643.                                 scoreSection != "Small-Straight" &&
  644.                                 scoreSection != "Large-Straight" &&
  645.                                 scoreSection != "Yahtzee" &&
  646.                                 scoreSection != "Chance"));
  647.             }
  648.  
  649.             //score
  650.             std::string bonusScore;
  651.             if(scoreSection == "Aces")
  652.             {
  653.                 //count 1s and score
  654.                 upSecScore[0] = countChar(output, '1');
  655.                 std::cout << "You scored " + std::to_string(upSecScore[0]) + " point(s) in the Aces section." << std::endl;
  656.                 if(countChar(output, '1') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
  657.                 {
  658.                     //bonus yahtzee!
  659.                     std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  660.                     std::cin >> bonusScore;
  661.                     while(bonusScore != "Y" && bonusScore != "N")
  662.                     {
  663.                         std::cout << "SPEAK CLEARLY." << std::endl;
  664.                         std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  665.                         std::cin >> bonusScore;
  666.                     }
  667.                     if(bonusScore == "N")
  668.                     {
  669.                         std::cout << "You're crazy, but okay." << std::endl;
  670.                     }
  671.                     else
  672.                     {
  673.                         //score the bonus later
  674.                         yahtzeeCount++;
  675.                     }
  676.                 }
  677.             }
  678.             if(scoreSection == "Twos")
  679.             {
  680.                 //count 2s and score
  681.                 upSecScore[1] = countChar(output, '2') * 2;
  682.                 std::cout << "You scored " + std::to_string(upSecScore[1]) + " point(s) in the Twos section." << std::endl;
  683.                 if(countChar(output, '2') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
  684.                 {
  685.                     //bonus yahtzee!
  686.                     std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  687.                     std::cin >> bonusScore;
  688.                     while(bonusScore != "Y" && bonusScore != "N")
  689.                     {
  690.                         std::cout << "SPEAK CLEARLY." << std::endl;
  691.                         std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  692.                         std::cin >> bonusScore;
  693.                     }
  694.                     if(bonusScore == "N")
  695.                     {
  696.                         std::cout << "You're crazy, but okay." << std::endl;
  697.                     }
  698.                     else
  699.                     {
  700.                         //score the bonus later
  701.                         yahtzeeCount++;
  702.                     }
  703.                 }
  704.             }
  705.             if(scoreSection == "Threes")
  706.             {
  707.                 //count 3s and score
  708.                 upSecScore[2] = countChar(output, '3') * 3;
  709.                 std::cout << "You scored " + std::to_string(upSecScore[2]) + " point(s) in the Threes section." << std::endl;
  710.                 if(countChar(output, '3') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
  711.                 {
  712.                     //bonus yahtzee!
  713.                     std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  714.                     std::cin >> bonusScore;
  715.                     while(bonusScore != "Y" && bonusScore != "N")
  716.                     {
  717.                         std::cout << "SPEAK CLEARLY." << std::endl;
  718.                         std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  719.                         std::cin >> bonusScore;
  720.                     }
  721.                     if(bonusScore == "N")
  722.                     {
  723.                         std::cout << "You're crazy, but okay." << std::endl;
  724.                     }
  725.                     else
  726.                     {
  727.                         //score the bonus later
  728.                         yahtzeeCount++;
  729.                     }
  730.                 }
  731.             }
  732.             if(scoreSection == "Fours")
  733.             {
  734.                 //count 4s and score
  735.                 upSecScore[3] = countChar(output, '4') * 4;
  736.                 std::cout << "You scored " + std::to_string(upSecScore[3]) + " point(s) in the Fours section." << std::endl;
  737.                 if(countChar(output, '4') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
  738.                 {
  739.                     //bonus yahtzee!
  740.                     std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  741.                     std::cin >> bonusScore;
  742.                     while(bonusScore != "Y" && bonusScore != "N")
  743.                     {
  744.                         std::cout << "SPEAK CLEARLY." << std::endl;
  745.                         std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  746.                         std::cin >> bonusScore;
  747.                     }
  748.                     if(bonusScore == "N")
  749.                     {
  750.                         std::cout << "You're crazy, but okay." << std::endl;
  751.                     }
  752.                     else
  753.                     {
  754.                         //score the bonus later
  755.                         yahtzeeCount++;
  756.                     }
  757.                 }
  758.             }
  759.             if(scoreSection == "Fives")
  760.             {
  761.                 //count 5s and score
  762.                 upSecScore[4] = countChar(output, '5') * 5;
  763.                 std::cout << "You scored " + std::to_string(upSecScore[4]) + " point(s) in the Aces section." << std::endl;
  764.                 if(countChar(output, '5') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
  765.                 {
  766.                     //bonus yahtzee!
  767.                     std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  768.                     std::cin >> bonusScore;
  769.                     while(bonusScore != "Y" && bonusScore != "N")
  770.                     {
  771.                         std::cout << "SPEAK CLEARLY." << std::endl;
  772.                         std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  773.                         std::cin >> bonusScore;
  774.                     }
  775.                     if(bonusScore == "N")
  776.                     {
  777.                         std::cout << "You're crazy, but okay." << std::endl;
  778.                     }
  779.                     else
  780.                     {
  781.                         //score the bonus later
  782.                         yahtzeeCount++;
  783.                     }
  784.                 }
  785.             }
  786.             if(scoreSection == "Sixes")
  787.             {
  788.                 //count 6s and score
  789.                 upSecScore[5] = countChar(output, '6') * 6;
  790.                 std::cout << "You scored " + std::to_string(upSecScore[5]) + " point(s) in the Aces section." << std::endl;
  791.                 if(countChar(output, '6') == 5 && loSecOccupied[5] && yahtzeeCount <= 4)
  792.                 {
  793.                     //bonus yahtzee!
  794.                     std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  795.                     std::cin >> bonusScore;
  796.                     while(bonusScore != "Y" && bonusScore != "N")
  797.                     {
  798.                         std::cout << "SPEAK CLEARLY." << std::endl;
  799.                         std::cout << "Would you like to score a bonus yahtzee? [Y for yes, N for no]" << std::endl;
  800.                         std::cin >> bonusScore;
  801.                     }
  802.                     if(bonusScore == "N")
  803.                     {
  804.                         std::cout << "You're crazy, but okay." << std::endl;
  805.                     }
  806.                     else
  807.                     {
  808.                         //score the bonus later
  809.                         yahtzeeCount++;
  810.                     }
  811.                 }
  812.             }
  813.             if(scoreSection == "Three-of-a-Kind")
  814.             {
  815.                 //sum all dice
  816.                 int oneScore = countChar(output, '1') * 1;
  817.                 int twoScore = countChar(output, '2') * 2;
  818.                 int thrScore = countChar(output, '3') * 3;
  819.                 int fouScore = countChar(output, '4') * 4; //fou score and seven years ago...
  820.                 int fivScore = countChar(output, '5') * 5;
  821.                 int sixScore = countChar(output, '6') * 6;
  822.  
  823.                 loSecScore[0] = oneScore + twoScore + thrScore + fouScore + fivScore + sixScore;
  824.                 std::cout << "You scored " + std::to_string(loSecScore[0]) + " point(s) in the Three-of-a-Kind section." << std::endl;
  825.             }
  826.             if(scoreSection == "Four-of-a-Kind")
  827.             {
  828.                 //sum all dice
  829.                 int oneScore = countChar(output, '1') * 1;
  830.                 int twoScore = countChar(output, '2') * 2;
  831.                 int thrScore = countChar(output, '3') * 3;
  832.                 int fouScore = countChar(output, '4') * 4; //fou score and seven years ago...
  833.                 int fivScore = countChar(output, '5') * 5;
  834.                 int sixScore = countChar(output, '6') * 6;
  835.  
  836.                 loSecScore[1] = oneScore + twoScore + thrScore + fouScore + fivScore + sixScore;
  837.                 std::cout << "You scored " + std::to_string(loSecScore[1]) + " point(s) in the Four-of-a-Kind section." << std::endl;
  838.             }
  839.             if(scoreSection == "Full-House")
  840.             {
  841.                 //25
  842.                 loSecScore[2] = 25;
  843.                 std::cout << "You scored " + std::to_string(loSecScore[2]) + " point(s) in the Full-House section." << std::endl;
  844.             }
  845.             if(scoreSection == "Small-Straight")
  846.             {
  847.                 //30
  848.                 loSecScore[3] = 30;
  849.                 std::cout << "You scored " + std::to_string(loSecScore[3]) + " point(s) in the Small-Straight section." << std::endl;
  850.             }
  851.             if(scoreSection == "Large-Straight")
  852.             {
  853.                 //40
  854.                 loSecScore[4] = 40;
  855.                 std::cout << "You scored " + std::to_string(loSecScore[4]) + " point(s) in the Large-Straight section." << std::endl;
  856.             }
  857.  
  858.             if(scoreSection == "Yahtzee")
  859.             {
  860.                 //50
  861.                 loSecScore[5] = 50;
  862.                 std::cout << "You scored " + std::to_string(loSecScore[5]) + " point(s) in the Yahtzee section." << std::endl;
  863.             }
  864.  
  865.             if(scoreSection == "Chance")
  866.             {
  867.                 //sum all dice
  868.                 int oneScore = countChar(output, '1') * 1;
  869.                 int twoScore = countChar(output, '2') * 2;
  870.                 int thrScore = countChar(output, '3') * 3;
  871.                 int fouScore = countChar(output, '4') * 4; //fou score and seven years ago...
  872.                 int fivScore = countChar(output, '5') * 5;
  873.                 int sixScore = countChar(output, '6') * 6;
  874.                 loSecScore[6] = oneScore + twoScore + thrScore + fouScore + fivScore + sixScore;
  875.                 std::cout << "You scored " + std::to_string(loSecScore[6]) + " point(s) in the Chance section." << std::endl;
  876.             }
  877.  
  878.             //print out scores
  879.         } //ends scoring section if/else statement
  880.  
  881.         //print out scorecard
  882.         std::cout << "SCORECARD" << std::endl;
  883.         std::cout << "Aces: " + std::to_string(upSecScore[0]) << std::endl;
  884.         std::cout << "Twos: " + std::to_string(upSecScore[1]) << std::endl;
  885.         std::cout << "Threes: " + std::to_string(upSecScore[2]) << std::endl;
  886.         std::cout << "Fours: " + std::to_string(upSecScore[3]) << std::endl;
  887.         std::cout << "Fives: " + std::to_string(upSecScore[4]) << std::endl;
  888.         std::cout << "Sixes: " + std::to_string(upSecScore[5]) << std::endl;
  889.         std::cout << "Three-of-a-Kind: " + std::to_string(loSecScore[0]) << std::endl;
  890.         std::cout << "Four-of-a-Kind: " + std::to_string(loSecScore[1]) << std::endl;
  891.         std::cout << "Full-House: " + std::to_string(loSecScore[2]) << std::endl;
  892.         std::cout << "Small-Straight: " + std::to_string(loSecScore[3]) << std::endl;
  893.         std::cout << "Large-Straight: " + std::to_string(loSecScore[4]) << std::endl;
  894.         if(yahtzeeCount < 2)
  895.         {
  896.             std::cout << "Yahtzee: " + std::to_string(yahtzeeCount * 50) << std::endl;
  897.             std::cout << "Bonus Yahtzees: 0" << std::endl;
  898.         }
  899.         else
  900.         {
  901.             std::cout << "Yahtzee: 50" << std::endl;
  902.             std::cout << "Bonus Yahtzees: " + std::to_string((yahtzeeCount - 1) * 100) << std::endl;
  903.         }
  904.         std::cout << "Chance: " + std::to_string(loSecScore[6]) << std::endl;
  905.     } //ends turn for loop
  906.     return 0;
  907. } //ends main
Advertisement
Add Comment
Please, Sign In to add comment