Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions exercises/risk-risiko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,56 @@
M 3 vs 3 => blue win
O 2 vs 1 => red win
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <ctime>

using namespace std;

int main() {
srand(static_cast<unsigned>(time(0)));

vector<int> red(3), blue(3);

// Lancio dei dadi
for (int i = 0; i < 3; ++i) {
red[i] = rand() % 6 + 1;
blue[i] = rand() % 6 + 1;
}

// Ordinamento decrescente
sort(red.begin(), red.end(), greater<int>());
sort(blue.begin(), blue.end(), greater<int>());

// Output dei dadi
cout << "Red dices:\n";
cout << " " << red[0] << " (N)\n";
cout << " " << red[1] << " (M)\n";
cout << " " << red[2] << " (O)\n\n";

cout << "Blue dices:\n";
cout << " " << blue[0] << " (N)\n";
cout << " " << blue[1] << " (M)\n";
cout << " " << blue[2] << " (O)\n\n";
// Confronto tra i dadi
cout << " R B\n";
const string labels[3] = {"N", "M", "O"};
int redWins = 0, blueWins = 0;

for (int i = 0; i < 3; ++i) {
cout << labels[i] << " " << red[i] << " vs " << blue[i] << " => ";
if (red[i] > blue[i]) {
cout << "red win\n";
++redWins;
} else {
cout << "blue win\n";
++blueWins;
}
}
// Risultato finale
cout << "\nResult: Red wins " << redWins << " | Blue wins " << blueWins << endl;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potrsti spezzettare questo codice in più funzioni al posto di implementare tutto nel main


return 0;
}