从 console 分支合并一些修改从
不涉及指针转引用的修改合并之。 分析时于是打印比分。 注意Debug自对弈时长貌似从16秒变成17秒。
This commit is contained in:
parent
47d66692f3
commit
140df0f6d1
|
@ -224,6 +224,10 @@ Position &Position::set(const string &fenStr, StateInfo *si, Thread *th)
|
|||
Square sq = SQ_A1;
|
||||
std::istringstream ss(fenStr);
|
||||
|
||||
if (this->phase != PHASE_NONE && this->phase != PHASE_READY && this->phase != PHASE_GAMEOVER) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
std::memset(this, 0, sizeof(Position));
|
||||
std::memset(si, 0, sizeof(StateInfo));
|
||||
//std::fill_n(&pieceList[0][0], sizeof(pieceList) / sizeof(Square), SQ_NONE);
|
||||
|
@ -301,7 +305,7 @@ Position &Position::set(const string &fenStr, StateInfo *si, Thread *th)
|
|||
set_state(st);
|
||||
|
||||
assert(pos_is_ok());
|
||||
|
||||
out:
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -265,8 +265,8 @@ int MainThread::search()
|
|||
if (th->rootMoves[0].score > bestThread->rootMoves[0].score)
|
||||
bestThread = th;
|
||||
} else if (th->rootMoves[0].score >= VALUE_TB_WIN_IN_MAX_PLY
|
||||
|| (th->rootMoves[0].score > VALUE_TB_LOSS_IN_MAX_PLY
|
||||
&& votes[th->rootMoves[0].pv[0]] > votes[bestThread->rootMoves[0].pv[0]]))
|
||||
|| (th->rootMoves[0].score > VALUE_TB_LOSS_IN_MAX_PLY
|
||||
&& votes[th->rootMoves[0].pv[0]] > votes[bestThread->rootMoves[0].pv[0]]))
|
||||
bestThread = th;
|
||||
}
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ void MainThread::check_time()
|
|||
/// UCI::pv() formats PV information according to the UCI protocol. UCI requires
|
||||
/// that all (if any) unsearched PV lines are sent using a previous search score.
|
||||
|
||||
string UCI::pv(Position *pos, Depth depth, Value alpha, Value beta)
|
||||
string UCI::pv(const Position *pos, Depth depth, Value alpha, Value beta)
|
||||
{
|
||||
|
||||
std::stringstream ss;
|
||||
|
@ -545,6 +545,7 @@ string UCI::pv(Position *pos, Depth depth, Value alpha, Value beta)
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern ThreadPool Threads;
|
||||
|
||||
vector<Key> moveHistory;
|
||||
|
||||
|
|
|
@ -156,7 +156,11 @@ void Thread::idle_loop()
|
|||
lk.unlock();
|
||||
|
||||
// TODO: Stockfish doesn't have this
|
||||
if (rootPos == nullptr || rootPos->side_to_move() != us) {
|
||||
if (
|
||||
#ifdef QT_UI
|
||||
//rootPos == nullptr ||
|
||||
#endif
|
||||
rootPos->side_to_move() != us) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -174,15 +178,13 @@ void Thread::idle_loop()
|
|||
if (search() == 3) {
|
||||
loggerDebug("Draw\n\n");
|
||||
strCommand = "draw";
|
||||
#ifdef QT_UI
|
||||
emitCommand();
|
||||
#endif
|
||||
} else {
|
||||
strCommand = nextMove();
|
||||
if (strCommand != "" && strCommand != "error!") {
|
||||
#ifdef QT_UI
|
||||
emitCommand();
|
||||
#endif
|
||||
} else {
|
||||
int err = 1;
|
||||
}
|
||||
}
|
||||
#ifdef OPENING_BOOK
|
||||
|
@ -216,12 +218,17 @@ void Thread::setAi(Position *p, int tl)
|
|||
timeLimit = tl;
|
||||
}
|
||||
|
||||
#ifdef QT_UI
|
||||
void Thread::emitCommand()
|
||||
{
|
||||
#ifdef QT_UI
|
||||
emit command(strCommand);
|
||||
}
|
||||
#else
|
||||
loggerDebug("%s\n", strCommand.c_str());
|
||||
rootPos.command(strCommand.c_str());
|
||||
us = rootPos.side_to_move();
|
||||
analyze(rootPos.side_to_move());
|
||||
#endif // QT_UI
|
||||
}
|
||||
|
||||
#ifdef OPENING_BOOK
|
||||
deque<int> openingBookDeque(
|
||||
|
@ -264,6 +271,10 @@ void sq2str(char *str)
|
|||
|
||||
void Thread::analyze(Color c)
|
||||
{
|
||||
static int nbwin = 0;
|
||||
static int nwwin = 0;
|
||||
static int ndraw = 0;
|
||||
|
||||
int d = (int)originDepth;
|
||||
int v = (int)bestvalue;
|
||||
int lv = (int)lastvalue;
|
||||
|
@ -291,10 +302,13 @@ void Thread::analyze(Color c)
|
|||
case PHASE_GAMEOVER:
|
||||
if (p->get_winner() == DRAW) {
|
||||
cout << "和棋" << endl;
|
||||
ndraw++;
|
||||
} else if (p->get_winner() == BLACK) {
|
||||
cout << "黑方胜" << endl;
|
||||
nbwin++;
|
||||
} else if (p->get_winner() == WHITE) {
|
||||
cout << "白方胜" << endl;
|
||||
nwwin++;
|
||||
}
|
||||
goto out;
|
||||
break;
|
||||
|
@ -365,11 +379,13 @@ void Thread::analyze(Color c)
|
|||
}
|
||||
|
||||
if (p->side_to_move() == BLACK) {
|
||||
cout << "轮到黑方行棋";
|
||||
cout << "轮到黑方行棋" << endl;
|
||||
} else {
|
||||
cout << "轮到白方行棋";
|
||||
cout << "轮到白方行棋" << endl;
|
||||
}
|
||||
|
||||
cout << "比分: " << nbwin << " : " << nwwin << " : " << ndraw << endl;
|
||||
|
||||
out:
|
||||
cout << endl << endl;
|
||||
}
|
||||
|
@ -506,8 +522,6 @@ void Thread::clearTT()
|
|||
|
||||
string Thread::nextMove()
|
||||
{
|
||||
return UCI::move(bestMove);
|
||||
|
||||
#if 0
|
||||
char charSelect = '*';
|
||||
|
||||
|
@ -564,6 +578,8 @@ string Thread::nextMove()
|
|||
|
||||
nodeCount = 0;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#ifdef TRANSPOSITION_TABLE_DEBUG
|
||||
size_t hashProbeCount = ttHitCount + ttMissCount;
|
||||
|
@ -574,12 +590,13 @@ string Thread::nextMove()
|
|||
#endif // TRANSPOSITION_TABLE_DEBUG
|
||||
#endif // TRANSPOSITION_TABLE_ENABLE
|
||||
|
||||
#if 0
|
||||
if (foundBest == false) {
|
||||
loggerDebug("Warning: Best Move NOT Found\n");
|
||||
}
|
||||
|
||||
return UCI::move(bestMove).c_str();
|
||||
#endif
|
||||
|
||||
return UCI::move(bestMove);
|
||||
}
|
||||
|
||||
#ifdef ENDGAME_LEARNING
|
||||
|
|
|
@ -106,6 +106,7 @@ void setoption(istringstream &is)
|
|||
|
||||
void go(Position *pos, istringstream &is, StateListPtr &states)
|
||||
{
|
||||
begin:
|
||||
Search::LimitsType limits;
|
||||
string token;
|
||||
bool ponderMode = false;
|
||||
|
@ -131,6 +132,8 @@ void go(Position *pos, istringstream &is, StateListPtr &states)
|
|||
else if (token == "ponder") ponderMode = true;
|
||||
|
||||
Threads.start_thinking(pos, states, limits, ponderMode);
|
||||
|
||||
goto begin;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ void loop(int argc, char* argv[]);
|
|||
std::string value(Value v);
|
||||
std::string square(Square s);
|
||||
std::string move(Move m);
|
||||
std::string pv(Position* pos, Depth depth, Value alpha, Value beta);
|
||||
std::string pv(const Position* pos, Depth depth, Value alpha, Value beta);
|
||||
Move to_move(Position* pos, std::string& str);
|
||||
|
||||
} // namespace UCI
|
||||
|
|
Loading…
Reference in New Issue