-
Notifications
You must be signed in to change notification settings - Fork 0
/
referee.h
74 lines (59 loc) · 1.85 KB
/
referee.h
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
#ifndef __REFEREE_H_INCLUDED__
#define __REFEREE_H_INCLUDED__
#include <vector>
#include <string>
#include "graph.h"
#include "muncher.h"
#include "state.h"
#include "socket/socket_server.h"
#include "socket/conn_protocol.h"
#include "protocol.h"
/**
* referee mointers the game, and provides methods to conduct
* a game by interacting with two players through underlying
* connection package.
*/
class referee {
public:
referee (const int, const char *, const char *);
~referee ();
bool is_prepare_done ();
void game_init ();
void game_loop ();
std::string declare_result ();
private:
void prepare ();
void play_one_round (std::vector<muncher> &, std::vector<muncher> &);
// Deploy new nanomunchers to current graph before each
// round, and resolve any conflict
void deploy_new_nanomunchers (std::vector<muncher> &,
std::vector<muncher> &);
// Play all nanomunchers, and resolve conflict
void run_nanomunchers ();
state get_current_state () const;
bool prepare_done;
const std::string file_name;
conn::socket_server * ptr_server;
std::string port;
std::string red_team_name;
std::string blue_team_name;
int fd_for_red;
int fd_for_blue;
graph graph_m_;
std::string graph_msg;
// used as the stopping criteria
bool is_munching;
// records how many nanomunchers each player has left.
int red_left;
int blue_left;
// records the number of nanomunchers has been munched by
// each player
int red_score;
int blue_score;
// records alive nanomunchers at a specific round for red player
std::vector< muncher > red_munchers;
// records alive nanomunchers at a spcific for blue player
std::vector< muncher > blue_munchers;
// -----------------------------------------------------------------
};
#endif