refactor: 部分变量和类型改名
启用 ring_t 和 seat_t capture -> removePiece choose -> selectPiece
This commit is contained in:
parent
71fa68b67d
commit
80bbec96a7
|
@ -56,7 +56,7 @@
|
||||||
<file>resources/icon/ic_visibility_black_48dp.png</file>
|
<file>resources/icon/ic_visibility_black_48dp.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/sound">
|
<qresource prefix="/sound">
|
||||||
<file>resources/sound/choose.wav</file>
|
<file>resources/sound/Select.wav</file>
|
||||||
<file>resources/sound/drog.wav</file>
|
<file>resources/sound/drog.wav</file>
|
||||||
<file>resources/sound/forbidden.wav</file>
|
<file>resources/sound/forbidden.wav</file>
|
||||||
<file>resources/sound/loss.wav</file>
|
<file>resources/sound/loss.wav</file>
|
||||||
|
@ -66,8 +66,8 @@
|
||||||
<file>resources/sound/warning.wav</file>
|
<file>resources/sound/warning.wav</file>
|
||||||
<file>resources/sound/BlockMill_B.wav</file>
|
<file>resources/sound/BlockMill_B.wav</file>
|
||||||
<file>resources/sound/BlockMill_W.wav</file>
|
<file>resources/sound/BlockMill_W.wav</file>
|
||||||
<file>resources/sound/Capture_B.wav</file>
|
<file>resources/sound/Remove_B.wav</file>
|
||||||
<file>resources/sound/Capture_W.wav</file>
|
<file>resources/sound/Remove_W.wav</file>
|
||||||
<file>resources/sound/Draw.wav</file>
|
<file>resources/sound/Draw.wav</file>
|
||||||
<file>resources/sound/GameStart.wav</file>
|
<file>resources/sound/GameStart.wav</file>
|
||||||
<file>resources/sound/Mill_B.wav</file>
|
<file>resources/sound/Mill_B.wav</file>
|
||||||
|
|
|
@ -140,7 +140,7 @@
|
||||||
//#define DONOT_PLAY_WIN_SOUND
|
//#define DONOT_PLAY_WIN_SOUND
|
||||||
|
|
||||||
// 摆棋阶段在叉下面显示被吃的子
|
// 摆棋阶段在叉下面显示被吃的子
|
||||||
//#define GAME_PLACING_SHOW_CAPTURED_PIECES
|
//#define GAME_PLACING_SHOW_REMOVED_PIECES
|
||||||
|
|
||||||
// 启动时窗口最大化
|
// 启动时窗口最大化
|
||||||
//#define SHOW_MAXIMIZED_ON_LOAD
|
//#define SHOW_MAXIMIZED_ON_LOAD
|
||||||
|
|
|
@ -455,7 +455,7 @@
|
||||||
</Image>
|
</Image>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Media Include="resources\sound\choose.wav">
|
<Media Include="resources\sound\Select.wav">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Media>
|
</Media>
|
||||||
<Media Include="resources\sound\drog.wav">
|
<Media Include="resources\sound\drog.wav">
|
||||||
|
@ -485,10 +485,10 @@
|
||||||
<Media Include="resources\sound\BlockMill_W.wav">
|
<Media Include="resources\sound\BlockMill_W.wav">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Media>
|
</Media>
|
||||||
<Media Include="resources\sound\Capture_B.wav">
|
<Media Include="resources\sound\Remove_B.wav">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Media>
|
</Media>
|
||||||
<Media Include="resources\sound\Capture_W.wav">
|
<Media Include="resources\sound\Remove_W.wav">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Media>
|
</Media>
|
||||||
<Media Include="resources\sound\Draw.wav">
|
<Media Include="resources\sound\Draw.wav">
|
||||||
|
|
|
@ -44,12 +44,12 @@ value_t Evaluation::getValue(Position *position)
|
||||||
|
|
||||||
switch (position->action) {
|
switch (position->action) {
|
||||||
// 选子和落子使用相同的评价方法
|
// 选子和落子使用相同的评价方法
|
||||||
case ACTION_CHOOSE:
|
case ACTION_SELECT:
|
||||||
case ACTION_PLACE:
|
case ACTION_PLACE:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 如果形成去子状态,每有一个可去的子,算100分
|
// 如果形成去子状态,每有一个可去的子,算100分
|
||||||
case ACTION_CAPTURE:
|
case ACTION_REMOVE:
|
||||||
nPiecesNeedRemove = (position->sideToMove == PLAYER_BLACK) ?
|
nPiecesNeedRemove = (position->sideToMove == PLAYER_BLACK) ?
|
||||||
position->nPiecesNeedRemove : -(position->nPiecesNeedRemove);
|
position->nPiecesNeedRemove : -(position->nPiecesNeedRemove);
|
||||||
value += nPiecesNeedRemove * VALUE_EACH_PIECE_PLACING_NEEDREMOVE;
|
value += nPiecesNeedRemove * VALUE_EACH_PIECE_PLACING_NEEDREMOVE;
|
||||||
|
@ -72,12 +72,12 @@ value_t Evaluation::getValue(Position *position)
|
||||||
|
|
||||||
switch (position->action) {
|
switch (position->action) {
|
||||||
// 选子和落子使用相同的评价方法
|
// 选子和落子使用相同的评价方法
|
||||||
case ACTION_CHOOSE:
|
case ACTION_SELECT:
|
||||||
case ACTION_PLACE:
|
case ACTION_PLACE:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 如果形成去子状态,每有一个可去的子,算128分
|
// 如果形成去子状态,每有一个可去的子,算128分
|
||||||
case ACTION_CAPTURE:
|
case ACTION_REMOVE:
|
||||||
nPiecesNeedRemove = (position->sideToMove == PLAYER_BLACK) ?
|
nPiecesNeedRemove = (position->sideToMove == PLAYER_BLACK) ?
|
||||||
position->nPiecesNeedRemove : -(position->nPiecesNeedRemove);
|
position->nPiecesNeedRemove : -(position->nPiecesNeedRemove);
|
||||||
value += nPiecesNeedRemove * VALUE_EACH_PIECE_MOVING_NEEDREMOVE;
|
value += nPiecesNeedRemove * VALUE_EACH_PIECE_MOVING_NEEDREMOVE;
|
||||||
|
@ -101,7 +101,7 @@ value_t Evaluation::getValue(Position *position)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 走棋阶段被闷判断
|
// 走棋阶段被闷判断
|
||||||
else if (position->action == ACTION_CHOOSE &&
|
else if (position->action == ACTION_SELECT &&
|
||||||
position->board.isAllSurrounded(position->sideId, position->nPiecesOnBoard, position->sideToMove) &&
|
position->board.isAllSurrounded(position->sideId, position->nPiecesOnBoard, position->sideToMove) &&
|
||||||
rule.isLoseWhenNoWay) {
|
rule.isLoseWhenNoWay) {
|
||||||
// 规则要求被“闷”判负,则对手获胜
|
// 规则要求被“闷”判负,则对手获胜
|
||||||
|
|
|
@ -308,7 +308,7 @@ ExtMove *generate(/* TODO: const */ Position *position, ExtMove *moveList)
|
||||||
// 列出所有合法的下一招
|
// 列出所有合法的下一招
|
||||||
switch (position->action) {
|
switch (position->action) {
|
||||||
// 对于选子和落子动作
|
// 对于选子和落子动作
|
||||||
case ACTION_CHOOSE:
|
case ACTION_SELECT:
|
||||||
case ACTION_PLACE:
|
case ACTION_PLACE:
|
||||||
// 对于摆子阶段
|
// 对于摆子阶段
|
||||||
if (position->phase & (PHASE_PLACING | PHASE_READY)) {
|
if (position->phase & (PHASE_PLACING | PHASE_READY)) {
|
||||||
|
@ -348,7 +348,7 @@ ExtMove *generate(/* TODO: const */ Position *position, ExtMove *moveList)
|
||||||
for (int i = Board::MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
for (int i = Board::MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||||
oldSquare = static_cast<square_t>(MoveList::movePriorityTable[i]);
|
oldSquare = static_cast<square_t>(MoveList::movePriorityTable[i]);
|
||||||
|
|
||||||
if (!position->choose(oldSquare)) {
|
if (!position->selectPiece(oldSquare)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,7 +377,7 @@ ExtMove *generate(/* TODO: const */ Position *position, ExtMove *moveList)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 对于吃子动作
|
// 对于吃子动作
|
||||||
case ACTION_CAPTURE:
|
case ACTION_REMOVE:
|
||||||
opponent = Player::getOpponent(position->sideToMove);
|
opponent = Player::getOpponent(position->sideToMove);
|
||||||
|
|
||||||
if (position->board.isAllInMills(opponent)) {
|
if (position->board.isAllInMills(opponent)) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ void MovePicker::score()
|
||||||
|
|
||||||
#ifdef SORT_MOVE_WITH_HUMAN_KNOWLEDGES
|
#ifdef SORT_MOVE_WITH_HUMAN_KNOWLEDGES
|
||||||
// TODO: rule.allowRemoveMultiPieces 以及 适配打三棋之外的其他规则
|
// TODO: rule.allowRemoveMultiPieces 以及 适配打三棋之外的其他规则
|
||||||
if (type_of(m) != MOVETYPE_CAPTURE) {
|
if (type_of(m) != MOVETYPE_REMOVE) {
|
||||||
// 在任何阶段, 都检测落子点是否能使得本方成三
|
// 在任何阶段, 都检测落子点是否能使得本方成三
|
||||||
if (nMills > 0) {
|
if (nMills > 0) {
|
||||||
#ifdef ALPHABETA_AI
|
#ifdef ALPHABETA_AI
|
||||||
|
@ -108,7 +108,7 @@ void MovePicker::score()
|
||||||
cur->rating += RATING_STAR_SQUARE;
|
cur->rating += RATING_STAR_SQUARE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else { // Capture
|
} else { // Remove
|
||||||
int nPlayerPiece = 0;
|
int nPlayerPiece = 0;
|
||||||
int nOpponentPiece = 0;
|
int nOpponentPiece = 0;
|
||||||
int nForbidden = 0;
|
int nForbidden = 0;
|
||||||
|
@ -120,7 +120,7 @@ void MovePicker::score()
|
||||||
#ifdef ALPHABETA_AI
|
#ifdef ALPHABETA_AI
|
||||||
if (nMills > 0) {
|
if (nMills > 0) {
|
||||||
// 吃子点处于我方的三连中
|
// 吃子点处于我方的三连中
|
||||||
//newNode->rating += static_cast<rating_t>(RATING_CAPTURE_ONE_MILL * nMills);
|
//newNode->rating += static_cast<rating_t>(RATING_REMOVE_ONE_MILL * nMills);
|
||||||
|
|
||||||
if (nOpponentPiece == 0) {
|
if (nOpponentPiece == 0) {
|
||||||
// 吃子点旁边没有对方棋子则优先考虑
|
// 吃子点旁边没有对方棋子则优先考虑
|
||||||
|
@ -203,7 +203,7 @@ void MovePicker::clearHistoryScore()
|
||||||
{
|
{
|
||||||
#ifndef HOSTORY_HEURISTIC_ACTION_MOVE_ONLY
|
#ifndef HOSTORY_HEURISTIC_ACTION_MOVE_ONLY
|
||||||
memset(placeHistory, 0, sizeof(placeHistory));
|
memset(placeHistory, 0, sizeof(placeHistory));
|
||||||
memset(captureHistory, 0, sizeof(captureHistory));
|
memset(removeHistory, 0, sizeof(removeHistory));
|
||||||
#endif
|
#endif
|
||||||
memset(moveHistory, 0, sizeof(moveHistory));
|
memset(moveHistory, 0, sizeof(moveHistory));
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
#ifdef HOSTORY_HEURISTIC
|
#ifdef HOSTORY_HEURISTIC
|
||||||
// TODO: Fix size
|
// TODO: Fix size
|
||||||
score_t placeHistory[64];
|
score_t placeHistory[64];
|
||||||
score_t captureHistory[64];
|
score_t removeHistory[64];
|
||||||
score_t moveHistory[10240];
|
score_t moveHistory[10240];
|
||||||
|
|
||||||
score_t getHistoryScore(move_t move);
|
score_t getHistoryScore(move_t move);
|
||||||
|
|
|
@ -619,7 +619,7 @@ const char* AIAlgorithm::nextMove()
|
||||||
return moveToCommand(bestMove);
|
return moveToCommand(bestMove);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
char charChoose = '*';
|
char charSelect = '*';
|
||||||
|
|
||||||
Board::printBoard();
|
Board::printBoard();
|
||||||
|
|
||||||
|
@ -629,9 +629,9 @@ const char* AIAlgorithm::nextMove()
|
||||||
int cs = root->childrenSize;
|
int cs = root->childrenSize;
|
||||||
for (int i = 0; i < cs; i++) {
|
for (int i = 0; i < cs; i++) {
|
||||||
if (root->children[i]->move != bestMove) {
|
if (root->children[i]->move != bestMove) {
|
||||||
charChoose = ' ';
|
charSelect = ' ';
|
||||||
} else {
|
} else {
|
||||||
charChoose = '*';
|
charSelect = '*';
|
||||||
foundBest = true;
|
foundBest = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,7 +645,7 @@ const char* AIAlgorithm::nextMove()
|
||||||
#else
|
#else
|
||||||
0,
|
0,
|
||||||
#endif
|
#endif
|
||||||
charChoose);
|
charSelect);
|
||||||
|
|
||||||
moveIndex++;
|
moveIndex++;
|
||||||
}
|
}
|
||||||
|
@ -698,13 +698,15 @@ const char* AIAlgorithm::nextMove()
|
||||||
|
|
||||||
const char *AIAlgorithm::moveToCommand(move_t move)
|
const char *AIAlgorithm::moveToCommand(move_t move)
|
||||||
{
|
{
|
||||||
int rto, sto;
|
ring_t rto;
|
||||||
|
seat_t sto;
|
||||||
Board::squareToPolar(to_sq(move), rto, sto);
|
Board::squareToPolar(to_sq(move), rto, sto);
|
||||||
|
|
||||||
if (move < 0) {
|
if (move < 0) {
|
||||||
sprintf(cmdline, "-(%1u,%1u)", rto, sto);
|
sprintf(cmdline, "-(%1u,%1u)", rto, sto);
|
||||||
} else if (move & 0x7f00) {
|
} else if (move & 0x7f00) {
|
||||||
int rfrom, sfrom;
|
ring_t rfrom;
|
||||||
|
seat_t sfrom;
|
||||||
Board::squareToPolar(from_sq(move), rfrom, sfrom);
|
Board::squareToPolar(from_sq(move), rfrom, sfrom);
|
||||||
sprintf(cmdline, "(%1u,%1u)->(%1u,%1u)", rfrom, sfrom, rto, sto);
|
sprintf(cmdline, "(%1u,%1u)->(%1u,%1u)", rfrom, sfrom, rto, sto);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -184,15 +184,15 @@ void Board::createMillTable()
|
||||||
#endif /* DEBUG_MODE */
|
#endif /* DEBUG_MODE */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::squareToPolar(const square_t square, int &r, int &s)
|
void Board::squareToPolar(const square_t square, ring_t &r, seat_t &s)
|
||||||
{
|
{
|
||||||
//r = square / N_SEATS;
|
//r = square / N_SEATS;
|
||||||
//s = square % N_SEATS + 1;
|
//s = square % N_SEATS + 1;
|
||||||
r = square >> 3;
|
r = ring_t(square >> 3);
|
||||||
s = (square & 0x07) + 1;
|
s = seat_t((square & 0x07) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
square_t Board::polarToSquare(int r, int s)
|
square_t Board::polarToSquare(ring_t r, seat_t s)
|
||||||
{
|
{
|
||||||
assert(!(r < 1 || r > N_RINGS || s < 1 || s > N_SEATS));
|
assert(!(r < 1 || r > N_RINGS || s < 1 || s > N_SEATS));
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ player_t Board::locationToPlayer(square_t square)
|
||||||
return player_t(locations[square] & 0x30);
|
return player_t(locations[square] & 0x30);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Board::inHowManyMills(square_t square, player_t player, square_t squareChoose)
|
int Board::inHowManyMills(square_t square, player_t player, square_t squareSelected)
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
location_t locbak = SQ_0;
|
location_t locbak = SQ_0;
|
||||||
|
@ -213,9 +213,9 @@ int Board::inHowManyMills(square_t square, player_t player, square_t squareChoos
|
||||||
player = locationToPlayer(square);
|
player = locationToPlayer(square);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareChoose != SQ_0) {
|
if (squareSelected != SQ_0) {
|
||||||
locbak = locations[squareChoose];
|
locbak = locations[squareSelected];
|
||||||
locations[squareChoose] = 0;
|
locations[squareSelected] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int l = 0; l < LINE_TYPES_COUNT; l++) {
|
for (int l = 0; l < LINE_TYPES_COUNT; l++) {
|
||||||
|
@ -226,8 +226,8 @@ int Board::inHowManyMills(square_t square, player_t player, square_t squareChoos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareChoose != SQ_0) {
|
if (squareSelected != SQ_0) {
|
||||||
locations[squareChoose] = locbak;
|
locations[squareSelected] = locbak;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
void rotate(int degrees, vector<string> &cmdlist, char *cmdline, int32_t move_, square_t square, bool cmdChange = true);
|
void rotate(int degrees, vector<string> &cmdlist, char *cmdline, int32_t move_, square_t square, bool cmdChange = true);
|
||||||
|
|
||||||
// 判断棋盘 square 处的棋子处于几个“三连”中
|
// 判断棋盘 square 处的棋子处于几个“三连”中
|
||||||
int inHowManyMills(square_t square, player_t player, square_t squareChoose = SQ_0);
|
int inHowManyMills(square_t square, player_t player, square_t squareSelected = SQ_0);
|
||||||
|
|
||||||
// 判断玩家的所有棋子是否都处于“三连”状态
|
// 判断玩家的所有棋子是否都处于“三连”状态
|
||||||
bool isAllInMills(player_t);
|
bool isAllInMills(player_t);
|
||||||
|
@ -87,10 +87,10 @@ public:
|
||||||
int addMills(square_t square);
|
int addMills(square_t square);
|
||||||
|
|
||||||
// 将棋盘下标形式转化为第r圈,第s位,r和s下标都从1开始
|
// 将棋盘下标形式转化为第r圈,第s位,r和s下标都从1开始
|
||||||
static void squareToPolar(square_t square, int &r, int &s);
|
static void squareToPolar(square_t square, ring_t &r, seat_t &s);
|
||||||
|
|
||||||
// 将第c圈,第p位转化为棋盘下标形式,r和s下标都从1开始
|
// 将第c圈,第p位转化为棋盘下标形式,r和s下标都从1开始
|
||||||
static square_t polarToSquare(int r, int s);
|
static square_t polarToSquare(ring_t r, seat_t s);
|
||||||
|
|
||||||
static void printBoard();
|
static void printBoard();
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,7 @@ bool Position::setPosition(const struct Rule *newRule,
|
||||||
countPiecesInHand();
|
countPiecesInHand();
|
||||||
|
|
||||||
// 设置去子状态时的剩余尚待去除子数
|
// 设置去子状态时的剩余尚待去除子数
|
||||||
if (action == ACTION_CAPTURE) {
|
if (action == ACTION_REMOVE) {
|
||||||
if (0 <= piecesNeedRemove && piecesNeedRemove < 3) {
|
if (0 <= piecesNeedRemove && piecesNeedRemove < 3) {
|
||||||
nPiecesNeedRemove = piecesNeedRemove;
|
nPiecesNeedRemove = piecesNeedRemove;
|
||||||
}
|
}
|
||||||
|
@ -372,7 +372,7 @@ bool Position::start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Position::place(square_t square, int8_t updateCmdlist)
|
bool Position::placePiece(square_t square, bool updateCmdlist)
|
||||||
{
|
{
|
||||||
// 如果局面为“结局”,返回false
|
// 如果局面为“结局”,返回false
|
||||||
if (phase == PHASE_GAMEOVER)
|
if (phase == PHASE_GAMEOVER)
|
||||||
|
@ -391,8 +391,8 @@ bool Position::place(square_t square, int8_t updateCmdlist)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 格式转换
|
// 格式转换
|
||||||
int r = 0;
|
ring_t r;
|
||||||
int s = 0;
|
seat_t s;
|
||||||
Board::squareToPolar(square, r, s);
|
Board::squareToPolar(square, r, s);
|
||||||
|
|
||||||
// 时间的临时变量
|
// 时间的临时变量
|
||||||
|
@ -441,7 +441,7 @@ bool Position::place(square_t square, int8_t updateCmdlist)
|
||||||
phase = PHASE_MOVING;
|
phase = PHASE_MOVING;
|
||||||
|
|
||||||
// 进入选子状态
|
// 进入选子状态
|
||||||
action = ACTION_CHOOSE;
|
action = ACTION_SELECT;
|
||||||
|
|
||||||
// 清除禁点
|
// 清除禁点
|
||||||
cleanForbiddenLocations();
|
cleanForbiddenLocations();
|
||||||
|
@ -470,7 +470,7 @@ bool Position::place(square_t square, int8_t updateCmdlist)
|
||||||
nPiecesNeedRemove = rule.allowRemoveMultiPieces ? n : 1;
|
nPiecesNeedRemove = rule.allowRemoveMultiPieces ? n : 1;
|
||||||
|
|
||||||
// 进入去子状态
|
// 进入去子状态
|
||||||
action = ACTION_CAPTURE;
|
action = ACTION_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -523,7 +523,7 @@ bool Position::place(square_t square, int8_t updateCmdlist)
|
||||||
// 中局阶段未成三
|
// 中局阶段未成三
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
// 进入选子状态
|
// 进入选子状态
|
||||||
action = ACTION_CHOOSE;
|
action = ACTION_SELECT;
|
||||||
|
|
||||||
// 设置轮到谁走
|
// 设置轮到谁走
|
||||||
changeSideToMove();
|
changeSideToMove();
|
||||||
|
@ -539,7 +539,7 @@ bool Position::place(square_t square, int8_t updateCmdlist)
|
||||||
nPiecesNeedRemove = rule.allowRemoveMultiPieces ? n : 1;
|
nPiecesNeedRemove = rule.allowRemoveMultiPieces ? n : 1;
|
||||||
|
|
||||||
// 进入去子状态
|
// 进入去子状态
|
||||||
action = ACTION_CAPTURE;
|
action = ACTION_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -550,30 +550,30 @@ out:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Position::_place(int r, int s)
|
bool Position::_placePiece(ring_t r, seat_t s)
|
||||||
{
|
{
|
||||||
// 转换为 square
|
// 转换为 square
|
||||||
square_t square = Board::polarToSquare(r, s);
|
square_t square = Board::polarToSquare(r, s);
|
||||||
|
|
||||||
return place(square, true);
|
return placePiece(square, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Position::_capture(int r, int s)
|
bool Position::_removePiece(ring_t r, seat_t s)
|
||||||
{
|
{
|
||||||
// 转换为 square
|
// 转换为 square
|
||||||
square_t square = Board::polarToSquare(r, s);
|
square_t square = Board::polarToSquare(r, s);
|
||||||
|
|
||||||
return capture(square, 1);
|
return removePiece(square, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Position::capture(square_t square, int8_t updateCmdlist)
|
bool Position::removePiece(square_t square, bool updateCmdlist)
|
||||||
{
|
{
|
||||||
// 如果局面为"未开局"或“结局”,返回false
|
// 如果局面为"未开局"或“结局”,返回false
|
||||||
if (phase & PHASE_NOTPLAYING)
|
if (phase & PHASE_NOTPLAYING)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 如非“去子”状态,返回false
|
// 如非“去子”状态,返回false
|
||||||
if (action != ACTION_CAPTURE)
|
if (action != ACTION_REMOVE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 如果去子完成,返回false
|
// 如果去子完成,返回false
|
||||||
|
@ -581,8 +581,8 @@ bool Position::capture(square_t square, int8_t updateCmdlist)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 格式转换
|
// 格式转换
|
||||||
int r = 0;
|
ring_t r;
|
||||||
int s = 0;
|
seat_t s;
|
||||||
Board::squareToPolar(square, r, s);
|
Board::squareToPolar(square, r, s);
|
||||||
|
|
||||||
// 时间的临时变量
|
// 时间的临时变量
|
||||||
|
@ -649,7 +649,7 @@ bool Position::capture(square_t square, int8_t updateCmdlist)
|
||||||
phase = PHASE_MOVING;
|
phase = PHASE_MOVING;
|
||||||
|
|
||||||
// 进入选子状态
|
// 进入选子状态
|
||||||
action = ACTION_CHOOSE;
|
action = ACTION_SELECT;
|
||||||
|
|
||||||
// 清除禁点
|
// 清除禁点
|
||||||
cleanForbiddenLocations();
|
cleanForbiddenLocations();
|
||||||
|
@ -683,7 +683,7 @@ bool Position::capture(square_t square, int8_t updateCmdlist)
|
||||||
// 中局阶段
|
// 中局阶段
|
||||||
else {
|
else {
|
||||||
// 进入选子状态
|
// 进入选子状态
|
||||||
action = ACTION_CHOOSE;
|
action = ACTION_SELECT;
|
||||||
|
|
||||||
// 设置轮到谁走
|
// 设置轮到谁走
|
||||||
changeSideToMove();
|
changeSideToMove();
|
||||||
|
@ -702,14 +702,14 @@ out:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Position::choose(square_t square)
|
bool Position::selectPiece(square_t square)
|
||||||
{
|
{
|
||||||
// 如果局面不是"中局”,返回false
|
// 如果局面不是"中局”,返回false
|
||||||
if (phase != PHASE_MOVING)
|
if (phase != PHASE_MOVING)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 如非“选子”或“落子”状态,返回false
|
// 如非“选子”或“落子”状态,返回false
|
||||||
if (action != ACTION_CHOOSE && action != ACTION_PLACE)
|
if (action != ACTION_SELECT && action != ACTION_PLACE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 判断选子是否可选
|
// 判断选子是否可选
|
||||||
|
@ -726,9 +726,9 @@ bool Position::choose(square_t square)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Position::choose(int r, int s)
|
bool Position::selectPiece(ring_t r, seat_t s)
|
||||||
{
|
{
|
||||||
return choose(Board::polarToSquare(r, s));
|
return selectPiece(Board::polarToSquare(r, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Position::giveup(player_t loser)
|
bool Position::giveup(player_t loser)
|
||||||
|
@ -760,7 +760,8 @@ bool Position::command(const char *cmd)
|
||||||
int r;
|
int r;
|
||||||
unsigned t;
|
unsigned t;
|
||||||
step_t s;
|
step_t s;
|
||||||
int r1, s1, r2, s2;
|
ring_t r1, r2;
|
||||||
|
seat_t s1, s2;
|
||||||
int args = 0;
|
int args = 0;
|
||||||
int mm = 0, ss = 0;
|
int mm = 0, ss = 0;
|
||||||
|
|
||||||
|
@ -782,8 +783,8 @@ bool Position::command(const char *cmd)
|
||||||
tm = mm * 60 + ss;
|
tm = mm * 60 + ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (choose(r1, s1)) {
|
if (selectPiece(r1, s1)) {
|
||||||
return _place(r2, s2);
|
return _placePiece(r2, s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -796,7 +797,7 @@ bool Position::command(const char *cmd)
|
||||||
if (mm >= 0 && ss >= 0)
|
if (mm >= 0 && ss >= 0)
|
||||||
tm = mm * 60 + ss;
|
tm = mm * 60 + ss;
|
||||||
}
|
}
|
||||||
return _capture(r1, s1);
|
return _removePiece(r1, s1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 落子
|
// 落子
|
||||||
|
@ -806,7 +807,7 @@ bool Position::command(const char *cmd)
|
||||||
if (mm >= 0 && ss >= 0)
|
if (mm >= 0 && ss >= 0)
|
||||||
tm = mm * 60 + ss;
|
tm = mm * 60 + ss;
|
||||||
}
|
}
|
||||||
return _place(r1, s1);
|
return _placePiece(r1, s1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 认输
|
// 认输
|
||||||
|
@ -840,14 +841,14 @@ bool Position::doMove(move_t m)
|
||||||
movetype_t mt = type_of(m);
|
movetype_t mt = type_of(m);
|
||||||
|
|
||||||
switch (mt) {
|
switch (mt) {
|
||||||
case MOVETYPE_CAPTURE:
|
case MOVETYPE_REMOVE:
|
||||||
return capture(static_cast<square_t>(-m));
|
return removePiece(static_cast<square_t>(-m));
|
||||||
case MOVETYPE_MOVE:
|
case MOVETYPE_MOVE:
|
||||||
if (choose(from_sq(m))) {
|
if (selectPiece(from_sq(m))) {
|
||||||
return place(to_sq(m));
|
return placePiece(to_sq(m));
|
||||||
}
|
}
|
||||||
case MOVETYPE_PLACE:
|
case MOVETYPE_PLACE:
|
||||||
return place(to_sq(m));
|
return placePiece(to_sq(m));
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -995,7 +996,7 @@ bool Position::checkGameOverCondition(int8_t updateCmdlist)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果中局被“闷”
|
// 如果中局被“闷”
|
||||||
if (phase == PHASE_MOVING && action == ACTION_CHOOSE && board.isAllSurrounded(sideId, nPiecesOnBoard, sideToMove)) {
|
if (phase == PHASE_MOVING && action == ACTION_SELECT && board.isAllSurrounded(sideId, nPiecesOnBoard, sideToMove)) {
|
||||||
// 规则要求被“闷”判负,则对手获胜 // TODO: 应该转移到下面的分支中
|
// 规则要求被“闷”判负,则对手获胜 // TODO: 应该转移到下面的分支中
|
||||||
phase = PHASE_GAMEOVER;
|
phase = PHASE_GAMEOVER;
|
||||||
|
|
||||||
|
@ -1116,15 +1117,15 @@ void Position::setTips()
|
||||||
case PHASE_PLACING:
|
case PHASE_PLACING:
|
||||||
if (action == ACTION_PLACE) {
|
if (action == ACTION_PLACE) {
|
||||||
tips = "轮到玩家" + turnStr + "落子,剩余" + std::to_string(nPiecesInHand[sideId]) + "子";
|
tips = "轮到玩家" + turnStr + "落子,剩余" + std::to_string(nPiecesInHand[sideId]) + "子";
|
||||||
} else if (action == ACTION_CAPTURE) {
|
} else if (action == ACTION_REMOVE) {
|
||||||
tips = "成三!轮到玩家" + turnStr + "去子,需去" + std::to_string(nPiecesNeedRemove) + "子";
|
tips = "成三!轮到玩家" + turnStr + "去子,需去" + std::to_string(nPiecesNeedRemove) + "子";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PHASE_MOVING:
|
case PHASE_MOVING:
|
||||||
if (action == ACTION_PLACE || action == ACTION_CHOOSE) {
|
if (action == ACTION_PLACE || action == ACTION_SELECT) {
|
||||||
tips = "轮到玩家" + turnStr + "选子移动";
|
tips = "轮到玩家" + turnStr + "选子移动";
|
||||||
} else if (action == ACTION_CAPTURE) {
|
} else if (action == ACTION_REMOVE) {
|
||||||
tips = "成三!轮到玩家" + turnStr + "去子,需去" + std::to_string(nPiecesNeedRemove) + "子";
|
tips = "成三!轮到玩家" + turnStr + "去子,需去" + std::to_string(nPiecesNeedRemove) + "子";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1204,7 +1205,7 @@ hash_t Position::updateHashMisc()
|
||||||
hi |= 1U;
|
hi |= 1U;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == ACTION_CAPTURE) {
|
if (action == ACTION_REMOVE) {
|
||||||
hi |= 1U << 1;
|
hi |= 1U << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1222,7 +1223,7 @@ hash_t Position::getNextMainHash(move_t m)
|
||||||
square_t sq = static_cast<square_t>(to_sq(m));;
|
square_t sq = static_cast<square_t>(to_sq(m));;
|
||||||
movetype_t mt = type_of(m);
|
movetype_t mt = type_of(m);
|
||||||
|
|
||||||
if (mt == MOVETYPE_CAPTURE) {
|
if (mt == MOVETYPE_REMOVE) {
|
||||||
int pieceType = Player::getOpponentById(Player::toId(sideToMove));
|
int pieceType = Player::getOpponentById(Player::toId(sideToMove));
|
||||||
nextMainHash ^= zobrist[sq][pieceType];
|
nextMainHash ^= zobrist[sq][pieceType];
|
||||||
|
|
||||||
|
|
|
@ -191,15 +191,6 @@ public:
|
||||||
// 游戏开始
|
// 游戏开始
|
||||||
bool start();
|
bool start();
|
||||||
|
|
||||||
// 选子,在第r圈第s个位置,为迎合日常,r和s下标都从1开始
|
|
||||||
bool choose(int r, int s);
|
|
||||||
|
|
||||||
// 落子,在第r圈第s个位置,为迎合日常,r和s下标都从1开始
|
|
||||||
bool _place(int r, int s);
|
|
||||||
|
|
||||||
// 去子,在第r圈第s个位置,为迎合日常,r和s下标都从1开始
|
|
||||||
bool _capture(int r, int s);
|
|
||||||
|
|
||||||
// 认输
|
// 认输
|
||||||
bool giveup(player_t loser);
|
bool giveup(player_t loser);
|
||||||
|
|
||||||
|
@ -236,11 +227,20 @@ public:
|
||||||
// 判断胜负
|
// 判断胜负
|
||||||
player_t getWinner() const;
|
player_t getWinner() const;
|
||||||
|
|
||||||
|
// 选子,在第r圈第s个位置,为迎合日常,r和s下标都从1开始
|
||||||
|
bool selectPiece(ring_t r, seat_t s);
|
||||||
|
|
||||||
|
// 落子,在第r圈第s个位置,为迎合日常,r和s下标都从1开始
|
||||||
|
bool _placePiece(ring_t r, seat_t s);
|
||||||
|
|
||||||
|
// 去子,在第r圈第s个位置,为迎合日常,r和s下标都从1开始
|
||||||
|
bool _removePiece(ring_t r, seat_t s);
|
||||||
|
|
||||||
// 下面几个函数没有算法无关判断和无关操作,节约算法时间
|
// 下面几个函数没有算法无关判断和无关操作,节约算法时间
|
||||||
bool doMove(move_t move);
|
bool doMove(move_t move);
|
||||||
bool choose(square_t square);
|
bool selectPiece(square_t square);
|
||||||
bool place(square_t square, int8_t cp = 0);
|
bool placePiece(square_t square, bool updateCmdlist = false);
|
||||||
bool capture(square_t square, int8_t cp = 0);
|
bool removePiece(square_t square, bool updateCmdlist = false);
|
||||||
|
|
||||||
// hash 相关
|
// hash 相关
|
||||||
hash_t getPosKey();
|
hash_t getPosKey();
|
||||||
|
|
|
@ -45,7 +45,7 @@ enum movetype_t
|
||||||
{
|
{
|
||||||
MOVETYPE_PLACE,
|
MOVETYPE_PLACE,
|
||||||
MOVETYPE_MOVE,
|
MOVETYPE_MOVE,
|
||||||
MOVETYPE_CAPTURE
|
MOVETYPE_REMOVE
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr int MAX_MOVES = 40;
|
constexpr int MAX_MOVES = 40;
|
||||||
|
@ -177,13 +177,13 @@ enum rating_t : int8_t
|
||||||
RATING_BLOCK_THREE_MILLS = RATING_BLOCK_ONE_MILL * 3,
|
RATING_BLOCK_THREE_MILLS = RATING_BLOCK_ONE_MILL * 3,
|
||||||
RATING_THREE_MILLS = RATING_ONE_MILL * 3,
|
RATING_THREE_MILLS = RATING_ONE_MILL * 3,
|
||||||
|
|
||||||
RATING_CAPTURE_ONE_MILL = RATING_ONE_MILL,
|
RATING_REMOVE_ONE_MILL = RATING_ONE_MILL,
|
||||||
RATING_CAPTURE_TWO_MILLS = RATING_TWO_MILLS,
|
RATING_REMOVE_TWO_MILLS = RATING_TWO_MILLS,
|
||||||
RATING_CAPTURE_THREE_MILLS = RATING_THREE_MILLS,
|
RATING_REMOVE_THREE_MILLS = RATING_THREE_MILLS,
|
||||||
|
|
||||||
RATING_CAPTURE_OPPONENT_ONE_MILL = -RATING_CAPTURE_ONE_MILL,
|
RATING_REMOVE_OPPONENT_ONE_MILL = -RATING_REMOVE_ONE_MILL,
|
||||||
RATING_CAPTURE_OPPONENT_TWO_MILLS = -RATING_CAPTURE_TWO_MILLS,
|
RATING_REMOVE_OPPONENT_TWO_MILLS = -RATING_REMOVE_TWO_MILLS,
|
||||||
RATING_CAPTURE_OPPONENT_THREE_MILLS = -RATING_CAPTURE_THREE_MILLS,
|
RATING_REMOVE_OPPONENT_THREE_MILLS = -RATING_REMOVE_THREE_MILLS,
|
||||||
|
|
||||||
RATING_TT = 100,
|
RATING_TT = 100,
|
||||||
RATING_MAX = std::numeric_limits<int8_t>::max(),
|
RATING_MAX = std::numeric_limits<int8_t>::max(),
|
||||||
|
@ -243,9 +243,9 @@ enum piece_t
|
||||||
enum action_t : uint16_t
|
enum action_t : uint16_t
|
||||||
{
|
{
|
||||||
ACTION_NONE = 0x0000,
|
ACTION_NONE = 0x0000,
|
||||||
ACTION_CHOOSE = 0x0100, // 选子
|
ACTION_SELECT = 0x0100, // 选子
|
||||||
ACTION_PLACE = 0x0200, // 落子
|
ACTION_PLACE = 0x0200, // 落子
|
||||||
ACTION_CAPTURE = 0x0400 // 提子
|
ACTION_REMOVE = 0x0400 // 提子
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ENABLE_BASE_OPERATORS_ON(T) \
|
#define ENABLE_BASE_OPERATORS_ON(T) \
|
||||||
|
@ -339,7 +339,7 @@ inline const square_t to_sq(move_t m)
|
||||||
inline const movetype_t type_of(move_t m)
|
inline const movetype_t type_of(move_t m)
|
||||||
{
|
{
|
||||||
if (m < 0) {
|
if (m < 0) {
|
||||||
return MOVETYPE_CAPTURE;
|
return MOVETYPE_REMOVE;
|
||||||
} else if (m & 0x1f00) {
|
} else if (m & 0x1f00) {
|
||||||
return MOVETYPE_MOVE;
|
return MOVETYPE_MOVE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "boarditem.h"
|
#include "boarditem.h"
|
||||||
#include "graphicsconst.h"
|
#include "graphicsconst.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
BoardItem::BoardItem(QGraphicsItem *parent) :
|
BoardItem::BoardItem(QGraphicsItem *parent) :
|
||||||
size(BOARD_SIZE)
|
size(BOARD_SIZE)
|
||||||
|
@ -169,19 +170,19 @@ QPointF BoardItem::nearestPosition(QPointF const pos)
|
||||||
return nearestPos;
|
return nearestPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF BoardItem::rs2pos(int r, int s)
|
QPointF BoardItem::rs2pos(ring_t r, seat_t s)
|
||||||
{
|
{
|
||||||
return position[(r - 1) * N_SEATS + s - 1]; // TODO: 为什么是 r - 1 和算法部分不一样?
|
return position[((int)r - 1) * N_SEATS + (int)s - 1]; // TODO: 为什么是 r - 1 和算法部分不一样?
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BoardItem::pos2rs(QPointF pos, int &r, int &s)
|
bool BoardItem::pos2rs(QPointF pos, ring_t &r, seat_t &s)
|
||||||
{
|
{
|
||||||
// 寻找最近的落子点
|
// 寻找最近的落子点
|
||||||
for (int i = 0; i < N_RINGS * N_SEATS; i++) {
|
for (int i = 0; i < N_RINGS * N_SEATS; i++) {
|
||||||
// 如果pos点在落子点附近
|
// 如果pos点在落子点附近
|
||||||
if (QLineF(pos, position[i]).length() < PIECE_SIZE / 6) {
|
if (QLineF(pos, position[i]).length() < PIECE_SIZE / 6) {
|
||||||
r = i / N_SEATS + 1;
|
r = ring_t(i / N_SEATS + 1);
|
||||||
s = i % N_SEATS + 1;
|
s = seat_t(i % N_SEATS + 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
class BoardItem : public QGraphicsItem
|
class BoardItem : public QGraphicsItem
|
||||||
{
|
{
|
||||||
|
@ -56,10 +57,10 @@ public:
|
||||||
QPointF nearestPosition(QPointF pos);
|
QPointF nearestPosition(QPointF pos);
|
||||||
|
|
||||||
// 将模型的圈、位转化为落子点坐标
|
// 将模型的圈、位转化为落子点坐标
|
||||||
QPointF rs2pos(int r, int s);
|
QPointF rs2pos(ring_t r, seat_t s);
|
||||||
|
|
||||||
// 将落子点坐标转化为模型用的圈、位
|
// 将落子点坐标转化为模型用的圈、位
|
||||||
bool pos2rs(QPointF pos, int &r, int &s);
|
bool pos2rs(QPointF pos, ring_t &r, seat_t &s);
|
||||||
|
|
||||||
// 3圈,禁止修改!
|
// 3圈,禁止修改!
|
||||||
static const uint8_t N_RINGS = 3;
|
static const uint8_t N_RINGS = 3;
|
||||||
|
|
|
@ -408,11 +408,11 @@ void GameController::playSound(sound_t soundType, player_t player)
|
||||||
case GAME_SOUND_BLOCK_MILL:
|
case GAME_SOUND_BLOCK_MILL:
|
||||||
filename = "BlockMill_" + sideStr + ".wav";
|
filename = "BlockMill_" + sideStr + ".wav";
|
||||||
break;
|
break;
|
||||||
case GAME_SOUND_CAPTURE:
|
case GAME_SOUND_REMOVE:
|
||||||
filename = "Capture_" + oppenentStr + ".wav";
|
filename = "Remove_" + oppenentStr + ".wav";
|
||||||
break;
|
break;
|
||||||
case GAME_SOUND_CHOOSE:
|
case GAME_SOUND_SELECT:
|
||||||
filename = "choose.wav";
|
filename = "Select.wav";
|
||||||
break;
|
break;
|
||||||
case GAME_SOUND_DRAW:
|
case GAME_SOUND_DRAW:
|
||||||
filename = "Draw.wav";
|
filename = "Draw.wav";
|
||||||
|
@ -450,9 +450,6 @@ void GameController::playSound(sound_t soundType, player_t player)
|
||||||
case GAME_SOUND_OBVIOUS:
|
case GAME_SOUND_OBVIOUS:
|
||||||
filename = "Obvious.wav";
|
filename = "Obvious.wav";
|
||||||
break;
|
break;
|
||||||
case GAME_SOUND_REMOVE:
|
|
||||||
filename = "remove.wav";
|
|
||||||
break;
|
|
||||||
case GAME_SOUND_REPEAT_THREE_DRAW:
|
case GAME_SOUND_REPEAT_THREE_DRAW:
|
||||||
filename = "RepeatThreeDraw.wav";
|
filename = "RepeatThreeDraw.wav";
|
||||||
break;
|
break;
|
||||||
|
@ -738,7 +735,9 @@ bool GameController::actionPiece(QPointF pos)
|
||||||
{
|
{
|
||||||
#ifndef TRAINING_MODE
|
#ifndef TRAINING_MODE
|
||||||
// 点击非落子点,不执行
|
// 点击非落子点,不执行
|
||||||
int r, s;
|
ring_t r;
|
||||||
|
seat_t s;
|
||||||
|
|
||||||
if (!scene.pos2rs(pos, r, s)) {
|
if (!scene.pos2rs(pos, r, s)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -795,8 +794,8 @@ bool GameController::actionPiece(QPointF pos)
|
||||||
|
|
||||||
switch (state.position->getAction()) {
|
switch (state.position->getAction()) {
|
||||||
case ACTION_PLACE:
|
case ACTION_PLACE:
|
||||||
if (state.position->_place(r, s)) {
|
if (state.position->_placePiece(r, s)) {
|
||||||
if (state.position->getAction() == ACTION_CAPTURE) {
|
if (state.position->getAction() == ACTION_REMOVE) {
|
||||||
// 播放成三音效
|
// 播放成三音效
|
||||||
playSound(GAME_SOUND_MILL, state.position->getSideToMove());
|
playSound(GAME_SOUND_MILL, state.position->getSideToMove());
|
||||||
} else {
|
} else {
|
||||||
|
@ -810,13 +809,13 @@ bool GameController::actionPiece(QPointF pos)
|
||||||
// 如果移子不成功,尝试重新选子,这里不break
|
// 如果移子不成功,尝试重新选子,这里不break
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
|
|
||||||
case ACTION_CHOOSE:
|
case ACTION_SELECT:
|
||||||
piece = qgraphicsitem_cast<PieceItem *>(item);
|
piece = qgraphicsitem_cast<PieceItem *>(item);
|
||||||
if (!piece)
|
if (!piece)
|
||||||
break;
|
break;
|
||||||
if (state.position->choose(r, s)) {
|
if (state.position->selectPiece(r, s)) {
|
||||||
// 播放选子音效
|
// 播放选子音效
|
||||||
playSound(GAME_SOUND_CHOOSE, state.position->getSideToMove());
|
playSound(GAME_SOUND_SELECT, state.position->getSideToMove());
|
||||||
result = true;
|
result = true;
|
||||||
} else {
|
} else {
|
||||||
// 播放禁止音效
|
// 播放禁止音效
|
||||||
|
@ -824,10 +823,10 @@ bool GameController::actionPiece(QPointF pos)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_CAPTURE:
|
case ACTION_REMOVE:
|
||||||
if (state.position->_capture(r, s)) {
|
if (state.position->_removePiece(r, s)) {
|
||||||
// 播放音效
|
// 播放音效
|
||||||
playSound(GAME_SOUND_CAPTURE, state.position->getSideToMove());
|
playSound(GAME_SOUND_REMOVE, state.position->getSideToMove());
|
||||||
result = true;
|
result = true;
|
||||||
} else {
|
} else {
|
||||||
// 播放禁止音效
|
// 播放禁止音效
|
||||||
|
@ -935,12 +934,12 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
||||||
sound_t soundType = GAME_SOUND_NONE;
|
sound_t soundType = GAME_SOUND_NONE;
|
||||||
|
|
||||||
switch (state.position->getAction()) {
|
switch (state.position->getAction()) {
|
||||||
case ACTION_CHOOSE:
|
case ACTION_SELECT:
|
||||||
case ACTION_PLACE:
|
case ACTION_PLACE:
|
||||||
soundType = GAME_SOUND_DROG;
|
soundType = GAME_SOUND_DROG;
|
||||||
break;
|
break;
|
||||||
case ACTION_CAPTURE:
|
case ACTION_REMOVE:
|
||||||
soundType = GAME_SOUND_CAPTURE;
|
soundType = GAME_SOUND_REMOVE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -956,7 +955,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifndef TRAINING_MODE
|
#ifndef TRAINING_MODE
|
||||||
if (soundType == GAME_SOUND_DROG && state.position->getAction() == ACTION_CAPTURE) {
|
if (soundType == GAME_SOUND_DROG && state.position->getAction() == ACTION_REMOVE) {
|
||||||
soundType = GAME_SOUND_MILL;
|
soundType = GAME_SOUND_MILL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1167,7 +1166,7 @@ bool GameController::updateScence(StateInfo &g)
|
||||||
// 遍历棋盘,查找并放置棋盘上的棋子
|
// 遍历棋盘,查找并放置棋盘上的棋子
|
||||||
for (j = SQ_BEGIN; j < SQ_END; j++) {
|
for (j = SQ_BEGIN; j < SQ_END; j++) {
|
||||||
if (board[j] == key) {
|
if (board[j] == key) {
|
||||||
pos = scene.rs2pos(j / Board::N_SEATS, j % Board::N_SEATS + 1);
|
pos = scene.rs2pos(ring_t(j / Board::N_SEATS), seat_t(j % Board::N_SEATS + 1));
|
||||||
if (piece->pos() != pos) {
|
if (piece->pos() != pos) {
|
||||||
|
|
||||||
// 让移动的棋子位于顶层
|
// 让移动的棋子位于顶层
|
||||||
|
@ -1203,7 +1202,7 @@ bool GameController::updateScence(StateInfo &g)
|
||||||
// 为了对最近移除的棋子置为选择状态作准备
|
// 为了对最近移除的棋子置为选择状态作准备
|
||||||
deletedPiece = piece;
|
deletedPiece = piece;
|
||||||
|
|
||||||
#ifdef GAME_PLACING_SHOW_CAPTURED_PIECES
|
#ifdef GAME_PLACING_SHOW_REMOVED_PIECES
|
||||||
if (state.position->getPhase() == PHASE_MOVING) {
|
if (state.position->getPhase() == PHASE_MOVING) {
|
||||||
#endif
|
#endif
|
||||||
QPropertyAnimation *animation = new QPropertyAnimation(piece, "pos");
|
QPropertyAnimation *animation = new QPropertyAnimation(piece, "pos");
|
||||||
|
@ -1212,7 +1211,7 @@ bool GameController::updateScence(StateInfo &g)
|
||||||
animation->setEndValue(pos);
|
animation->setEndValue(pos);
|
||||||
animation->setEasingCurve(QEasingCurve::InOutQuad);
|
animation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||||
animationGroup->addAnimation(animation);
|
animationGroup->addAnimation(animation);
|
||||||
#ifdef GAME_PLACING_SHOW_CAPTURED_PIECES
|
#ifdef GAME_PLACING_SHOW_REMOVED_PIECES
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1225,7 +1224,7 @@ bool GameController::updateScence(StateInfo &g)
|
||||||
if (rule.hasForbiddenLocations && g.position->getPhase() == PHASE_PLACING) {
|
if (rule.hasForbiddenLocations && g.position->getPhase() == PHASE_PLACING) {
|
||||||
for (int j = SQ_BEGIN; j < SQ_END; j++) {
|
for (int j = SQ_BEGIN; j < SQ_END; j++) {
|
||||||
if (board[j] == PIECE_FORBIDDEN) {
|
if (board[j] == PIECE_FORBIDDEN) {
|
||||||
pos = scene.rs2pos(j / Board::N_SEATS, j % Board::N_SEATS + 1);
|
pos = scene.rs2pos(ring_t(j / Board::N_SEATS), seat_t(j % Board::N_SEATS + 1));
|
||||||
if (nTotalPieces < static_cast<int>(pieceList.size())) {
|
if (nTotalPieces < static_cast<int>(pieceList.size())) {
|
||||||
pieceList.at(static_cast<size_t>(nTotalPieces++))->setPos(pos);
|
pieceList.at(static_cast<size_t>(nTotalPieces++))->setPos(pos);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -50,8 +50,8 @@ enum sound_t
|
||||||
{
|
{
|
||||||
GAME_SOUND_NONE,
|
GAME_SOUND_NONE,
|
||||||
GAME_SOUND_BLOCK_MILL,
|
GAME_SOUND_BLOCK_MILL,
|
||||||
GAME_SOUND_CAPTURE,
|
GAME_SOUND_REMOVE,
|
||||||
GAME_SOUND_CHOOSE,
|
GAME_SOUND_SELECT,
|
||||||
GAME_SOUND_DRAW,
|
GAME_SOUND_DRAW,
|
||||||
GAME_SOUND_DROG,
|
GAME_SOUND_DROG,
|
||||||
GAME_SOUND_FORBIDDEN,
|
GAME_SOUND_FORBIDDEN,
|
||||||
|
@ -64,7 +64,6 @@ enum sound_t
|
||||||
GAME_SOUND_NEW_GAME,
|
GAME_SOUND_NEW_GAME,
|
||||||
GAME_SOUND_NEXT_MILL,
|
GAME_SOUND_NEXT_MILL,
|
||||||
GAME_SOUND_OBVIOUS,
|
GAME_SOUND_OBVIOUS,
|
||||||
GAME_SOUND_REMOVE,
|
|
||||||
GAME_SOUND_REPEAT_THREE_DRAW,
|
GAME_SOUND_REPEAT_THREE_DRAW,
|
||||||
GAME_SOUND_SIDE,
|
GAME_SOUND_SIDE,
|
||||||
GAME_SOUND_STAR,
|
GAME_SOUND_STAR,
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "pieceitem.h"
|
#include "pieceitem.h"
|
||||||
#include "boarditem.h"
|
#include "boarditem.h"
|
||||||
#include "graphicsconst.h"
|
#include "graphicsconst.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
GameScene::GameScene(QObject *parent) :
|
GameScene::GameScene(QObject *parent) :
|
||||||
QGraphicsScene(parent),
|
QGraphicsScene(parent),
|
||||||
|
@ -112,12 +113,12 @@ void GameScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
//QGraphicsScene::mouseReleaseEvent(mouseEvent);
|
//QGraphicsScene::mouseReleaseEvent(mouseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF GameScene::rs2pos(int r, int s)
|
QPointF GameScene::rs2pos(ring_t r, seat_t s)
|
||||||
{
|
{
|
||||||
return board->rs2pos(r, s);
|
return board->rs2pos(r, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameScene::pos2rs(QPointF pos, int &r, int &s)
|
bool GameScene::pos2rs(QPointF pos, ring_t &r, seat_t &s)
|
||||||
{
|
{
|
||||||
return board->pos2rs(pos, r, s);
|
return board->pos2rs(pos, r, s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
class BoardItem;
|
class BoardItem;
|
||||||
|
|
||||||
|
@ -34,10 +35,10 @@ public:
|
||||||
~GameScene() override;
|
~GameScene() override;
|
||||||
|
|
||||||
// 将模型的圈、位转化为落子点坐标
|
// 将模型的圈、位转化为落子点坐标
|
||||||
QPointF rs2pos(int r, int s);
|
QPointF rs2pos(ring_t r, seat_t s);
|
||||||
|
|
||||||
// 将落子点坐标转化为模型用的圈、位
|
// 将落子点坐标转化为模型用的圈、位
|
||||||
bool pos2rs(QPointF pos, int &r, int &s);
|
bool pos2rs(QPointF pos, ring_t &r, seat_t &s);
|
||||||
|
|
||||||
// 设置棋盘斜线
|
// 设置棋盘斜线
|
||||||
void setDiagonal(bool arg = true);
|
void setDiagonal(bool arg = true);
|
||||||
|
|
|
@ -53,16 +53,16 @@ PieceItem::PieceItem(QGraphicsItem *parent) :
|
||||||
size = PIECE_SIZE;
|
size = PIECE_SIZE;
|
||||||
|
|
||||||
// 选中子标识线宽度
|
// 选中子标识线宽度
|
||||||
chooseLineWeight = LINE_WEIGHT;
|
selectLineWeight = LINE_WEIGHT;
|
||||||
|
|
||||||
// 删除线宽度
|
// 删除线宽度
|
||||||
removeLineWeight = LINE_WEIGHT * 5;
|
removeLineWeight = LINE_WEIGHT * 5;
|
||||||
|
|
||||||
// 选中线为黄色
|
// 选中线为黄色
|
||||||
#ifdef MOBILE_APP_UI
|
#ifdef MOBILE_APP_UI
|
||||||
chooseLineColor = Qt::gray;
|
selectLineColor = Qt::gray;
|
||||||
#else
|
#else
|
||||||
chooseLineColor = Qt::darkYellow;
|
selectLineColor = Qt::darkYellow;
|
||||||
#endif /* MOBILE_APP_UI */
|
#endif /* MOBILE_APP_UI */
|
||||||
|
|
||||||
// 删除线颜色
|
// 删除线颜色
|
||||||
|
@ -145,9 +145,9 @@ void PieceItem::paint(QPainter *painter,
|
||||||
|
|
||||||
// 如果模型为选中状态,则画上四个小直角
|
// 如果模型为选中状态,则画上四个小直角
|
||||||
if (isSelected()) {
|
if (isSelected()) {
|
||||||
QPen pen(chooseLineColor, chooseLineWeight, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
|
QPen pen(selectLineColor, selectLineWeight, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
int xy = (size - chooseLineWeight) / 2;
|
int xy = (size - selectLineWeight) / 2;
|
||||||
|
|
||||||
painter->drawLine(-xy, -xy, -xy, -xy / 2);
|
painter->drawLine(-xy, -xy, -xy, -xy / 2);
|
||||||
painter->drawLine(-xy, -xy, -xy / 2, -xy);
|
painter->drawLine(-xy, -xy, -xy / 2, -xy);
|
||||||
|
|
|
@ -127,13 +127,13 @@ private:
|
||||||
bool showNum {false};
|
bool showNum {false};
|
||||||
|
|
||||||
// 选中子标识线宽度
|
// 选中子标识线宽度
|
||||||
int chooseLineWeight;
|
int selectLineWeight;
|
||||||
|
|
||||||
// 删除线宽度
|
// 删除线宽度
|
||||||
int removeLineWeight;
|
int removeLineWeight;
|
||||||
|
|
||||||
// 选中线颜色
|
// 选中线颜色
|
||||||
QColor chooseLineColor;
|
QColor selectLineColor;
|
||||||
|
|
||||||
// 删除线颜色
|
// 删除线颜色
|
||||||
QColor removeLineColor;
|
QColor removeLineColor;
|
||||||
|
|
Loading…
Reference in New Issue