#include #include #include #include "DiceArray.h" #include "YatzyBoard.h" using namespace std; // Gets the correct values for the first six values void FirstXs(int number, DiceArray dices, int pos, YatzyBoard * board) { for (int i = 1; i <= 3; i++ ) { dices.throwDice(); dices.keepNumber(number); } board->firstsix[pos].getValue(dices.getValues()); // cout << board->firstsix[pos].getPoints() << " : " << PointClass::global_points << endl; } // Returns the highest number with the one closest to number alike int findHighestNumberValue(int numberAlike, vector notValues, DiceArray * dices, int betterThan) { vector tmp = dices->getValues(); for (int i = numberAlike; i>0; i--) { for (int j = 6; j>0 && j>betterThan; j--) { if (count(tmp.begin(), tmp.end(), j) >= i) { // If value in notValues, then start next iteration of loop // so we won't get the same value again. if (binary_search (notValues.begin(), notValues.end(),j)) { continue; } int index = 0; for (int k = i; k > 0; k--) { index = dices->keepOneNumber(j,index); } return j; } } } } // Gets the correct value of the number of alike void findAlike(int throws, int numberAlike, int betterThan, DiceArray dices, YatzyBoard * board) { DiceArray *pointerDices = &dices; for (int l = 0; l < throws; l++) { // Resets and throwdice vector notValues; dices.throwDice(); dices.reset(); // Saves the number that is closest to number alike. notValues.push_back(findHighestNumberValue(numberAlike, notValues, pointerDices, betterThan)); } board->alike[numberAlike-2].getValue(dices.getValues()); // cout << board->alike[numberAlike-2].getPoints() << " : " << PointClass::global_points << endl; } // Gets The correct value of 2 pairs void findTwoPair (int throws, int betterThan, DiceArray dices, YatzyBoard * board) { int numberAlike1 = 2, numberAlike2 = 2; vector tmp; DiceArray * pointerDices = &dices; for (int l = 0; l < throws; l++) { // Resets and throw dice vector notValues; dices.throwDice(); dices.reset(); // Saves the number that is the closest to number alike notValues.push_back(findHighestNumberValue(numberAlike1, notValues,pointerDices, betterThan)); // Saves the number that is the closest to number alike notValues.push_back(findHighestNumberValue(numberAlike2, notValues,pointerDices, betterThan)); } board->twopair.getValue(dices.getValues()); // cout << board->twopair.getPoints() << " : " << PointClass::global_points << endl; } // Gets the correct value of house void findHouse (int throws, int betterThan, DiceArray dices, YatzyBoard * board) { int numberAlike1 = 3, numberAlike2 = 2; vector tmp; DiceArray * pointerDices = &dices; for (int l = 0; l < throws; l++) { vector notValues; dices.throwDice(); dices.reset(); // Saves the number that is the closest to number alike notValues.push_back(findHighestNumberValue(numberAlike1, notValues,pointerDices, betterThan)); // Saves the number that is the closest to number alike notValues.push_back(findHighestNumberValue(numberAlike2, notValues,pointerDices, betterThan)); } board->house.getValue(dices.getValues()); // cout << board->house.getPoints() << " : " << PointClass::global_points << endl; } // Gets the correct value of straight void findStraight(int throws, DiceArray dices, YatzyBoard * board, int start,int stopp, int whichStraight) { vector tmp; for (int i = 0; i< throws;i++) { dices.throwDice(); dices.reset(); tmp = dices.getValues(); // Saves the values needed for straight for (int j = start; j <= stopp; j++) { dices.keepOneNumber(j, 0); } } board->straight[whichStraight].getValue(dices.getValues()); // cout << board->straight[whichStraight].getPoints() << " : " << PointClass::global_points << endl; } // Get a good value for chance void findChance(DiceArray dices, YatzyBoard * board, int throws, int betterThan) { for (int i = 0; i < throws; i++) { dices.throwDice(); for (int i = 6; i > betterThan; i--) { dices.keepNumber(i); } } board->chance.getValue(dices.getValues()); // cout << board->chance.getPoints() << " : "<< PointClass::global_points << endl; } // Get yatzy void findYatzy(int throws, YatzyBoard * board, DiceArray dices) { DiceArray *pointerDices = &dices; for (int l = 0; l < throws; l++) { vector notValues; dices.throwDice(); dices.reset(); // Find highest alike ... Doesn't have to be highest but it // prioritize the most alike before highest notValues.push_back(findHighestNumberValue(6, notValues, pointerDices, 0)); } board->yatzy.getValue(dices.getValues()); // cout << board->yatzy.getPoints() << " : " << PointClass::global_points << endl; } // Here it is all put together int main() { ofstream verdier; verdier.open("YatzyVerdier.txt"); int numberOfDice = 6; int numberOfSides = 6; YatzyBoard board; YatzyBoard * pointerBoard = &board; DiceArray dices(numberOfDice, numberOfSides); DiceArray * pointerDices = &dices; for(int i = 0; i<1000000; i++) { for (int i = 0; i < numberOfDice; i++) { FirstXs(i+1, dices, i, pointerBoard); } board.bonusCheck(); // cout << board.Bonus << endl; for (int i = 2; i<=4; i++) { findAlike(3, i, 0, dices, pointerBoard); } findHouse(3,0,dices, pointerBoard); findTwoPair(3,0,dices, pointerBoard); findStraight(3,dices, pointerBoard, 1,5,0); findStraight(3, dices, pointerBoard, 2,6,1); findStraight(3, dices, pointerBoard, 1,6,2); findChance(dices, pointerBoard, 3, 3); findYatzy(3, pointerBoard, dices); verdier << board.firstsix[0].getPoints() << " " << board.firstsix[1].getPoints() << " " << board.firstsix[2].getPoints() << " " << board.firstsix[3].getPoints() << " " << board.firstsix[4].getPoints() << " " << board.firstsix[5].getPoints() << " " << FirstSix::sumPoints << " " << board.Bonus << " " << board.alike[0].getPoints() << " " << board.alike[1].getPoints() << " " << board.alike[2].getPoints() << " " << board.twopair.getPoints() << " " << board.house.getPoints() << " " << board.straight[0].getPoints() << " " << board.straight[1].getPoints() << " " << board.straight[2].getPoints() << " " << board.yatzy.getPoints() << " " << PointClass::global_points << endl; board.reset(); } }