增加若干宏
This commit is contained in:
parent
49b2080238
commit
2a2ac8c7af
|
@ -859,7 +859,7 @@ bool GameController::updateScence(NineChess &chess)
|
|||
int j;
|
||||
|
||||
// 遍历棋盘,查找并放置棋盘上的棋子
|
||||
for (j = NineChess::N_SEATS; j < (NineChess::N_SEATS) * (NineChess::N_RINGS + 1); j++) {
|
||||
for (int j = NineChess::POS_BEGIN; j < NineChess::POS_END; j++) {
|
||||
if (board[j] == key) {
|
||||
pos = scene.cp2pos(j / NineChess::N_SEATS, j % NineChess::N_SEATS + 1);
|
||||
if (piece->pos() != pos) {
|
||||
|
@ -904,7 +904,7 @@ bool GameController::updateScence(NineChess &chess)
|
|||
|
||||
// 添加开局禁子点
|
||||
if (chess.getRule()->hasForbiddenPoint && chess.getStage() == NineChess::GAME_PLACING) {
|
||||
for (int j = NineChess::N_SEATS; j < (NineChess::N_SEATS) * (NineChess::N_RINGS + 1); j++) {
|
||||
for (int j = NineChess::POS_BEGIN; j < NineChess::POS_END; j++) {
|
||||
if (board[j] == 0x0F) {
|
||||
pos = scene.cp2pos(j / NineChess::N_SEATS, j % NineChess::N_SEATS + 1);
|
||||
if (n < pieceList.size()) {
|
||||
|
|
|
@ -31,9 +31,20 @@ public:
|
|||
// 8位,禁止修改!
|
||||
static const int N_SEATS = 8;
|
||||
|
||||
// 遍历棋盘点所用的起始位置,即 [8, 32)
|
||||
static const int POS_BEGIN = N_SEATS;
|
||||
static const int POS_END = ((N_RINGS + 1) * N_SEATS);
|
||||
|
||||
// 预定义的规则数目
|
||||
static const int N_RULES = 4;
|
||||
|
||||
// 定义 move
|
||||
typedef int move_t;
|
||||
|
||||
// 位置迭代器
|
||||
// typedef typename std::vector<move_t>::iterator posIterator;
|
||||
// typedef typename std::vector<move_t>::const_iterator constPosIterator;
|
||||
|
||||
// 嵌套的规则结构体
|
||||
struct Rule
|
||||
{
|
||||
|
|
|
@ -53,7 +53,7 @@ void NineChessAi_ab::buildChildren(Node *node)
|
|||
case NineChess::ACTION_PLACE:
|
||||
// 对于开局落子
|
||||
if ((chessTemp.context.stage) & (NineChess::GAME_PLACING | NineChess::GAME_NOTSTARTED)) {
|
||||
for (int i = NineChess::N_SEATS; i < (NineChess::N_RINGS + 1) * NineChess::N_SEATS; i++) {
|
||||
for (int i = NineChess::POS_BEGIN; i < NineChess::POS_END; i++) {
|
||||
if (!chessTemp.board_[i]) {
|
||||
addNode(node, 0, i);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ void NineChessAi_ab::buildChildren(Node *node)
|
|||
// 对于中局移子
|
||||
else {
|
||||
int newPos;
|
||||
for (int oldPos = NineChess::N_SEATS; oldPos < (NineChess::N_RINGS + 1) * NineChess::N_SEATS; oldPos++) {
|
||||
for (int oldPos = NineChess::POS_BEGIN; oldPos < NineChess::POS_END; oldPos++) {
|
||||
if (!chessTemp.choose(oldPos))
|
||||
continue;
|
||||
if ((chessTemp.context.turn == NineChess::PLAYER1 &&
|
||||
|
@ -76,7 +76,7 @@ void NineChessAi_ab::buildChildren(Node *node)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
for (int j = NineChess::N_SEATS; j < (NineChess::N_RINGS + 1) * NineChess::N_SEATS; j++) {
|
||||
for (int j = NineChess::POS_BEGIN; j < NineChess::POS_END; j++) {
|
||||
if (!chessTemp.board_[j]) {
|
||||
addNode(node, 0, (oldPos << 8) + j);
|
||||
}
|
||||
|
@ -89,13 +89,13 @@ void NineChessAi_ab::buildChildren(Node *node)
|
|||
case NineChess::ACTION_CAPTURE:
|
||||
// 全成三的情况
|
||||
if (chessTemp.isAllInMills(opponent)) {
|
||||
for (int i = NineChess::N_SEATS; i < (NineChess::N_RINGS + 1) * NineChess::N_SEATS; i++) {
|
||||
for (int i = NineChess::POS_BEGIN; i < NineChess::POS_END; i++) {
|
||||
if (chessTemp.board_[i] & opponent) {
|
||||
addNode(node, 0, -i);
|
||||
}
|
||||
}
|
||||
} else if (!chessTemp.isAllInMills(opponent)) {
|
||||
for (int i = NineChess::N_SEATS; i < (NineChess::N_RINGS + 1) * NineChess::N_SEATS; i++) {
|
||||
for (int i = NineChess::POS_BEGIN; i < NineChess::POS_END; i++) {
|
||||
if (chessTemp.board_[i] & opponent) {
|
||||
if (!chessTemp.isInMills(i)) {
|
||||
addNode(node, 0, -i);
|
||||
|
|
|
@ -67,7 +67,7 @@ protected:
|
|||
void deleteTree(Node *node);
|
||||
|
||||
// 增加新节点
|
||||
void addNode(Node* parent, int value, int move);
|
||||
void addNode(Node* parent, int value, NineChess::move_t move);
|
||||
|
||||
// 评价函数
|
||||
int evaluate(Node *node);
|
||||
|
|
Loading…
Reference in New Issue