perfect: Integrate Perfect AI to Qt (WIP)
This commit is contained in:
parent
920ad3f592
commit
e58ad0f63a
|
@ -14,7 +14,7 @@ int perfect_init(void)
|
|||
char databaseDirectory[] = "";
|
||||
#endif
|
||||
|
||||
if (mill != nullptr) {
|
||||
if (mill != nullptr || ai != nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,33 @@ int perfect_init(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int perfect_exit(void)
|
||||
{
|
||||
if (mill == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
delete mill;
|
||||
mill = nullptr;
|
||||
|
||||
if (ai == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
delete ai;
|
||||
ai = nullptr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int perfect_reset(void)
|
||||
{
|
||||
perfect_exit();
|
||||
perfect_init();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Square from_perfect_sq(unsigned int sq)
|
||||
{
|
||||
Square map[] = {
|
||||
|
@ -72,11 +99,12 @@ void to_perfect_move(Move move, unsigned int &from, unsigned int &to)
|
|||
{
|
||||
Square f = from_sq(move);
|
||||
Square t = to_sq(move);
|
||||
MoveType type = type_of(move);
|
||||
|
||||
if (mill->mustStoneBeRemoved()) {
|
||||
from = fieldStruct::size;
|
||||
to = to_perfect_sq(t);
|
||||
} else if (mill->inSettingPhase()) {
|
||||
if (type == MOVETYPE_REMOVE) {
|
||||
from = to_perfect_sq(t);
|
||||
to = fieldStruct::size;
|
||||
} else if (type == MOVETYPE_PLACE) {
|
||||
from = fieldStruct::size;
|
||||
to = to_perfect_sq(t);
|
||||
} else {
|
||||
|
@ -99,6 +127,8 @@ Move perfect_search()
|
|||
//sync_cout << "========================" << sync_endl;
|
||||
|
||||
mill->getComputersChoice(&from, &to);
|
||||
assert(!(from == 24 && to == 24));
|
||||
|
||||
ret = mill->doMove(from, to);
|
||||
assert(ret == true);
|
||||
|
||||
|
@ -129,11 +159,6 @@ bool perfect_do_move(Move move)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool perfect_reset()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool perfect_command(const char *cmd)
|
||||
{
|
||||
unsigned int ruleNo = 0;
|
||||
|
@ -156,20 +181,22 @@ bool perfect_command(const char *cmd)
|
|||
|
||||
if (args >= 4) {
|
||||
move = make_move(make_square(file1, rank1), make_square(file2, rank2));
|
||||
|
||||
return perfect_do_move(move);
|
||||
}
|
||||
|
||||
args = sscanf(cmd, "-(%1u,%1u)", (unsigned *)&file1, (unsigned *)&rank1);
|
||||
if (args >= 2) {
|
||||
move = (Move)-make_move(SQ_0, make_square(file1, rank1));
|
||||
return perfect_do_move(move);
|
||||
}
|
||||
|
||||
args = sscanf(cmd, "(%1u,%1u)", (unsigned *)&file1, (unsigned *)&rank1);
|
||||
if (args >= 2) {
|
||||
move = make_move(SQ_0, make_square(file1, rank1));
|
||||
return perfect_do_move(move);
|
||||
}
|
||||
|
||||
return perfect_do_move(move);
|
||||
return false;
|
||||
|
||||
args = sscanf(cmd, "Player%1u give up!", &t);
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ extern PerfectAI *ai;
|
|||
|
||||
// Perfect AI
|
||||
int perfect_init(void);
|
||||
int perfect_exit(void);
|
||||
int perfect_reset(void);
|
||||
Square from_perfect_sq(unsigned int sq);
|
||||
Move from_perfect_move(unsigned int from, unsigned int to);
|
||||
unsigned to_perfect_sq(Square sq);
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "misc.h"
|
||||
#include "test.h"
|
||||
|
||||
#include "perfect/perfect.h"
|
||||
|
||||
#ifdef TEST_MODE
|
||||
#ifdef QT_GUI_LIB
|
||||
QString getAppFileName();
|
||||
|
@ -216,6 +218,9 @@ void Test::readFromMemory()
|
|||
memset(to, 0, SHARED_MEMORY_SIZE);
|
||||
sharedMemory.unlock();
|
||||
readStr = str;
|
||||
#ifdef PERFECT_AI
|
||||
perfect_command(str.toStdString().c_str());
|
||||
#endif
|
||||
emit command(str.toStdString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,8 +60,6 @@ Thread::Thread(size_t n
|
|||
idx(n), stdThread(&Thread::idle_loop, this),
|
||||
timeLimit(3600)
|
||||
{
|
||||
perfect_init();
|
||||
|
||||
wait_for_search_finished();
|
||||
}
|
||||
|
||||
|
|
|
@ -195,6 +195,9 @@ void Game::gameReset()
|
|||
moveHistory.emplace_back(bak);
|
||||
}
|
||||
|
||||
#ifdef PERFECT_AI
|
||||
perfect_reset();
|
||||
#endif
|
||||
position.reset();
|
||||
elapsedSeconds[BLACK] = elapsedSeconds[WHITE] = 0;
|
||||
sideToMove = position.side_to_move();
|
||||
|
|
Loading…
Reference in New Issue