diff --git a/exercises/risk-risiko.cpp b/exercises/risk-risiko.cpp index 3166f058..5c58869f 100644 --- a/exercises/risk-risiko.cpp +++ b/exercises/risk-risiko.cpp @@ -27,3 +27,73 @@ M 3 vs 3 => blue win O 2 vs 1 => red win */ + +#include +#include +#include +#include +#include + +using namespace std; + +const int NUM_DICES_FOR_USER = 3; +const int NUM_TOTAL_DICE = NUM_DICES_FOR_USER * 2; +const short int RED_WIN = 1; +const short int BLUE_WIN = -1; +const unsigned short int FACES_DICES = 6; + +unsigned int * generateDicesNumber(); +void compareValue(unsigned int * dices); +void showDices(unsigned int * dices); + +int main() { + unsigned int seed = static_cast( + chrono::steady_clock::now().time_since_epoch().count() + ); + srand(seed); + + unsigned int * dices = generateDicesNumber(); + + sort(dices, dices+NUM_DICES_FOR_USER); + sort(dices+NUM_DICES_FOR_USER, dices+(NUM_DICES_FOR_USER*2)); + + showDices(dices); + compareValue(dices); + + free(dices); + return EXIT_SUCCESS; +} + +unsigned int * generateDicesNumber(){ + unsigned int* dices = new unsigned int[NUM_TOTAL_DICE]; + + for(int i = 0; i < NUM_TOTAL_DICE; i++) + dices[i] = rand() % FACES_DICES + 1; + + return dices; +} + +void compareValue(unsigned int * dices) { + cout << endl << " R B"; + + for(int i = NUM_DICES_FOR_USER-1; i >= 0; i--) { + cout << endl << "N " << dices[i] << " vs " << dices[i+NUM_DICES_FOR_USER]; + + if(dices[i] > dices[i+NUM_DICES_FOR_USER]) + cout << " => RED WIN"; + else + cout << " => BLUE WIN"; + } + cout << endl; +} + +void showDices(unsigned int * dices){ + cout << "\nBlue dices: " << endl; + + for(int i = NUM_TOTAL_DICE-1; i >= 0; i--) { + if(i == 2) + cout << "\n\nRed dices: " << endl; + + cout << dices[i] << endl; + } +} \ No newline at end of file