-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathrisk-risiko.cpp
107 lines (89 loc) · 2.22 KB
/
risk-risiko.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Write a program that simulates a risk/risiko fight using 6 dices.
How does it work?
When a player attacks another player he uses 3 dices, the red is always the attacker and the blue is the defender.
You have to compare the dice with the highest number to simulate the fight.
N = first highest number
M = second highest number
O = third highest number
If the numbers are equal, the defensor (blue) wins.
Output:
Red dices:
6 (N)
3 (M)
2 (O)
Blue dices:
5 (N)
3 (M)
1 (O)
R B
N 6 vs 5 => red win
M 3 vs 3 => blue win
O 2 vs 1 => red win
*/
/*
Write a program that simulates a risk/risiko fight using 6 dices.
How does it work?
When a player attacks another player he uses 3 dices, the red is always the attacker and the blue is the defender.
You have to compare the dice with the highest number to simulate the fight.
N = first highest number
M = second highest number
O = third highest number
If the numbers are equal, the defensor (blue) wins.
Output:
Red dices:
6 (N)
3 (M)
2 (O)
Blue dices:
5 (N)
3 (M)
1 (O)
R B
N 6 vs 5 => red win
M 3 vs 3 => blue win
O 2 vs 1 => red win
*/
#define EXIT_SUCCESS 0
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
void attack()
{
vector<int> blue = {0, 0, 0};
vector<int> red = {0, 0, 0};
int attacker_points = 0;
for (int i = 0; i < 3; i++)
{
blue[i] = rand() % 6 + 1;
red[i] = rand() % 6 + 1;
}
sort(blue.begin(), blue.end(), greater<int>());
sort(red.begin(), red.end(), greater<int>());
cout << "Red dices:" << endl;
cout << red[0] << " (N)" << endl;
cout << red[1] << " (M)" << endl;
cout << red[2] << " (O)" << endl;
cout << endl;
cout << "Blue dices:" << endl;
cout << blue[0] << " (N)" << endl;
cout << blue[1] << " (M)" << endl;
cout << blue[2] << " (O)" << endl;
cout << endl;
for (int i = 0; i < 3; i++)
{
if (blue[i] < red[i])
{
attacker_points++;
}
}
cout << (attacker_points >= 2 ? "Red" : "Blue") << " wins!" << endl;
}
int main(int argc, char *argv[])
{
srand(time(NULL));
attack();
return EXIT_SUCCESS;
}