-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
83 lines (73 loc) · 2.08 KB
/
main.cpp
File metadata and controls
83 lines (73 loc) · 2.08 KB
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
#include "main.h"
#include <iostream>
#include <algorithm>
#include "Driver.h"
#include "MemoryAnalytics.h"
using namespace std;
/// <summary>
/// Returns a command line parameter as char*
/// </summary>
char* get_cmd_options(char** begin, char** end, const std::string& option)
{
char** itr = std::find(begin, end, option);
if (itr != end && ++itr != end)
{
return *itr;
}
return 0;
}
/// <summary>
/// Check if command line parameter with prefix exists
/// </summary>
bool cmd_option_exists(char** begin, char** end, const std::string& option)
{
return std::find(begin, end, option) != end;
}
void print_welcome()
{
cerr << "--- --- --- Simple C++ chess --- --- ---" << endl;
cerr << "USAGE: no arguments for chess game" << endl;
cerr << "USAGE: -b for bot game" << endl;
cerr << "USAGE: -m for memory analytics about classes" << endl;
cerr << "USAGE: -s <INT> to change board size. default size 8, must be > 8 and straight" << endl;
cerr << "USAGE: -a to play with the super cool MyChessman figures." << endl;
cerr << "--- --- --- Have Fun --- --- ---" << endl;
}
int main(int argc, char** argv) {
srand(time(NULL));
int size = 8;
bool use_my_chessman = false;
print_welcome();
// custom size parameter
if (cmd_option_exists(argv, argv + argc, "-s"))
{
char* c_size = get_cmd_options(argv, argv + argc, "-s");
size = atoi(c_size);
cout << "Found size parameter. Initialising board with size " << size << endl;
}
// use my custom chessman
if (cmd_option_exists(argv, argv + argc, "-a"))
{
use_my_chessman = true;
}
// start a bot game
if (cmd_option_exists(argv, argv + argc, "-b"))
{
cout << "Found bot parameter. Launching bot game" << endl;
Driver driver{ size, use_my_chessman };
driver.start_simulation();
}
// start memory analytics output
else if (cmd_option_exists(argv, argv + argc, "-m"))
{
cout << "Found memory parameter. Launching memory analytics " << endl;
MemoryAnalytics analytics;
analytics.print_class_memory();
}
// start player vs player game
else {
Driver driver{ size, use_my_chessman };
driver.start_game();
}
return 0;
}