dummyGame -> tempGame
This commit is contained in:
parent
3cc120e8fc
commit
38fd3ef062
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "evaluate.h"
|
||||
|
||||
value_t Evaluation::getValue(Game &dummyGame, Position *position, AIAlgorithm::Node *node)
|
||||
value_t Evaluation::getValue(Game &tempGame, Position *position, AIAlgorithm::Node *node)
|
||||
{
|
||||
// 初始评估值为0,对先手有利则增大,对后手有利则减小
|
||||
value_t value = VALUE_ZERO;
|
||||
|
@ -83,7 +83,7 @@ value_t Evaluation::getValue(Game &dummyGame, Position *position, AIAlgorithm::N
|
|||
|
||||
#ifdef EVALUATE_MOBILITY
|
||||
// 按棋子活动能力计分
|
||||
value += dummyGame.getMobilityDiff(position->turn, dummyGame.currentRule, position->nPiecesInHand[1], position->nPiecesInHand[2], false) * 10;
|
||||
value += tempGame.getMobilityDiff(position->turn, tempGame.currentRule, position->nPiecesInHand[1], position->nPiecesInHand[2], false) * 10;
|
||||
#endif /* EVALUATE_MOBILITY */
|
||||
|
||||
switch (position->action) {
|
||||
|
@ -112,7 +112,7 @@ value_t Evaluation::getValue(Game &dummyGame, Position *position, AIAlgorithm::N
|
|||
// 布局阶段闷棋判断
|
||||
if (position->nPiecesOnBoard[1] + position->nPiecesOnBoard[2] >=
|
||||
Board::N_SEATS * Board::N_RINGS) {
|
||||
if (dummyGame.getRule()->isStartingPlayerLoseWhenBoardFull) {
|
||||
if (tempGame.getRule()->isStartingPlayerLoseWhenBoardFull) {
|
||||
value -= VALUE_WIN;
|
||||
} else {
|
||||
value = VALUE_DRAW;
|
||||
|
@ -121,17 +121,17 @@ value_t Evaluation::getValue(Game &dummyGame, Position *position, AIAlgorithm::N
|
|||
|
||||
// 走棋阶段被闷判断
|
||||
if (position->action == ACTION_CHOOSE &&
|
||||
dummyGame.position.board.isAllSurrounded(position->turn, dummyGame.currentRule, position->nPiecesOnBoard, position->turn) &&
|
||||
dummyGame.getRule()->isLoseWhenNoWay) {
|
||||
tempGame.position.board.isAllSurrounded(position->turn, tempGame.currentRule, position->nPiecesOnBoard, position->turn) &&
|
||||
tempGame.getRule()->isLoseWhenNoWay) {
|
||||
// 规则要求被“闷”判负,则对手获胜
|
||||
value_t delta = position->turn == PLAYER_1 ? -VALUE_WIN : VALUE_WIN;
|
||||
value += delta;
|
||||
}
|
||||
|
||||
// 剩余棋子个数判断
|
||||
if (position->nPiecesOnBoard[1] < dummyGame.getRule()->nPiecesAtLeast) {
|
||||
if (position->nPiecesOnBoard[1] < tempGame.getRule()->nPiecesAtLeast) {
|
||||
value -= VALUE_WIN;
|
||||
} else if (position->nPiecesOnBoard[2] < dummyGame.getRule()->nPiecesAtLeast) {
|
||||
} else if (position->nPiecesOnBoard[2] < tempGame.getRule()->nPiecesAtLeast) {
|
||||
value += VALUE_WIN;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
|
||||
Evaluation &operator=(const Evaluation &) = delete;
|
||||
|
||||
static value_t getValue(Game &dummyGame, Position *Position, AIAlgorithm::Node *node);
|
||||
static value_t getValue(Game &tempGame, Position *Position, AIAlgorithm::Node *node);
|
||||
|
||||
// 评估子力
|
||||
#ifdef EVALUATE_ENABLE
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "player.h"
|
||||
#include "misc.h"
|
||||
|
||||
void MoveList::generateLegalMoves(AIAlgorithm &ai, Game &dummyGame,
|
||||
void MoveList::generateLegalMoves(AIAlgorithm &ai, Game &tempGame,
|
||||
AIAlgorithm::Node *node, AIAlgorithm::Node *rootNode,
|
||||
move_t bestMove)
|
||||
{
|
||||
|
@ -34,17 +34,17 @@ void MoveList::generateLegalMoves(AIAlgorithm &ai, Game &dummyGame,
|
|||
size_t newCapacity = 24;
|
||||
|
||||
// 留足余量空间避免多次重新分配,此动作本身也占用 CPU/内存 开销
|
||||
switch (dummyGame.getPhase()) {
|
||||
switch (tempGame.getPhase()) {
|
||||
case PHASE_PLACING:
|
||||
if (dummyGame.getAction() == ACTION_CAPTURE) {
|
||||
newCapacity = static_cast<size_t>(dummyGame.getPiecesOnBoardCount(dummyGame.position.opponentId));
|
||||
if (tempGame.getAction() == ACTION_CAPTURE) {
|
||||
newCapacity = static_cast<size_t>(tempGame.getPiecesOnBoardCount(tempGame.position.opponentId));
|
||||
} else {
|
||||
newCapacity = static_cast<size_t>(dummyGame.getPiecesInHandCount(1) + dummyGame.getPiecesInHandCount(2));
|
||||
newCapacity = static_cast<size_t>(tempGame.getPiecesInHandCount(1) + tempGame.getPiecesInHandCount(2));
|
||||
}
|
||||
break;
|
||||
case PHASE_MOVING:
|
||||
if (dummyGame.getAction() == ACTION_CAPTURE) {
|
||||
newCapacity = static_cast<size_t>(dummyGame.getPiecesOnBoardCount(dummyGame.position.opponentId));
|
||||
if (tempGame.getAction() == ACTION_CAPTURE) {
|
||||
newCapacity = static_cast<size_t>(tempGame.getPiecesOnBoardCount(tempGame.position.opponentId));
|
||||
} else {
|
||||
newCapacity = 6;
|
||||
}
|
||||
|
@ -65,28 +65,28 @@ void MoveList::generateLegalMoves(AIAlgorithm &ai, Game &dummyGame,
|
|||
}
|
||||
|
||||
// 对手
|
||||
player_t opponent = Player::getOpponent(dummyGame.position.turn);
|
||||
player_t opponent = Player::getOpponent(tempGame.position.turn);
|
||||
|
||||
// 列出所有合法的下一招
|
||||
switch (dummyGame.position.action) {
|
||||
switch (tempGame.position.action) {
|
||||
// 对于选子和落子动作
|
||||
case ACTION_CHOOSE:
|
||||
case ACTION_PLACE:
|
||||
// 对于摆子阶段
|
||||
if (dummyGame.position.phase & (PHASE_PLACING | PHASE_NOTSTARTED)) {
|
||||
if (tempGame.position.phase & (PHASE_PLACING | PHASE_NOTSTARTED)) {
|
||||
for (move_t i : movePriorityTable) {
|
||||
location = i;
|
||||
|
||||
if (dummyGame.boardLocations[location]) {
|
||||
if (tempGame.boardLocations[location]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dummyGame.position.phase != PHASE_NOTSTARTED || node != rootNode) {
|
||||
ai.addNode(node, VALUE_ZERO, (move_t)location, bestMove, dummyGame.position.turn);
|
||||
if (tempGame.position.phase != PHASE_NOTSTARTED || node != rootNode) {
|
||||
ai.addNode(node, VALUE_ZERO, (move_t)location, bestMove, tempGame.position.turn);
|
||||
} else {
|
||||
// 若为先手,则抢占星位
|
||||
if (Board::isStarLocation(location)) {
|
||||
ai.addNode(node, VALUE_INFINITE, (move_t)location, bestMove, dummyGame.position.turn);
|
||||
ai.addNode(node, VALUE_INFINITE, (move_t)location, bestMove, tempGame.position.turn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,34 +94,34 @@ void MoveList::generateLegalMoves(AIAlgorithm &ai, Game &dummyGame,
|
|||
}
|
||||
|
||||
// 对于移子阶段
|
||||
if (dummyGame.position.phase & PHASE_MOVING) {
|
||||
if (tempGame.position.phase & PHASE_MOVING) {
|
||||
int newLocation, oldLocation;
|
||||
|
||||
// 尽量走理论上较差的位置的棋子
|
||||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
oldLocation = movePriorityTable[i];
|
||||
|
||||
if (!dummyGame.choose(oldLocation)) {
|
||||
if (!tempGame.choose(oldLocation)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dummyGame.position.nPiecesOnBoard[dummyGame.position.turnId] > dummyGame.currentRule.nPiecesAtLeast ||
|
||||
!dummyGame.currentRule.allowFlyWhenRemainThreePieces) {
|
||||
if (tempGame.position.nPiecesOnBoard[tempGame.position.turnId] > tempGame.currentRule.nPiecesAtLeast ||
|
||||
!tempGame.currentRule.allowFlyWhenRemainThreePieces) {
|
||||
// 对于棋盘上还有3个子以上,或不允许飞子的情况,要求必须在着法表中
|
||||
for (int direction = DIRECTION_CLOCKWISE; direction <= DIRECTION_OUTWARD; direction++) {
|
||||
// 对于原有位置,遍历四个方向的着法,如果棋盘上为空位就加到结点列表中
|
||||
newLocation = moveTable[oldLocation][direction];
|
||||
if (newLocation && !dummyGame.boardLocations[newLocation]) {
|
||||
if (newLocation && !tempGame.boardLocations[newLocation]) {
|
||||
move_t move = move_t((oldLocation << 8) + newLocation);
|
||||
ai.addNode(node, VALUE_ZERO, move, bestMove, dummyGame.position.turn); // (12%)
|
||||
ai.addNode(node, VALUE_ZERO, move, bestMove, tempGame.position.turn); // (12%)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 对于棋盘上还有不到3个字,但允许飞子的情况,不要求在着法表中,是空位就行
|
||||
for (newLocation = Board::LOCATION_BEGIN; newLocation < Board::LOCATION_END; newLocation++) {
|
||||
if (!dummyGame.boardLocations[newLocation]) {
|
||||
if (!tempGame.boardLocations[newLocation]) {
|
||||
move_t move = move_t((oldLocation << 8) + newLocation);
|
||||
ai.addNode(node, VALUE_ZERO, move, bestMove, dummyGame.position.turn);
|
||||
ai.addNode(node, VALUE_ZERO, move, bestMove, tempGame.position.turn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,12 +131,12 @@ void MoveList::generateLegalMoves(AIAlgorithm &ai, Game &dummyGame,
|
|||
|
||||
// 对于吃子动作
|
||||
case ACTION_CAPTURE:
|
||||
if (dummyGame.position.board.isAllInMills(opponent)) {
|
||||
if (tempGame.position.board.isAllInMills(opponent)) {
|
||||
// 全成三的情况
|
||||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
location = movePriorityTable[i];
|
||||
if (dummyGame.boardLocations[location] & opponent) {
|
||||
ai.addNode(node, VALUE_ZERO, (move_t)-location, bestMove, dummyGame.position.turn);
|
||||
if (tempGame.boardLocations[location] & opponent) {
|
||||
ai.addNode(node, VALUE_ZERO, (move_t)-location, bestMove, tempGame.position.turn);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -145,9 +145,9 @@ void MoveList::generateLegalMoves(AIAlgorithm &ai, Game &dummyGame,
|
|||
// 不是全成三的情况
|
||||
for (int i = MOVE_PRIORITY_TABLE_SIZE - 1; i >= 0; i--) {
|
||||
location = movePriorityTable[i];
|
||||
if (dummyGame.boardLocations[location] & opponent) {
|
||||
if (dummyGame.getRule()->allowRemoveMill || !dummyGame.position.board.inHowManyMills(location)) {
|
||||
ai.addNode(node, VALUE_ZERO, (move_t)-location, bestMove, dummyGame.position.turn);
|
||||
if (tempGame.boardLocations[location] & opponent) {
|
||||
if (tempGame.getRule()->allowRemoveMill || !tempGame.position.board.inHowManyMills(location)) {
|
||||
ai.addNode(node, VALUE_ZERO, (move_t)-location, bestMove, tempGame.position.turn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
MoveList &operator=(const MoveList &) = delete;
|
||||
|
||||
// 生成所有合法的着法并建立子节点
|
||||
static void generateLegalMoves(AIAlgorithm &ai, Game &dummyGame,
|
||||
static void generateLegalMoves(AIAlgorithm &ai, Game &tempGame,
|
||||
AIAlgorithm::Node *node, AIAlgorithm::Node *rootNode,
|
||||
move_t bestMove);
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ depth_t AIAlgorithm::changeDepth(depth_t originalDepth)
|
|||
{
|
||||
depth_t newDepth = originalDepth;
|
||||
|
||||
if ((dummyGame.position.phase) & (PHASE_PLACING)) {
|
||||
if ((tempGame.position.phase) & (PHASE_PLACING)) {
|
||||
#ifdef GAME_PLACING_DYNAMIC_DEPTH
|
||||
#ifdef DEAL_WITH_HORIZON_EFFECT
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
|
@ -77,7 +77,7 @@ depth_t AIAlgorithm::changeDepth(depth_t originalDepth)
|
|||
depth_t depthTable[] = { 2, 13, 13, 13, 12, 11, 10, 9, 9, 8, 8, 7, 1 };
|
||||
#endif
|
||||
#endif // DEAL_WITH_HORIZON_EFFECT
|
||||
newDepth = depthTable[dummyGame.getPiecesInHandCount(1)];
|
||||
newDepth = depthTable[tempGame.getPiecesInHandCount(1)];
|
||||
#elif defined GAME_PLACING_FIXED_DEPTH
|
||||
newDepth = GAME_PLACING_FIXED_DEPTH;
|
||||
#endif // GAME_PLACING_DYNAMIC_DEPTH
|
||||
|
@ -85,7 +85,7 @@ depth_t AIAlgorithm::changeDepth(depth_t originalDepth)
|
|||
|
||||
#ifdef GAME_MOVING_FIXED_DEPTH
|
||||
// 走棋阶段将深度调整
|
||||
if ((dummyGame.position.phase) & (PHASE_MOVING)) {
|
||||
if ((tempGame.position.phase) & (PHASE_MOVING)) {
|
||||
newDepth = GAME_MOVING_FIXED_DEPTH;
|
||||
}
|
||||
#endif /* GAME_MOVING_FIXED_DEPTH */
|
||||
|
@ -141,8 +141,8 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode(
|
|||
|
||||
#ifdef DEBUG_AB_TREE
|
||||
newNode->root = rootNode;
|
||||
newNode->phase = dummyGame.position.phase;
|
||||
newNode->action = dummyGame.position.action;
|
||||
newNode->phase = tempGame.position.phase;
|
||||
newNode->action = tempGame.position.action;
|
||||
newNode->evaluated = false;
|
||||
newNode->nPiecesInHandDiff = INT_MAX;
|
||||
newNode->nPiecesOnBoardDiff = INT_MAX;
|
||||
|
@ -155,15 +155,15 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode(
|
|||
char cmd[32] = { 0 };
|
||||
|
||||
if (move < 0) {
|
||||
dummyGame.position.board.locationToPolar(-move, r, s);
|
||||
tempGame.position.board.locationToPolar(-move, r, s);
|
||||
sprintf(cmd, "-(%1u,%1u)", r, s);
|
||||
} else if (move & 0x7f00) {
|
||||
int r1, s1;
|
||||
dummyGame.position.board.locationToPolar(move >> 8, r1, s1);
|
||||
dummyGame.position.board.locationToPolar(move & 0x00ff, r, s);
|
||||
tempGame.position.board.locationToPolar(move >> 8, r1, s1);
|
||||
tempGame.position.board.locationToPolar(move & 0x00ff, r, s);
|
||||
sprintf(cmd, "(%1u,%1u)->(%1u,%1u)", r1, s1, r, s);
|
||||
} else {
|
||||
dummyGame.position.board.locationToPolar(move & 0x007f, r, s);
|
||||
tempGame.position.board.locationToPolar(move & 0x007f, r, s);
|
||||
sprintf(cmd, "(%1u,%1u)", r, s);
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ struct AIAlgorithm::Node *AIAlgorithm::addNode(
|
|||
if (bestMove == 0 || move != bestMove) {
|
||||
#ifdef MILL_FIRST
|
||||
// 优先成三
|
||||
if (dummyGame.getPhase() == GAME_PLACING && move > 0 && dummyGame.position.board.isInMills(move, true)) {
|
||||
if (tempGame.getPhase() == GAME_PLACING && move > 0 && tempGame.position.board.isInMills(move, true)) {
|
||||
parent->children.insert(parent->children.begin(), newNode);
|
||||
} else {
|
||||
parent->children.push_back(newNode);
|
||||
|
@ -232,7 +232,7 @@ void AIAlgorithm::sortLegalMoves(Node *node)
|
|||
{
|
||||
// 这个函数对效率的影响很大,排序好的话,剪枝较早,节省时间,但不能在此函数耗费太多时间
|
||||
|
||||
auto cmp = dummyGame.position.turn == PLAYER_1 ? nodeGreater : nodeLess;
|
||||
auto cmp = tempGame.position.turn == PLAYER_1 ? nodeGreater : nodeLess;
|
||||
|
||||
std::stable_sort(node->children.begin(), node->children.end(), cmp);
|
||||
}
|
||||
|
@ -275,8 +275,8 @@ void AIAlgorithm::setGame(const Game &game)
|
|||
}
|
||||
|
||||
this->game_ = game;
|
||||
dummyGame = game;
|
||||
position = &(dummyGame.position);
|
||||
tempGame = game;
|
||||
position = &(tempGame.position);
|
||||
requiredQuit = false;
|
||||
deleteTree(rootNode);
|
||||
#ifdef MEMORY_POOL
|
||||
|
@ -397,7 +397,7 @@ value_t AIAlgorithm::alphaBetaPruning(depth_t depth, value_t alpha, value_t beta
|
|||
enum TranspositionTable::HashType hashf = TranspositionTable::hashfALPHA;
|
||||
|
||||
// 获取哈希值
|
||||
hash_t hash = dummyGame.getHash();
|
||||
hash_t hash = tempGame.getHash();
|
||||
#ifdef DEBUG_AB_TREE
|
||||
node->hash = hash;
|
||||
#endif
|
||||
|
@ -454,7 +454,7 @@ value_t AIAlgorithm::alphaBetaPruning(depth_t depth, value_t alpha, value_t beta
|
|||
// 搜索到叶子节点(决胜局面) // TODO: 对哈希进行特殊处理
|
||||
if (position->phase == PHASE_GAMEOVER) {
|
||||
// 局面评估
|
||||
node->value = Evaluation::getValue(dummyGame, position, node);
|
||||
node->value = Evaluation::getValue(tempGame, position, node);
|
||||
evaluatedNodeCount++;
|
||||
|
||||
// 为争取速胜,value 值 +- 深度
|
||||
|
@ -479,7 +479,7 @@ value_t AIAlgorithm::alphaBetaPruning(depth_t depth, value_t alpha, value_t beta
|
|||
// 搜索到第0层或需要退出
|
||||
if (!depth || requiredQuit) {
|
||||
// 局面评估
|
||||
node->value = Evaluation::getValue(dummyGame, position, node);
|
||||
node->value = Evaluation::getValue(tempGame, position, node);
|
||||
evaluatedNodeCount++;
|
||||
|
||||
// 为争取速胜,value 值 +- 深度 (有必要?)
|
||||
|
@ -511,18 +511,18 @@ value_t AIAlgorithm::alphaBetaPruning(depth_t depth, value_t alpha, value_t beta
|
|||
}
|
||||
|
||||
// 生成子节点树,即生成每个合理的着法
|
||||
MoveList::generateLegalMoves(*this, dummyGame, node, rootNode, bestMove);
|
||||
MoveList::generateLegalMoves(*this, tempGame, node, rootNode, bestMove);
|
||||
|
||||
// 根据演算模型执行 MiniMax 检索,对先手,搜索 Max, 对后手,搜索 Min
|
||||
|
||||
minMax = dummyGame.position.turn == PLAYER_1 ? -VALUE_INFINITE : VALUE_INFINITE;
|
||||
minMax = tempGame.position.turn == PLAYER_1 ? -VALUE_INFINITE : VALUE_INFINITE;
|
||||
|
||||
for (auto child : node->children) {
|
||||
// 棋局入栈保存,以便后续撤销着法
|
||||
positionStack.push(dummyGame.position);
|
||||
positionStack.push(tempGame.position);
|
||||
|
||||
// 执行着法
|
||||
dummyGame.command(child->move);
|
||||
tempGame.command(child->move);
|
||||
|
||||
#ifdef DEAL_WITH_HORIZON_EFFECT
|
||||
// 克服“水平线效应”: 若遇到吃子,则搜索深度增加
|
||||
|
@ -543,10 +543,10 @@ value_t AIAlgorithm::alphaBetaPruning(depth_t depth, value_t alpha, value_t beta
|
|||
value = alphaBetaPruning(depth - 1 + epsilon, alpha, beta, child);
|
||||
|
||||
// 棋局弹出栈,撤销着法
|
||||
dummyGame.position = positionStack.top();
|
||||
tempGame.position = positionStack.top();
|
||||
positionStack.pop();
|
||||
|
||||
if (dummyGame.position.turn == PLAYER_1) {
|
||||
if (tempGame.position.turn == PLAYER_1) {
|
||||
// 为走棋一方的层, 局面对走棋的一方来说是以 α 为评价
|
||||
|
||||
// 取最大值
|
||||
|
@ -722,15 +722,15 @@ const char *AIAlgorithm::move2string(move_t move)
|
|||
int r, s;
|
||||
|
||||
if (move < 0) {
|
||||
dummyGame.position.board.locationToPolar(-move, r, s);
|
||||
tempGame.position.board.locationToPolar(-move, r, s);
|
||||
sprintf(cmdline, "-(%1u,%1u)", r, s);
|
||||
} else if (move & 0x7f00) {
|
||||
int r1, s1;
|
||||
dummyGame.position.board.locationToPolar(move >> 8, r1, s1);
|
||||
dummyGame.position.board.locationToPolar(move & 0x00ff, r, s);
|
||||
tempGame.position.board.locationToPolar(move >> 8, r1, s1);
|
||||
tempGame.position.board.locationToPolar(move & 0x00ff, r, s);
|
||||
sprintf(cmdline, "(%1u,%1u)->(%1u,%1u)", r1, s1, r, s);
|
||||
} else {
|
||||
dummyGame.position.board.locationToPolar(move & 0x007f, r, s);
|
||||
tempGame.position.board.locationToPolar(move & 0x007f, r, s);
|
||||
sprintf(cmdline, "(%1u,%1u)", r, s);
|
||||
}
|
||||
|
||||
|
|
|
@ -185,12 +185,12 @@ private:
|
|||
Game game_;
|
||||
|
||||
// 演算用的模型
|
||||
Game dummyGame;
|
||||
Game tempGame;
|
||||
|
||||
Position *position {};
|
||||
|
||||
// hash 计算时,各种转换用的模型
|
||||
Game dummyGameShift;
|
||||
Game tempGameShift;
|
||||
|
||||
// 根节点
|
||||
Node *rootNode {nullptr};
|
||||
|
|
|
@ -49,17 +49,17 @@ bool TranspositionTable::findHash(hash_t hash, TranspositionTable::HashValue &ha
|
|||
return iter;
|
||||
|
||||
// 变换局面,查找 hash (废弃)
|
||||
dummyGameShift = dummyGame;
|
||||
tempGameShift = tempGame;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (i)
|
||||
dummyGameShift.mirror(false);
|
||||
tempGameShift.mirror(false);
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
if (j)
|
||||
dummyGameShift.turn(false);
|
||||
tempGameShift.turn(false);
|
||||
for (int k = 0; k < 4; k++) {
|
||||
dummyGameShift.rotate(k * 90, false);
|
||||
iter = hashmap.find(dummyGameShift.getHash());
|
||||
tempGameShift.rotate(k * 90, false);
|
||||
iter = hashmap.find(tempGameShift.getHash());
|
||||
if (iter != hashmap.end())
|
||||
return iter;
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ void GameController::gameStart()
|
|||
{
|
||||
game_.configure(giveUpIfMostLose_, randomMove_);
|
||||
game_.start();
|
||||
dummyGame = game_;
|
||||
tempGame = game_;
|
||||
|
||||
// 每隔100毫秒调用一次定时器处理函数
|
||||
if (timeID == 0) {
|
||||
|
@ -150,7 +150,7 @@ void GameController::gameReset()
|
|||
// 重置游戏
|
||||
game_.configure(giveUpIfMostLose_, randomMove_);
|
||||
game_.reset();
|
||||
dummyGame = game_;
|
||||
tempGame = game_;
|
||||
|
||||
// 停掉线程
|
||||
if (!isAutoRestart) {
|
||||
|
@ -281,7 +281,7 @@ void GameController::setRule(int ruleNo, step_t stepLimited /*= -1*/, int timeLi
|
|||
|
||||
// 设置模型规则,重置游戏
|
||||
game_.setPosition(&RULES[ruleNo], stepsLimit, timeLimit);
|
||||
dummyGame = game_;
|
||||
tempGame = game_;
|
||||
|
||||
// 重置游戏
|
||||
gameReset();
|
||||
|
@ -400,7 +400,7 @@ void GameController::flip()
|
|||
|
||||
game_.position.board.mirror(game_.cmdlist, game_.cmdline, game_.move_, game_.currentRule, game_.currentLocation);
|
||||
game_.position.board.rotate(180, game_.cmdlist, game_.cmdline, game_.move_, game_.currentRule, game_.currentLocation);
|
||||
dummyGame = game_;
|
||||
tempGame = game_;
|
||||
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
|
@ -439,7 +439,7 @@ void GameController::mirror()
|
|||
}
|
||||
|
||||
game_.position.board.mirror(game_.cmdlist, game_.cmdline, game_.move_, game_.currentRule, game_.currentLocation);
|
||||
dummyGame = game_;
|
||||
tempGame = game_;
|
||||
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
|
@ -481,7 +481,7 @@ void GameController::turnRight()
|
|||
}
|
||||
|
||||
game_.position.board.rotate(-90, game_.cmdlist, game_.cmdline, game_.move_, game_.currentRule, game_.currentLocation);
|
||||
dummyGame = game_;
|
||||
tempGame = game_;
|
||||
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
|
@ -521,7 +521,7 @@ void GameController::turnLeft()
|
|||
}
|
||||
|
||||
game_.position.board.rotate(90, game_.cmdlist, game_.cmdline, game_.move_, game_.currentRule, game_.currentLocation);
|
||||
dummyGame = game_;
|
||||
tempGame = game_;
|
||||
|
||||
// 更新棋谱
|
||||
int row = 0;
|
||||
|
@ -642,7 +642,7 @@ bool GameController::actionPiece(QPointF pos)
|
|||
|
||||
if (QMessageBox::Ok == msgBox.exec()) {
|
||||
#endif /* !MOBILE_APP_UI */
|
||||
game_ = dummyGame;
|
||||
game_ = tempGame;
|
||||
manualListModel.removeRows(currentRow + 1, manualListModel.rowCount() - currentRow - 1);
|
||||
|
||||
// 如果再决出胜负后悔棋,则重新启动计时
|
||||
|
@ -953,14 +953,14 @@ bool GameController::phaseChange(int row, bool forceUpdate)
|
|||
|
||||
for (int i = 0; i <= row; i++) {
|
||||
loggerDebug("%s\n", mlist.at(i).toStdString().c_str());
|
||||
dummyGame.command(mlist.at(i).toStdString().c_str());
|
||||
tempGame.command(mlist.at(i).toStdString().c_str());
|
||||
}
|
||||
|
||||
// 下面这步关键,会让悔棋者承担时间损失
|
||||
dummyGame.setStartTime(game_.getStartTimeb());
|
||||
tempGame.setStartTime(game_.getStartTimeb());
|
||||
|
||||
// 刷新棋局场景
|
||||
updateScence(dummyGame);
|
||||
updateScence(tempGame);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ private:
|
|||
Game game_;
|
||||
|
||||
// 棋对象的数据模型(临时)
|
||||
Game dummyGame;
|
||||
Game tempGame;
|
||||
|
||||
// 2个AI的线程
|
||||
AiThread *ai[3];
|
||||
|
|
Loading…
Reference in New Issue