From 4b0569ea6528ca82ef07d7b716fe06468d9e95ba Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sat, 28 Sep 2019 02:06:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=20phase=20?= =?UTF-8?q?=E7=9A=84=E6=88=90=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ai/search.cpp | 4 ++-- src/game/position.cpp | 13 ++++--------- src/game/types.h | 4 +++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/ai/search.cpp b/src/ai/search.cpp index 3f16de25..2f67088a 100644 --- a/src/ai/search.cpp +++ b/src/ai/search.cpp @@ -89,11 +89,11 @@ depth_t AIAlgorithm::changeDepth(depth_t origDepth) }; #endif /* ENDGAME_LEARNING */ - if ((tempGame.position.phase) & (PHASE_PLACING)) { + if (tempGame.position.phase & PHASE_PLACING) { d = placingDepthTable[tempGame.getPiecesInHandCount(1)]; } - if ((tempGame.position.phase) & (PHASE_MOVING)) { + if (tempGame.position.phase & PHASE_MOVING) { int p1 = tempGame.getPiecesOnBoardCount(1); int p2 = tempGame.getPiecesOnBoardCount(2); diff --git a/src/game/position.cpp b/src/game/position.cpp index f53de144..a07f1a94 100644 --- a/src/game/position.cpp +++ b/src/game/position.cpp @@ -471,7 +471,7 @@ bool Game::_capture(int r, int s) bool Game::capture(int location, int8_t updateCmdlist) { // 如果局面为"未开局"或“结局”,返回false - if (position.phase == PHASE_NOTSTARTED || position.phase == PHASE_GAMEOVER) + if (position.phase & PHASE_NOTPLAYING) return false; // 如非“去子”状态,返回false @@ -642,8 +642,7 @@ bool Game::choose(int r, int s) bool Game::giveup(player_t loser) { - if (position.phase == PHASE_NOTSTARTED || - position.phase == PHASE_GAMEOVER || + if (position.phase & PHASE_NOTPLAYING || position.phase == PHASE_NONE) { return false; } @@ -771,7 +770,7 @@ inline int Game::update() // 根据局面调整计时器 - if (!(position.phase == PHASE_PLACING || position.phase == PHASE_MOVING)) { + if (!(position.phase & PHASE_PLAYING)) { return -1; } @@ -802,14 +801,10 @@ bool Game::win() // 是否分出胜负 bool Game::win(bool forceDraw) { - if (position.phase == PHASE_GAMEOVER) { + if (position.phase & PHASE_NOTPLAYING) { return true; } - if (position.phase == PHASE_NOTSTARTED) { - return false; - } - // 如果有时间限定 if (rule.maxTimeLedToLose > 0) { position.phase = PHASE_GAMEOVER; diff --git a/src/game/types.h b/src/game/types.h index 13d7c5a8..ca1494e1 100644 --- a/src/game/types.h +++ b/src/game/types.h @@ -98,7 +98,9 @@ enum phase_t : uint16_t PHASE_NOTSTARTED = 1, // 未开局 PHASE_PLACING = 1 << 1, // 开局(摆棋) PHASE_MOVING = 1 << 2, // 中局(走棋) - PHASE_GAMEOVER = 1 << 3 // 结局 + PHASE_GAMEOVER = 1 << 3, // 结局 + PHASE_PLAYING = PHASE_PLACING | PHASE_MOVING, // 进行中 + PHASE_NOTPLAYING = PHASE_NOTSTARTED | PHASE_GAMEOVER, // 不在进行中 }; enum value_t : int16_t