forked from gomoku/Carbon-Gomoku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AIwrapper.cpp
123 lines (104 loc) · 2.46 KB
/
AIwrapper.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "pisqpipe.h"
#include <windows.h>
#include <stdio.h>
#include "AICarbon.h"
const char *infotext="name=\"Carbon\", author=\"Michal Czardybon\", version=\"2.3\", country=\"Poland\", www=\"http://mczard.republika.pl/gomoku.en.html\"";
AICarbon *ai;
void brain_init()
{
if(width<5 || height < 5){
pipeOut("ERROR Invalid size of the board");
return;
}
if(width > MAX_BOARD_WIDTH){
pipeOut("ERROR Maximal board width is %d", MAX_BOARD_WIDTH);
return;
}
if(height > MAX_BOARD_HEIGHT){
pipeOut("ERROR Maximal board height is %d", MAX_BOARD_HEIGHT);
return;
}
brain_restart();
}
void brain_restart()
{
if(!ai) ai = new AICarbon();
ai->start(width, height);
pipeOut("OK");
}
void brain_my(int x, int y)
{
ai->setWho(XP);
ai->move(x, y);
}
void brain_opponents(int x, int y)
{
ai->setWho(OP);
ai->move(x, y);
}
void brain_block(int x, int y)
{
ai->block(x, y);
}
int brain_takeback(int x, int y)
{
return ai->undo(x, y);
}
void brain_turn()
{
int x, y;
ai->setWho(XP);
ai->yourTurn(x, y);
ai->move(x, y);
pipeOut("%d,%d", x, y);
}
void brain_end()
{
delete ai;
}
void WriteLog(int points, int nSearched, int speed, int depth, bool debug)
{
pipeOut("%s eval %d, depth %d, nodes %d, speed %d", debug ? "DEBUG" : "MESSAGE",
points, depth, nSearched, speed);
}
long getTime()
{
return (long)GetTickCount();
}
#ifdef DEBUG_EVAL
void brain_eval(int x, int y)
{
ai->eval(x, y);
}
static HWND wnd = FindWindowA("Piskvork", 0);
static void vprint(int x, int y, int w, char *format, va_list va)
{
HDC dc = GetDC(wnd);
RECT rc;
rc.top = y;
rc.bottom = y+16;
rc.left = x - w/2;
rc.right = rc.left + w;
char buf[128];
int n = vsprintf(buf, format, va);
SetTextAlign(dc, TA_CENTER);
ExtTextOutA(dc, x, y, ETO_OPAQUE, &rc, buf, n, 0);
ReleaseDC(wnd, dc);
}
static void printXY(int x, int y, int w, char *format, ...)
{
va_list va;
va_start(va, format);
vprint(x, y, w, format, va);
va_end(va);
}
void AICarbon::eval(int x, int y)
{
OXCell *c = &cell[x+4][y+4];
printXY(300, 0, 60, " [%d,%d,%d,%d],[%d,%d,%d,%d] ",
c->status1[0][0], c->status1[1][0], c->status1[2][0], c->status1[3][0],
c->status1[0][1], c->status1[1][1], c->status1[2][1], c->status1[3][1]);
printXY(300, 16, 60, "%d,%d", c->status4[0], c->status4[1]);
printXY(300, 32, 60, "%d", c->prior());
}
#endif