-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsiEngine.cpp
68 lines (62 loc) · 1.4 KB
/
UsiEngine.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
#include "UsiEngine.h"
UsiEngine::UsiEngine()
{
_fen = SHOGIFEN;
}
UsiEngine::~UsiEngine()
{
}
EngineProtocol UsiEngine::GetType()
{
return USI;
}
void UsiEngine::StartGame(QString variant)
{
_moves.clear();
_process->write("usi\n");
_process->write("isready\n");
_process->write("usinewgame\n");
}
void UsiEngine::Move(signed char x1, signed char y1, signed char x2, signed char y2, char promotion)
{
_process->write("position startpos moves ");
for (auto& _move : _moves)
{
_process->write(_move);
_process->write(" ");
}
_process->write(AddMove(x1, y1, x2, y2, promotion));
_process->write("\n");
_process->write("go depth 10\n");
}
QByteArray UsiEngine::AddMove(signed char x1, signed char y1, signed char x2, signed char y2, char promotion)
{
QByteArray moveStr;
if (y1 == '*')
{
moveStr.push_back(x1);
moveStr.push_back(y1);
moveStr.push_back(QString::number(x2)[0].toLatin1());
moveStr.push_back(static_cast<char>(y2 + 97));
}
else if (x1 < 10)
{
moveStr.push_back(QString::number(x1)[0].toLatin1());
moveStr.push_back(static_cast<char>(y1 + 97));
moveStr.push_back(QString::number(x2)[0].toLatin1());
moveStr.push_back(static_cast<char>(y2 + 97));
}
else
{
moveStr.push_back(x1);
moveStr.push_back(y1);
moveStr.push_back(x2);
moveStr.push_back(y2);
}
if (promotion == '+')
{
moveStr.push_back(promotion);
}
_moves.push_back(moveStr);
return moveStr;
}