From 1e6456b9021931772bf8663d61b8b780db90ee0a Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sat, 29 Feb 2020 00:11:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=AE=A9=20NODE=5FCHILDREN=5FSIZE?= =?UTF-8?q?=20=E7=9B=B4=E6=8E=A5=E7=AD=89=E4=BA=8E=20MOVE=5FCOUNT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 顺带加了一段 MCTS 相关的双方棋盘上棋子数相差4则算负的代码但未启用。 --- src/ai/search.h | 2 +- src/game/position.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ai/search.h b/src/ai/search.h index 35357fa7..0684c676 100644 --- a/src/ai/search.h +++ b/src/ai/search.h @@ -92,7 +92,7 @@ public: string indentString(int indent) const; #endif // MCTS_AI - static const int NODE_CHILDREN_SIZE = (4 * 4 + 3 * 4 * 2); // TODO: 缩减空间 + static const int NODE_CHILDREN_SIZE = MOVE_COUNT; Node *children[NODE_CHILDREN_SIZE]; Node *parent { nullptr }; diff --git a/src/game/position.cpp b/src/game/position.cpp index ab33c6bd..1d4440f6 100644 --- a/src/game/position.cpp +++ b/src/game/position.cpp @@ -923,6 +923,29 @@ bool Game::checkGameOverCondition() } } +#ifdef MCTS_AI +#if 0 + int diff = position->nPiecesOnBoard[BLACK] - position->nPiecesOnBoard[WHITE]; + if (diff > 4) { + winner = PLAYER_BLACK; + position->phase = PHASE_GAMEOVER; + sprintf(cmdline, "Player1 win!"); + cmdlist.emplace_back(string(cmdline)); + + return true; + } + + if (diff < -4) { + winner = PLAYER_WHITE; + position->phase = PHASE_GAMEOVER; + sprintf(cmdline, "Player2 win!"); + cmdlist.emplace_back(string(cmdline)); + + return true; + } +#endif +#endif + // 如果摆满了,根据规则判断胜负 if (position->nPiecesOnBoard[BLACK] + position->nPiecesOnBoard[WHITE] >= Board::N_SEATS * Board::N_RINGS) { position->phase = PHASE_GAMEOVER;