refactor: 增加重载类型运算符的宏

valut_t OK, 但是 direction_t 未奏效,待查.
This commit is contained in:
CalciteM Team 2019-09-13 13:31:49 +08:00
parent c665c64803
commit 091321a6e1
4 changed files with 45 additions and 17 deletions

View File

@ -78,8 +78,8 @@ value_t Evaluation::getValue(Position &dummyPosition, PositionContext *positionC
case PHASE_MOVING:
// 按场上棋子计分
value = (value_t)(positionContext->nPiecesOnBoard_1 * VALUE_EACH_PIECE_ONBOARD -
positionContext->nPiecesOnBoard_2 * VALUE_EACH_PIECE_ONBOARD);
value = positionContext->nPiecesOnBoard_1 * VALUE_EACH_PIECE_ONBOARD -
positionContext->nPiecesOnBoard_2 * VALUE_EACH_PIECE_ONBOARD;
#ifdef EVALUATE_MOBILITY
// 按棋子活动能力计分

View File

@ -358,7 +358,7 @@ int MillGameAi_ab::alphaBetaPruning(depth_t depth)
TranspositionTable::clearTranspositionTable(); // 每次走子前清空哈希表
#endif
#endif
alphaBetaPruning(i, (value_t)-VALUE_INFINITE, VALUE_INFINITE, rootNode);
alphaBetaPruning(i, -VALUE_INFINITE, VALUE_INFINITE, rootNode);
}
timeEnd = chrono::steady_clock::now();
@ -525,7 +525,7 @@ value_t MillGameAi_ab::alphaBetaPruning(depth_t depth, value_t alpha, value_t be
// 根据演算模型执行 MiniMax 检索,对先手,搜索 Max, 对后手,搜索 Min
minMax = dummyPosition.whosTurn() == PLAYER1 ? (value_t)-VALUE_INFINITE : VALUE_INFINITE;
minMax = dummyPosition.whosTurn() == PLAYER1 ? -VALUE_INFINITE : VALUE_INFINITE;
for (auto child : node->children) {
// 上下文入栈保存,以便后续撤销着法

View File

@ -338,8 +338,8 @@ int Board::getSurroundedEmptyLocationCount(enum player_t turn, const Rule &curre
(nPiecesOnBoard_1 > currentRule.nPiecesAtLeast || !currentRule.allowFlyWhenRemainThreePieces)) ||
(turn == PLAYER2 &&
(nPiecesOnBoard_2 > currentRule.nPiecesAtLeast || !currentRule.allowFlyWhenRemainThreePieces))) {
int d, moveLocation;
for (d = 0; d < DIRECTIONS_COUNT; d++) {
int moveLocation;
for (direction_t d = DIRECTION_BEGIN; d < DIRECTIONS_COUNT; d = (direction_t)(d + 1)) {
moveLocation = MoveList::moveTable[location][d];
if (moveLocation) {
if (locations[moveLocation] == 0x00 ||
@ -396,7 +396,7 @@ bool Board::isAllSurrounded(enum player_t turn, const Rule &currentRule, int nPi
continue;
}
for (int d = 0; d < DIRECTIONS_COUNT; d++) {
for (direction_t d = DIRECTION_BEGIN; d < DIRECTIONS_COUNT; d = (direction_t)(d + 1)) {
moveLocation = MoveList::moveTable[i][d];
if (moveLocation && !locations[moveLocation])
return false;

View File

@ -54,6 +54,7 @@ enum square_t : int
enum direction_t
{
DIRECTION_CLOCKWISE = 0, // 顺时针
DIRECTION_BEGIN = DIRECTION_CLOCKWISE,
DIRECTION_ANTICLOCKWISE = 1, // 逆时针
DIRECTION_INWARD = 2, // 向内
DIRECTION_OUTWARD = 3, // 向外
@ -113,6 +114,42 @@ enum value_t : int16_t
VALUE_EACH_PIECE_NEEDREMOVE_2 = 128,
};
// 动作状态标识
enum action_t : uint16_t
{
ACTION_NONE = 0x0000,
ACTION_CHOOSE = 0x0100, // 选子
ACTION_PLACE = 0x0200, // 落子
ACTION_CAPTURE = 0x0400 // 提子
};
#define ENABLE_BASE_OPERATORS_ON(T) \
constexpr T operator+(T d1, T d2) { return T(int(d1) + int(d2)); } \
constexpr T operator-(T d1, T d2) { return T(int(d1) - int(d2)); } \
constexpr T operator-(T d) { return T(-int(d)); } \
inline T& operator+=(T& d1, T d2) { return d1 = d1 + d2; } \
inline T& operator-=(T& d1, T d2) { return d1 = d1 - d2; }
#define ENABLE_INCR_OPERATORS_ON(T) \
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
inline T& operator--(T& d) { return d = T(int(d) - 1); }
#define ENABLE_FULL_OPERATORS_ON(T) \
ENABLE_BASE_OPERATORS_ON(T) \
constexpr T operator*(int i, T d) { return T(i * int(d)); } \
constexpr T operator*(T d, int i) { return T(int(d) * i); } \
constexpr T operator/(T d, int i) { return T(int(d) / i); } \
constexpr int operator/(T d1, T d2) { return int(d1) / int(d2); } \
inline T& operator*=(T& d, int i) { return d = T(int(d) * i); } \
inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
ENABLE_FULL_OPERATORS_ON(value_t)
ENABLE_FULL_OPERATORS_ON(direction_t)
ENABLE_INCR_OPERATORS_ON(direction_t)
ENABLE_INCR_OPERATORS_ON(piece_t)
ENABLE_INCR_OPERATORS_ON(square_t)
// Additional operators to add integers to a Value
constexpr value_t operator+(value_t v, int i)
{
@ -132,15 +169,6 @@ inline value_t &operator+=(value_t &v, int i)
inline value_t &operator-=(value_t &v, int i)
{
return v = v - i;
}
// 动作状态标识
enum action_t : uint16_t
{
ACTION_NONE = 0x0000,
ACTION_CHOOSE = 0x0100, // 选子
ACTION_PLACE = 0x0200, // 落子
ACTION_CAPTURE = 0x0400 // 提子
};
}
#endif /* TYPES_H */