refactor: 增加 phase 的成员

This commit is contained in:
Calcitem 2019-09-28 02:06:43 +08:00
parent e0601e8fa0
commit 4b0569ea65
3 changed files with 9 additions and 12 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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