Remove warnings

This commit is contained in:
Calcitem Team 2019-08-24 23:39:28 +08:00
parent 0e70629878
commit 98ad902fb0
4 changed files with 70 additions and 64 deletions

View File

@ -347,12 +347,14 @@ void GameController::setSound(bool arg)
void GameController::playSound(const QString &soundPath)
{
if (soundPath == "") {
return;
}
#ifndef DONOT_PLAY_SOUND
if (hasSound) {
QSound::play(soundPath);
}
#else
soundPath; // 为消除变量未使用过的警告
#endif /* ! DONOT_PLAY_SOUND */
}
@ -637,7 +639,7 @@ bool GameController::actionPiece(QPointF pos)
switch (chess_.getAction()) {
case NineChess::ACTION_PLACE:
if (chess_.place(c, p)) {
if (chess_._place(c, p)) {
if (chess_.getAction() == NineChess::ACTION_CAPTURE) {
// 播放成三音效
playSound(":/sound/resources/sound/capture.wav");
@ -650,6 +652,7 @@ bool GameController::actionPiece(QPointF pos)
}
// 如果移子不成功尝试重新选子这里不break
[[fallthrough]];
case NineChess::ACTION_CHOOSE:
piece = qgraphicsitem_cast<PieceItem *>(item);
@ -666,7 +669,7 @@ bool GameController::actionPiece(QPointF pos)
break;
case NineChess::ACTION_CAPTURE:
if (chess_.capture(c, p)) {
if (chess_._capture(c, p)) {
// 播放音效
playSound(":/sound/resources/sound/remove.wav");
result = true;

View File

@ -104,7 +104,7 @@ signals:
// 和棋数改变的信号
void scoreDrawChanged(const QString &score);
// 玩家1(先手)用时改变的信号
// 玩家1(先手)用时改变的信号
void time1Changed(const QString &time);
// 玩家2(后手)用时改变的信号
@ -240,10 +240,10 @@ private:
int stepsLimit;
// 玩家1剩余时间毫秒
long remainingTime1;
int remainingTime1;
// 玩家2剩余时间毫秒
long remainingTime2;
int remainingTime2;
// 用于主窗口状态栏显示的字符串
QString message;

View File

@ -327,13 +327,12 @@ void NineChess::createMillTable()
}
// 设置棋局状态和棋盘数据,用于初始化
bool NineChess::setContext(const struct Rule *rule, int maxStepsLedToDraw, int maxTimeLedToLose,
int initialStep, int flags, const char *board,
bool NineChess::setContext(const struct Rule *rule, step_t maxStepsLedToDraw, int maxTimeLedToLose,
step_t initialStep, int flags, const char *board,
int nPiecesInHand_1, int nPiecesInHand_2, int nPiecesNeedRemove)
{
// 有效性判断
if (maxStepsLedToDraw < 0 || maxTimeLedToLose < 0 || initialStep < 0 ||
nPiecesInHand_1 < 0 || nPiecesInHand_2 < 0 || nPiecesNeedRemove < 0) {
if (maxTimeLedToLose < 0) {
return false;
}
@ -571,12 +570,11 @@ bool NineChess::reset()
if (sprintf(cmdline, "r%1u s%03u t%02u", i + 1, currentRule.maxStepsLedToDraw, currentRule.maxTimeLedToLose) > 0) {
cmdlist.push_back(string(cmdline));
return true;
} else {
cmdline[0] = '\0';
return false;
}
return true;
cmdline[0] = '\0';
return false;
}
bool NineChess::start()
@ -588,7 +586,8 @@ bool NineChess::start()
return false;
// 如果游戏结束,则重置游戏,进入未开始状态
case GAME_OVER:
reset(); // 这里不要break;
reset();
[[fallthrough]];
// 如果游戏处于未开始状态
case GAME_NOTSTARTED:
// 启动计时器
@ -661,7 +660,7 @@ int NineChess::cp2pos(int c, int p)
return c * N_SEATS + p - 1;
}
bool NineChess::place(int pos, long time_p, bool cp)
bool NineChess::place(int pos, int time_p, int8_t cp)
{
// 如果局面为“结局”返回false
if (context.stage == GAME_OVER)
@ -685,7 +684,7 @@ bool NineChess::place(int pos, long time_p, bool cp)
pos2cp(pos, c, p);
// 时间的临时变量
long player_ms = -1;
int player_ms = -1;
// 对于开局落子
int piece = '\x00';
@ -712,7 +711,7 @@ bool NineChess::place(int pos, long time_p, bool cp)
#endif
move_ = pos;
if (cp == true) {
if (cp) {
player_ms = update(time_p);
sprintf(cmdline, "(%1u,%1u) %02u:%02u.%03u",
c, p, player_ms / 60000, (player_ms % 60000) / 1000, player_ms % 1000);
@ -794,7 +793,7 @@ bool NineChess::place(int pos, long time_p, bool cp)
// 移子
move_ = (currentPos << 8) + pos;
if (cp == true) {
if (cp) {
player_ms = update(time_p);
sprintf(cmdline, "(%1u,%1u)->(%1u,%1u) %02u:%02u.%03u", currentPos / N_SEATS, currentPos % N_SEATS + 1,
c, p, player_ms / 60000, (player_ms % 60000) / 1000, player_ms % 1000);
@ -841,14 +840,14 @@ bool NineChess::place(int pos, long time_p, bool cp)
}
out:
if (cp == true) {
if (cp) {
setTips();
}
return true;
}
bool NineChess::place(int c, int p, long time_p)
bool NineChess::_place(int c, int p, int time_p)
{
// 转换为 pos
int pos = cp2pos(c, p);
@ -856,15 +855,15 @@ bool NineChess::place(int c, int p, long time_p)
return place(pos, time_p, true);
}
bool NineChess::capture(int c, int p, long time_p)
bool NineChess::_capture(int c, int p, int time_p)
{
// 转换为 pos
int pos = cp2pos(c, p);
return capture(pos, time_p, true);
return capture(pos, time_p, 1);
}
bool NineChess::capture(int pos, long time_p, bool cp)
bool NineChess::capture(int pos, int time_p, int8_t cp)
{
// 如果局面为"未开局"或“结局”返回false
if (context.stage == GAME_NOTSTARTED || context.stage == GAME_OVER)
@ -884,7 +883,7 @@ bool NineChess::capture(int pos, long time_p, bool cp)
pos2cp(pos, c, p);
// 时间的临时变量
long player_ms = -1;
int player_ms = -1;
// 对手
char opponent = context.turn == PLAYER1 ? 0x20 : 0x10;
@ -922,7 +921,7 @@ bool NineChess::capture(int pos, long time_p, bool cp)
move_ = -pos;
if (cp == true) {
if (cp) {
player_ms = update(time_p);
sprintf(cmdline, "-(%1u,%1u) %02u:%02u.%03u", c, p, player_ms / 60000, (player_ms % 60000) / 1000, player_ms % 1000);
cmdlist.push_back(string(cmdline));
@ -1006,7 +1005,7 @@ bool NineChess::capture(int pos, long time_p, bool cp)
}
out:
if (cp == true) {
if (cp) {
setTips();
}
@ -1077,16 +1076,19 @@ bool NineChess::giveup(Player loser)
// 打算用个C++的命令行解析库的,简单的没必要,但中文编码有极小概率出问题
bool NineChess::command(const char *cmd)
{
int r, s, t;
int r, t;
step_t s;
int c1, p1, c2, p2;
int args = 0;
int mm = 0, ss = 0, mss = 0;
long tm = -1;
int tm = -1;
// 设置规则
if (sscanf(cmd, "r%1u s%3u t%2u", &r, &s, &t) == 3) {
if (r <= 0 || r > N_RULES)
if (sscanf(cmd, "r%1u s%3hd t%2u", &r, &s, &t) == 3) {
if (r <= 0 || r > N_RULES) {
return false;
}
return setContext(&NineChess::RULES[r - 1], s, t);
}
@ -1098,7 +1100,7 @@ bool NineChess::command(const char *cmd)
tm = mm * 60000 + ss * 1000 + mss;
}
if (choose(c1, p1))
return place(c2, p2, tm);
return _place(c2, p2, tm);
else
return false;
}
@ -1110,7 +1112,7 @@ bool NineChess::command(const char *cmd)
if (mm >= 0 && ss >= 0 && mss >= 0)
tm = mm * 60000 + ss * 1000 + mss;
}
return capture(c1, p1, tm);
return _capture(c1, p1, tm);
}
// 落子
@ -1120,7 +1122,7 @@ bool NineChess::command(const char *cmd)
if (mm >= 0 && ss >= 0 && mss >= 0)
tm = mm * 60000 + ss * 1000 + mss;
}
return place(c1, p1, tm);
return _place(c1, p1, tm);
}
// 认输
@ -1169,11 +1171,11 @@ bool NineChess::command(int move)
return false;
}
inline long NineChess::update(long time_p /*= -1*/)
inline int NineChess::update(int time_p /*= -1*/)
{
long ret = -1;
long *player_ms = (context.turn == PLAYER1 ? &elapsedMS_1 : &elapsedMS_2);
long playerNext_ms = (context.turn == PLAYER1 ? elapsedMS_2 : elapsedMS_1);
int ret = -1;
int *player_ms = (context.turn == PLAYER1 ? &elapsedMS_1 : &elapsedMS_2);
int playerNext_ms = (context.turn == PLAYER1 ? elapsedMS_2 : elapsedMS_1);
// 根据局面调整计时器
@ -1186,7 +1188,7 @@ inline long NineChess::update(long time_p /*= -1*/)
// 更新时间
if (time_p >= *player_ms) {
*player_ms = ret = time_p;
long t = elapsedMS_1 + elapsedMS_2;
int t = elapsedMS_1 + elapsedMS_2;
startTimeb.time = currentTimeb.time - (t / 1000);
startTimeb.millitm = currentTimeb.millitm - (t % 1000);
@ -1196,7 +1198,7 @@ inline long NineChess::update(long time_p /*= -1*/)
startTimeb.millitm += 1000;
}
} else {
*player_ms = ret = static_cast<long>(currentTimeb.time - startTimeb.time) * 1000
*player_ms = ret = static_cast<int>(currentTimeb.time - startTimeb.time) * 1000
+ (currentTimeb.millitm - startTimeb.millitm) - playerNext_ms;
}
@ -1630,7 +1632,7 @@ enum NineChess::Player NineChess::getWhosPiece(int c, int p)
return NOBODY;
}
void NineChess::getElapsedTimeMS(long &p1_ms, long &p2_ms)
void NineChess::getElapsedTimeMS(int &p1_ms, int &p2_ms)
{
update();
@ -1662,14 +1664,14 @@ void NineChess::mirror(bool cmdChange /*= true*/)
s = (N_SEATS - s) % N_SEATS;
move_ = -(r * N_SEATS + s);
} else {
llp[0] = move_ >> 8;
llp[0] = static_cast<uint64_t>(move_ >> 8);
llp[1] = move_ & 0x00ff;
for (i = 0; i < 2; i++) {
r = static_cast<int>(llp[i]) / N_SEATS;
s = static_cast<int>(llp[i]) % N_SEATS;
s = (N_SEATS - s) % N_SEATS;
llp[i] = r * N_SEATS + s;
llp[i] = static_cast<uint64_t>(r * N_SEATS + s);
}
move_ = static_cast<int16_t>(((llp[0] << 8) | llp[1]));
@ -1692,7 +1694,7 @@ void NineChess::mirror(bool cmdChange /*= true*/)
r = static_cast<int>(llp[i]) / N_SEATS;
s = static_cast<int>(llp[i]) % N_SEATS;
s = (N_SEATS - s) % N_SEATS;
llp[i] = r * N_SEATS + s;
llp[i] = static_cast<uint64_t>(r * N_SEATS + s);
}
*mill &= 0xffffff00ff00ff00;
@ -1777,7 +1779,7 @@ void NineChess::turn(bool cmdChange /*= true*/)
move_ = -(r * N_SEATS + s);
} else {
llp[0] = move_ >> 8;
llp[0] = static_cast<uint64_t>(move_ >> 8);
llp[1] = move_ & 0x00ff;
for (i = 0; i < 2; i++) {
@ -1789,7 +1791,7 @@ void NineChess::turn(bool cmdChange /*= true*/)
else if (r == N_RINGS)
r = 1;
llp[i] = r * N_SEATS + s;
llp[i] = static_cast<uint64_t>(r * N_SEATS + s);
}
move_ = static_cast<int16_t>(((llp[0] << 8) | llp[1]));
@ -1822,7 +1824,7 @@ void NineChess::turn(bool cmdChange /*= true*/)
else if (r == N_RINGS)
r = 1;
llp[i] = r * N_SEATS + s;
llp[i] = static_cast<uint64_t>(r * N_SEATS + s);
}
*mill &= 0xffffff00ff00ff00;
@ -1983,16 +1985,16 @@ void NineChess::rotate(int degrees, bool cmdChange /*= true*/)
s = (s + N_SEATS - degrees) % N_SEATS;
move_ = -(r * N_SEATS + s);
} else {
llp[0] = move_ >> 8;
llp[0] = static_cast<uint64_t>(move_ >> 8);
llp[1] = move_ & 0x00ff;
r = static_cast<int>(llp[0]) / N_SEATS;
s = static_cast<int>(llp[0]) % N_SEATS;
s = (s + N_SEATS - degrees) % N_SEATS;
llp[0] = r * N_SEATS + s;
llp[0] = static_cast<uint64_t>(r * N_SEATS + s);
r = static_cast<int>(llp[1]) / N_SEATS;
s = static_cast<int>(llp[1]) % N_SEATS;
s = (s + N_SEATS - degrees) % N_SEATS;
llp[1] = r * N_SEATS + s;
llp[1] = static_cast<uint64_t>(r * N_SEATS + s);
move_ = static_cast<int16_t>(((llp[0] << 8) | llp[1]));
}
@ -2013,7 +2015,7 @@ void NineChess::rotate(int degrees, bool cmdChange /*= true*/)
r = static_cast<int>(llp[i]) / N_SEATS;
s = static_cast<int>(llp[i]) % N_SEATS;
s = (s + N_SEATS - degrees) % N_SEATS;
llp[i] = r * N_SEATS + s;
llp[i] = static_cast<uint64_t>(r * N_SEATS + s);
}
*mill &= 0xffffff00ff00ff00;
@ -2149,7 +2151,7 @@ NineChess::hash_t NineChess::revertHash(int pos)
NineChess::hash_t NineChess::updateHashMisc()
{
// 清除标记位
context.hash &= ~0xFF;
context.hash &= static_cast<hash_t>(~0xFF);
// 置位

View File

@ -74,6 +74,7 @@ public:
// 定义类型
typedef int32_t move_t;
typedef uint16_t step_t;
#ifdef HASH_MAP_CUTDOWN
typedef uint32_t hash_t;
@ -133,7 +134,7 @@ public:
bool allowFlyWhenRemainThreePieces;
// 最大步数,超出判和
int maxStepsLedToDraw;
step_t maxStepsLedToDraw;
// 包干最长时间超出判负为0则不计时
int maxTimeLedToLose;
@ -303,9 +304,9 @@ public:
// 设置棋局状态和棋盘上下文,用于初始化
bool setContext(const struct Rule *rule,
int maxStepsLedToDraw = 0, // 限制步数
step_t maxStepsLedToDraw = 0, // 限制步数
int maxTimeLedToLose = 0, // 限制时间
int initialStep = 0, // 默认起始步数为0
step_t initialStep = 0, // 默认起始步数为0
int flags = GAME_NOTSTARTED | PLAYER1 | ACTION_PLACE, // 默认状态
const char *board = nullptr, // 默认空棋盘
int nPiecesInHand_1 = 12, // 玩家1剩余未放置子数
@ -384,7 +385,7 @@ public:
}
// 玩家1和玩家2的用时
void getElapsedTimeMS(long &p1_ms, long &p2_ms);
void getElapsedTimeMS(int &p1_ms, int &p2_ms);
// 获取棋局的字符提示
const string getTips() const
@ -459,10 +460,10 @@ public:
bool choose(int c, int p);
// 落子在第c圈第p个位置为迎合日常c和p下标都从1开始
bool place(int c, int p, long time_p = -1);
bool _place(int c, int p, int time_p = -1);
// 去子在第c圈第p个位置为迎合日常c和p下标都从1开始
bool capture(int c, int p, long time_p = -1);
bool _capture(int c, int p, int time_p = -1);
// 认输
bool giveup(Player loser);
@ -505,7 +506,7 @@ protected:
int cp2pos(int c, int p);
// 更新时间和状态,用内联函数以提高效率
inline long update(long time_p = -1);
inline int update(int time_p = -1);
// 是否分出胜负
bool win();
@ -523,8 +524,8 @@ protected:
// 下面几个函数没有算法无关判断和无关操作,节约算法时间
bool command(int move);
bool choose(int pos);
bool place(int pos, long time_p = -1, bool cp = false);
bool capture(int pos, long time_p = -1, bool cp = false);
bool place(int pos, int time_p = -1, int8_t cp = 0);
bool capture(int pos, int time_p = -1, int8_t cp = 0);
#if ((defined HASH_MAP_ENABLE) || (defined BOOK_LEARNING) || (defined THREEFOLD_REPETITION))
// hash相关
@ -566,10 +567,10 @@ private:
timeb currentTimeb;
// 玩家1用时毫秒
long elapsedMS_1;
int elapsedMS_1;
// 玩家2用时毫秒
long elapsedMS_2;
int elapsedMS_2;
/* 当前着法AI会用到如下表示
0x 00 00