-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.hpp
63 lines (48 loc) · 1.39 KB
/
client.hpp
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
/*
* class client
* responsible for:
* communication with server
* AI of the game
*/
#ifndef CLIENT_HPP
#define CLIENT_HPP
#include <string>
#include <fstream>
#include <memory>
#include "boost/asio.hpp"
#include "mazeCom_.hpp"
#include "board.hpp"
using namespace std;
using boost::asio::io_service;
using boost::asio::ip::tcp;
typedef std::auto_ptr<MazeCom> MazeCom_Ptr;
class client
{
public:
//log for messages, only works after login
static std::ofstream log;
private:
io_service _ios;
tcp::socket _socket;
MazeCom::id_type _id;
bool _accepted;
public:
int id() const;
//ctor, connects to server
client(const string& ip, const string& port);
void find_next_move(const AwaitMoveMessageType&, MoveMessageType&);
void default_move(const AwaitMoveMessageType&, MoveMessageType&);
//distance of player with id to card with treasure t
int distance(const Board& board, int id, Treasure t);
//weighted possible movement of all opponents, used for determining quality of moves
int count_freedom_opponents(const Board&, const vector<int>&);
void write_body(boost::system::error_code e, size_t, shared_ptr<string> msg);
void close();
void login(const string&);
void send(const MazeCom&);
void start_recv();
void read_next();
void read_body(boost::system::error_code, size_t, shared_ptr<vector<char>>);
void handle_msg(boost::system::error_code, size_t, shared_ptr<vector<char>>);
};
#endif