-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
68 lines (61 loc) · 1.07 KB
/
main.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
//Copyright (C) 2009 - Missouri S&T ACM AI Team
//Please do not modify this file while building your AI
//See AI.h & AI.cpp for that
#include <iostream>
#include <cstring>
#include <cstdlib>
#include "AI.h"
#include "network.h"
#include "game.h"
using namespace std;
int main(int argc, char** argv)
{
if(argc < 2)
{
cout<<"Please enter a host name."<<endl;
return 1;
}
Connection* c;
c = createConnection();
AI ai(c);
int gameNumber;
if(!serverConnect(c, argv[1], "19000"))
{
cerr << "Unable to connect to server" << endl;
return 1;
}
if(!serverLogin(c, ai.username(), ai.password()))
{
return 1;
}
if(argc < 3)
{
gameNumber = createGame(c);
}
else
{
if(!joinGame(c, atoi(argv[2]), "player"))
{
cerr << "Error joining game." << endl;
return 1;
}
}
while(networkLoop(c))
{
if(ai.startTurn())
{
endTurn(c);
}
else
{
getStatus(c);
}
}
ai.end();
//Grab a log
networkLoop(c);
//Grab the end game status
networkLoop(c);
destroyConnection(c);
return 0;
}