-
Notifications
You must be signed in to change notification settings - Fork 3
/
blotto.cpp
57 lines (48 loc) · 1.44 KB
/
blotto.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
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
if (argc != 3) {
cout << "Must include 2 files with player moves\n";
return -1;
}
ifstream player1File(argv[1]);
ifstream player2File(argv[2]);
if (player1File.fail() || player2File.fail()) {
cout << "Invalid files\n";
return -1;
}
int player1Count[10] = {0};
int player1Score = 0;
int player2Count[10] = {0};
int player2Score = 0;
for (int i = 0; i < 100; i++) {
int temp;
player1File >> temp;
player1Count[temp]++;
player2File >> temp;
player2Count[temp]++;
}
for (int i = 0; i < 10; i++) {
if (player2Count[i] > player1Count[i]) {
cout << "Player 2 won " << i << "\n";
player2Score += i;
} else if (player1Count[i] > player2Count[i]) {
cout << "Player 1 won " << i << "\n";
player1Score += i;
} else {
cout << "It was a tie! No points assigned\n";
}
cout << "Score: Player 1: " << player1Score
<< "\tPlayer 2: " << player2Score << "\n";
if (player2Score >= 20) {
cout << "Player 2 won!\n";
return 0;
} else if (player1Score >= 20) {
cout << "Player 1 won!\n";
return 0;
}
}
cout << "Not enough values were different, so it's a tie!\n";
return 0;
}