全面使用 file_of() 和 rank_of() 代替旧函数
This commit is contained in:
parent
ddbd0c2ea6
commit
dd10fcb8d3
|
@ -118,7 +118,8 @@ void sq2str(char *str)
|
||||||
sig = 0;
|
sig = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Position::square_to_polar((Square)sq, file, rank);
|
file = file_of(sq);
|
||||||
|
rank = rank_of(sq);
|
||||||
|
|
||||||
if (sig == 1) {
|
if (sig == 1) {
|
||||||
sprintf_s(str, 16, "(%d,%d)", file, rank);
|
sprintf_s(str, 16, "(%d,%d)", file, rank);
|
||||||
|
|
|
@ -616,7 +616,8 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Position::square_to_polar(s, file, rank);
|
file = file_of(s);
|
||||||
|
rank = rank_of(s);
|
||||||
|
|
||||||
if (phase == PHASE_PLACING) {
|
if (phase == PHASE_PLACING) {
|
||||||
piece = (Piece)((0x01 | (sideToMove << PLAYER_SHIFT)) + rule.nTotalPiecesEachSide - pieceCountInHand[us]);
|
piece = (Piece)((0x01 | (sideToMove << PLAYER_SHIFT)) + rule.nTotalPiecesEachSide - pieceCountInHand[us]);
|
||||||
|
@ -753,9 +754,8 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
||||||
if (pieceCountNeedRemove <= 0)
|
if (pieceCountNeedRemove <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
File file;
|
File file = file_of(s);
|
||||||
Rank rank;
|
Rank rank = rank_of(s);
|
||||||
Position::square_to_polar(s, file, rank);
|
|
||||||
|
|
||||||
int seconds = -1;
|
int seconds = -1;
|
||||||
|
|
||||||
|
@ -1447,14 +1447,6 @@ void Position::create_mill_table()
|
||||||
#endif /* DEBUG_MODE */
|
#endif /* DEBUG_MODE */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Position::square_to_polar(const Square s, File &file, Rank &rank)
|
|
||||||
{
|
|
||||||
//r = s / RANK_NB;
|
|
||||||
//s = s % RANK_NB + 1;
|
|
||||||
file = File(s >> 3);
|
|
||||||
rank = Rank((s & 0x07) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color Position::color_on(Square s) const
|
Color Position::color_on(Square s) const
|
||||||
{
|
{
|
||||||
return Color((board[s] & 0x30) >> PLAYER_SHIFT);
|
return Color((board[s] & 0x30) >> PLAYER_SHIFT);
|
||||||
|
|
|
@ -157,8 +157,6 @@ public:
|
||||||
void surrounded_pieces_count(Square s, int &nOurPieces, int &nTheirPieces, int &nBanned, int &nEmpty);
|
void surrounded_pieces_count(Square s, int &nOurPieces, int &nTheirPieces, int &nBanned, int &nEmpty);
|
||||||
bool is_all_surrounded() const;
|
bool is_all_surrounded() const;
|
||||||
|
|
||||||
static void square_to_polar(Square s, File &file, Rank &rank);
|
|
||||||
|
|
||||||
static void print_board();
|
static void print_board();
|
||||||
|
|
||||||
int pieces_on_board_count();
|
int pieces_on_board_count();
|
||||||
|
|
|
@ -604,16 +604,14 @@ const char* AIAlgorithm::nextMove()
|
||||||
|
|
||||||
const char *AIAlgorithm::moveToCommand(Move move)
|
const char *AIAlgorithm::moveToCommand(Move move)
|
||||||
{
|
{
|
||||||
File file2;
|
File file2 = file_of(to_sq(move));
|
||||||
Rank rank2;
|
Rank rank2 = rank_of(to_sq(move));
|
||||||
Position::square_to_polar(to_sq(move), file2, rank2);
|
|
||||||
|
|
||||||
if (move < 0) {
|
if (move < 0) {
|
||||||
sprintf(cmdline, "-(%1u,%1u)", file2, rank2);
|
sprintf(cmdline, "-(%1u,%1u)", file2, rank2);
|
||||||
} else if (move & 0x7f00) {
|
} else if (move & 0x7f00) {
|
||||||
File file1;
|
File file1 = file_of(from_sq(move));
|
||||||
Rank rank1;
|
Rank rank1 = rank_of(from_sq(move));
|
||||||
Position::square_to_polar(from_sq(move), file1, rank1);
|
|
||||||
sprintf(cmdline, "(%1u,%1u)->(%1u,%1u)", file1, rank1, file2, rank2);
|
sprintf(cmdline, "(%1u,%1u)->(%1u,%1u)", file1, rank1, file2, rank2);
|
||||||
} else {
|
} else {
|
||||||
sprintf(cmdline, "(%1u,%1u)", file2, rank2);
|
sprintf(cmdline, "(%1u,%1u)", file2, rank2);
|
||||||
|
|
16
src/types.h
16
src/types.h
|
@ -481,26 +481,14 @@ constexpr bool is_ok(Square s)
|
||||||
|
|
||||||
constexpr File file_of(Square s)
|
constexpr File file_of(Square s)
|
||||||
{
|
{
|
||||||
return File((s >> 3) - 1);
|
return File(s >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Rank rank_of(Square s)
|
constexpr Rank rank_of(Square s)
|
||||||
{
|
{
|
||||||
return Rank(s & 7);
|
return Rank((s & 0x07) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
constexpr ring_t ring_of(Square s)
|
|
||||||
{
|
|
||||||
// return File(s & 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr Rank seat_of(Square s)
|
|
||||||
{
|
|
||||||
//return seat(s >> 3);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
constexpr Square from_sq(Move m)
|
constexpr Square from_sq(Move m)
|
||||||
{
|
{
|
||||||
return static_cast<Square>(m >> 8);
|
return static_cast<Square>(m >> 8);
|
||||||
|
|
Loading…
Reference in New Issue