time: 修正变量名以配合将精度由毫秒改为秒

This commit is contained in:
Calcitem 2019-08-30 00:15:54 +08:00
parent 7aaa330f1f
commit 4212e5b5d2
3 changed files with 34 additions and 47 deletions

View File

@ -523,7 +523,7 @@ void GameController::timerEvent(QTimerEvent *event)
static QTime qt1, qt2;
// 玩家的已用时间
chess_.getElapsedTimeMS(remainingTime1, remainingTime2);
chess_.getElapsedTime(remainingTime1, remainingTime2);
// 如果规则要求计时则time1和time2表示倒计时
if (timeLimit > 0) {
@ -925,7 +925,7 @@ bool GameController::stageChange(int row, bool forceUpdate)
}
// 下面这步关键,会让悔棋者承担时间损失
chessTemp.setStartTimeb(chess_.getStartTimeb());
chessTemp.setStartTime(chess_.getStartTimeb());
// 刷新棋局场景
updateScence(chessTemp);

View File

@ -164,10 +164,10 @@ NineChess::NineChess(const NineChess &chess)
board_ = context.board;
currentPos = chess.currentPos;
winner = chess.winner;
startTimeb = chess.startTimeb;
currentTimeb = chess.currentTimeb;
elapsedMS_1 = chess.elapsedMS_1;
elapsedMS_2 = chess.elapsedMS_2;
startTime = chess.startTime;
currentTime = chess.currentTime;
elapsedSeconds_1 = chess.elapsedSeconds_1;
elapsedSeconds_2 = chess.elapsedSeconds_2;
move_ = chess.move_;
memcpy(cmdline, chess.cmdline, sizeof(cmdline));
cmdlist = chess.cmdlist;
@ -186,10 +186,10 @@ NineChess &NineChess::operator=(const NineChess &chess)
board_ = context.board;
currentPos = chess.currentPos;
winner = chess.winner;
startTimeb = chess.startTimeb;
currentTimeb = chess.currentTimeb;
elapsedMS_1 = chess.elapsedMS_1;
elapsedMS_2 = chess.elapsedMS_2;
startTime = chess.startTime;
currentTime = chess.currentTime;
elapsedSeconds_1 = chess.elapsedSeconds_1;
elapsedSeconds_2 = chess.elapsedSeconds_2;
move_ = chess.move_;
memcpy(cmdline, chess.cmdline, sizeof(cmdline));
cmdlist = chess.cmdlist;
@ -468,7 +468,7 @@ bool NineChess::setContext(const struct Rule *rule, step_t maxStepsLedToDraw, in
currentPos = 0;
// 用时置零
elapsedMS_1 = elapsedMS_2 = 0;
elapsedSeconds_1 = elapsedSeconds_2 = 0;
// 提示
setTips();
@ -505,7 +505,7 @@ void NineChess::getContext(struct Rule &rule, step_t &step, int &flags,
bool NineChess::reset()
{
if (context.stage == GAME_NOTSTARTED && elapsedMS_1 == elapsedMS_2 == 0)
if (context.stage == GAME_NOTSTARTED && elapsedSeconds_1 == elapsedSeconds_2 == 0)
return true;
// 步数归零
@ -543,7 +543,7 @@ bool NineChess::reset()
currentPos = 0;
// 用时置零
elapsedMS_1 = elapsedMS_2 = 0;
elapsedSeconds_1 = elapsedSeconds_2 = 0;
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
// 哈希归零
@ -587,7 +587,7 @@ bool NineChess::start()
// 如果游戏处于未开始状态
case GAME_NOTSTARTED:
// 启动计时器
startTimeb = time(NULL);
startTime = time(NULL);
// 进入开局状态
context.stage = GAME_PLACING;
return true;
@ -1178,8 +1178,8 @@ bool NineChess::command(int move)
inline int NineChess::update(int time_p /*= -1*/)
{
int ret = -1;
time_t *player_ms = (context.turn == PLAYER1 ? &elapsedMS_1 : &elapsedMS_2);
time_t playerNext_ms = (context.turn == PLAYER1 ? elapsedMS_2 : elapsedMS_1);
time_t *player_ms = (context.turn == PLAYER1 ? &elapsedSeconds_1 : &elapsedSeconds_2);
time_t playerNext_ms = (context.turn == PLAYER1 ? elapsedSeconds_2 : elapsedSeconds_1);
// 根据局面调整计时器
@ -1187,27 +1187,15 @@ inline int NineChess::update(int time_p /*= -1*/)
return -1;
}
#if 1
currentTimeb = time(NULL);
currentTime = time(NULL);
// 更新时间
if (time_p >= *player_ms) {
*player_ms = ret = time_p;
time_t t = elapsedMS_1 + elapsedMS_2;
startTimeb = currentTimeb - t;
#if 0
startTimeb.millitm = currentTimeb.millitm - (t % 1000);
if (t % 1000 > currentTimeb.millitm) {
startTimeb.time--;
startTimeb.millitm += 1000;
}
#endif
startTime = currentTime - (elapsedSeconds_1 + elapsedSeconds_2);
} else {
*player_ms = ret = currentTimeb - startTimeb - playerNext_ms;
*player_ms = ret = currentTime - startTime - playerNext_ms;
}
#endif
// 有限时要求则判断胜负
if (currentRule.maxTimeLedToLose > 0) {
@ -1240,15 +1228,15 @@ bool NineChess::win(bool forceDraw)
// 这里不能update更新时间否则会形成循环嵌套
// 如果玩家1超时
if (elapsedMS_1 > currentRule.maxTimeLedToLose * 60) {
elapsedMS_1 = currentRule.maxTimeLedToLose * 60;
if (elapsedSeconds_1 > currentRule.maxTimeLedToLose * 60) {
elapsedSeconds_1 = currentRule.maxTimeLedToLose * 60;
winner = PLAYER2;
tips = "玩家1超时判负。";
sprintf(cmdline, "Time over. Player2 win!");
}
// 如果玩家2超时
else if (elapsedMS_2 > currentRule.maxTimeLedToLose * 60) {
elapsedMS_2 = currentRule.maxTimeLedToLose * 60;
else if (elapsedSeconds_2 > currentRule.maxTimeLedToLose * 60) {
elapsedSeconds_2 = currentRule.maxTimeLedToLose * 60;
winner = PLAYER1;
tips = "玩家2超时判负。";
sprintf(cmdline, "Time over. Player1 win!");
@ -1643,12 +1631,12 @@ enum NineChess::Player NineChess::getWhosPiece(int c, int p)
return NOBODY;
}
void NineChess::getElapsedTimeMS(time_t &p1_ms, time_t &p2_ms)
void NineChess::getElapsedTime(time_t &p1_ms, time_t &p2_ms)
{
update();
p1_ms = elapsedMS_1;
p2_ms = elapsedMS_2;
p1_ms = elapsedSeconds_1;
p2_ms = elapsedSeconds_2;
}
void NineChess::mirror(bool cmdChange /*= true*/)

View File

@ -22,7 +22,6 @@
#ifndef NINECHESS
#define NINECHESS
//#include <sys/timeb.h>
#include <string>
#include <cstring>
#include <list>
@ -385,7 +384,7 @@ public:
}
// 玩家1和玩家2的用时
void getElapsedTimeMS(time_t &p1_ms, time_t &p2_ms);
void getElapsedTime(time_t &p1_ms, time_t &p2_ms);
// 获取棋局的字符提示
const string getTips() const
@ -411,13 +410,13 @@ public:
// 获取开局时间
time_t getStartTimeb() const
{
return startTimeb;
return startTime;
}
// 重新设置开局时间
void setStartTimeb(int stimeb)
void setStartTime(int stimeb)
{
startTimeb = stimeb;
startTime = stimeb;
}
// 玩家1剩余未放置子数
@ -561,16 +560,16 @@ private:
int moveStep {};
// 游戏起始时间
time_t startTimeb {};
time_t startTime {};
// 当前游戏时间
time_t currentTimeb {};
time_t currentTime {};
// 玩家1用时
time_t elapsedMS_1 {};
time_t elapsedSeconds_1 {};
// 玩家2用时
time_t elapsedMS_2 {};
time_t elapsedSeconds_2 {};
/* 当前着法AI会用到如下表示
0x 00 00