-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGomokuClient.h
70 lines (57 loc) · 1.72 KB
/
GomokuClient.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
//=============================================================
// Name : GomokuClient.h
// Author : Albin Engström
// Created : 2014-10-26
// Modified : 2014-11-15
// Description : Definition of class GomokuClient
// Purpose : A TCP Socket that is used from a client
//=============================================================
#include "TCPSocket.h"
#include <stdexcept>
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <time.h>
#include <thread>
#include <mutex>
#include <exception>
#include <string>
class GomokuClient
{
private:
//A TCPSocket pointer
TCPSocket *mp_tcpsocket;
//Creates 2 dimensinal vectors to represent the players moves
std::vector< std::vector<bool> > m_player_board;
std::vector< std::vector<bool> > m_ai_board;
//Used to make sure cout usage is atomic
std::mutex m_cout_mutex;
public:
GomokuClient();
//Pre:
//Post: Establishes a connection to the server
~GomokuClient();
//Pre:
//Post: Closes the connection to the server
void Run();
//Pre:
//Post: Runs a game of gomoku
void PrintBoard(std::vector< std::vector<bool> > a_m_player_board,
std::vector< std::vector<bool> > a_m_ai_board);
//Pre:
//Post: Prints the board to screen
void getMove(char *message, int &x, int &y);
//Pre:
//Post: Sets x and y according to the message
void ListenToServer();
//Pre:
//Post: Reacts to messages from the server
//A Wrapper allowing ListenToServer() to be called by a thread
/*
static void StaticWrapper_ListenToServer(void *o)
{
GomokuClient *gomokuclient = static_cast<GomokuClient*>(o);
gomokuclient->ListenToServer();
}
*/
};