-
Notifications
You must be signed in to change notification settings - Fork 3
/
blotto2.cpp
61 lines (51 loc) · 1.59 KB
/
blotto2.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
#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 player1[10] = {0};
int player2[10] = {0};
int player1Score, player2Score, player1T, player2T;
player1Score = player2Score = player1T = player2T = 0;
for (int i = 0; i < 10; i++) {
player1File >> player1[i];
player2File >> player2[i];
player1T += player1[i];
player2T += player2[i];
}
if (player1T != 100 || player2T != 100) {
cout << "Must place down 100 soldiers\n";
return -1;
}
for (int i = 0; i < 10; i++) {
if (player2[i] > player1[i]) {
cout << "Player 2 won " << i << "\n";
player2Score += i;
} else if (player1[i] > player2[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 2;
} else if (player1Score >= 20) {
cout << "Player 1 won!\n";
return 1;
}
}
cout << "Not enough values were different, so it's a tie!\n";
return 0;
}