-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (29 loc) · 771 Bytes
/
main.cpp
File metadata and controls
35 lines (29 loc) · 771 Bytes
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
#include <iostream>
#include <memory>
#include "computer_player.hpp"
#include "game.hpp"
#include "human_player.hpp"
using namespace tictactoe;
std::unique_ptr<player> make_player(std::string name) {
return ("cpu" == name)
? std::unique_ptr<player>(new computer_player())
: std::unique_ptr<player>(new human_player(name));
}
int main(int argc, const char * const argv[]) {
if (argc < 3) {
std::cerr <<
"Usage:\n"
"\t" << argv[0] << " <player1> <player2>\n"
"\n"
"<player1>, <player2>\n"
"\tThe names for the respective players.\n"
"\tTo play against the computer, use the name \"cpu\".\n";
}
else {
std::unique_ptr<player>
player1(make_player(argv[1])),
player2(make_player(argv[2]));
game(*player1, *player2);
}
return 0;
}