-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChessEngine.s3d
67 lines (56 loc) · 1016 Bytes
/
ChessEngine.s3d
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
#ifndef _CHESSENGINE
#define _CHESSENGINE
class ChessEngine
{
var channel;
var data;
var port;
Connect();
DataReady(timeout);
Send(msg);
Receive();
};
function ChessEngine::ChessEngine(p)
{
port = p;
}
function ChessEngine::Connect()
{
//return;
var t = 3;
do
{
channel = NetConnectTCP("localhost", port, VR_NO_BLOCKING);
if(channel !=0) //not working, XVR crash
{
OutputLN("Connected to engine");
return true;
}
else
{
OutputLN("Connection Fail, try: " + t);
t--;
Sleep(1000);
}
} while(t > 0);
return false;
}
function ChessEngine::DataReady(timeout)
{
return NetDataReady(channel, timeout);
}
function ChessEngine::Receive()
{
var data = "";
do
{
data = NetReceiveFromTCP(channel);
}
while(data == "");
return data;
}
function ChessEngine::Send(msg)
{
NetSendToTCP(channel, msg);
}
#endif