本文整理汇总了C++中MoveList::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ MoveList::empty方法的具体用法?C++ MoveList::empty怎么用?C++ MoveList::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoveList
的用法示例。
在下文中一共展示了MoveList::empty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SearchForNewMods
void CMissionManager::SearchForNewMods()
{
// List all PK4s in the fms/ directory
MoveList moveList = SearchForNewMods(".pk4");
MoveList zipMoveList = SearchForNewMods(".zip");
// Merge the zips into the pk4 list
if (!zipMoveList.empty())
{
moveList.merge(zipMoveList);
}
DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Found %d new mission packages.\r", static_cast<int>(moveList.size()));
gameLocal.Printf("Found %d new mission packages.\n", static_cast<int>(moveList.size()));
// greebo: The D3 engine should no longer hold locks on those files
// and we can start moving them into their respective locations
for (MoveList::const_iterator i = moveList.begin(); i != moveList.end(); ++i)
{
fs::path targetPath = i->second;
// Remove any target file first, to overwrite when moving
DoRemoveFile(targetPath);
// Move the file
DoMoveFile(i->first, targetPath);
// Remove the file portion
targetPath.remove_leaf();
// Remove any darkmod.txt, splashimage etc. when copying a new PK4. It may contain updated versions of those.
DoRemoveFile(targetPath / cv_tdm_fm_desc_file.GetString());
DoRemoveFile(targetPath / cv_tdm_fm_splashimage_file.GetString());
DoRemoveFile(targetPath / cv_tdm_fm_notes_file.GetString());
}
}
示例2: alphaBeta
int Search::alphaBeta(bool white_turn, int depth, int alpha, int beta, Board& board, Transposition *tt,
bool null_move_in_branch, Move (&killers)[32][2], int (&history)[64][64], int ply) {
// If, mate we do not need search at greater depths
if (board.b[WHITE][KING] == 0) {
return -10000;
} else if (board.b[BLACK][KING] == 0) {
return 10000;
}
if (depth == 0) {
return capture_quiescence_eval_search(white_turn, alpha, beta, board);
}
if (depth == 1) {
// futility pruning. we do not hope for improving a position more than 300 in one move...
int static_eval = evaluate(board);
if (white_turn && (static_eval + 300) < alpha) {
return capture_quiescence_eval_search(white_turn, alpha, beta, board);
}
if (!white_turn && (static_eval - 300) > beta) {
return capture_quiescence_eval_search(white_turn, alpha, beta, board);
}
}
if (depth == 2) {
// extended futility pruning. we do not hope for improving a position more than 500 in two plies...
// not really proven to +ELO but does not worse performance at least
int static_eval = evaluate(board);
if ((white_turn && (static_eval + 500) < alpha) || (!white_turn && (static_eval - 500) > beta)) {
return capture_quiescence_eval_search(white_turn, alpha, beta, board);
}
}
// null move heuristic - we do this despite in check..
if (!null_move_in_branch && depth > 3) {
// skip a turn and see if and see if we get a cut-off at shallower depth
// it assumes:
// 1. That the disadvantage of forfeiting one's turn is greater than the disadvantage of performing a shallower search.
// 2. That the beta cut-offs prunes enough branches to be worth the time searching at reduced depth
int R = 2; // depth reduction
int res = alphaBeta(!white_turn, depth - 1 - R, alpha, beta, board, tt, true, killers, history, ply + 1);
if (white_turn && res > alpha) {
alpha = res;
} else if (!white_turn && res < beta) {
beta = res;
}
if (beta <= alpha) {
if (white_turn) {
return alpha;
}
return beta;
}
}
MoveList moves = get_children(board, white_turn);
if (moves.empty()) {
return 0;
}
Transposition tt_pv = tt[board.hash_key % HASH_SIZE];
for (auto it = moves.begin(); it != moves.end(); ++it) {
// sort pv moves first
if (tt_pv.next_move != 0 && tt_pv.hash == board.hash_key && tt_pv.next_move == it->m) {
it->sort_score += 1100000;
}
// ...then captures in MVVLVA order
if (!is_capture(it->m)) {
// killer moves are quite moves that has previously led to a cut-off
if (killers[ply - 1][0].m == it->m) {
it->sort_score += 999999;
} else if (killers[ply - 1][1].m == it->m) {
it->sort_score += 899999;
} else {
// "history heuristics"
// the rest of the quite moves are sorted based on how often they increase score in the search tree
it->sort_score += history[from_square(it->m)][to_square(it->m)];
}
}
}
total_generated_moves += moves.size();
Transposition t;
t.hash = board.hash_key;
int next_move = 0;
for (unsigned int i = 0; i < moves.size(); ++i) {
// late move reduction.
// we assume sort order is good enough to not search later moves as deep as the first 4
if (depth > 5 && i == 10) {
depth -= 2;
}
pick_next_move(moves, i);
Move child = moves[i];
node_count++;
make_move(board, child);
int res = alphaBeta(!white_turn, depth - 1, alpha, beta, board, tt, null_move_in_branch, killers, history,
ply + 1);
unmake_move(board, child);
if (res > alpha && res < beta) {
// only cache exact scores
}
//.........这里部分代码省略.........
示例3: _get_all_moves
void MoveGenDefault::_get_all_moves(MoveList& moves) const
{
static bool capture[8][8] = {};
// Search for capture-moves first
if (MT != NON_CAPTURE)
{
for (int i = 0; i < board.piece_count[turn_simple(TURN)]; ++i)
{
const auto& pos = board.piece_list[turn_simple(TURN)][i];
Move move(pos);
move.set_original(board[pos.row][pos.column]);
tmp_assign<Piece> move_begin(const_cast<Piece&>
(board[pos.row][pos.column]), Piece(PT_EMPTY)); // Because this position is empty when we move from it
_find_deep_capture<TURN>(moves, move, pos.row, pos.column, capture);
}
for (int i = 0; i < board.piece_count[turn_queen(TURN)]; ++i)
{
const auto& pos = board.piece_list[turn_queen(TURN)][i];
Move move(pos);
move.set_original(board[pos.row][pos.column]);
tmp_assign<Piece> move_begin(const_cast<Piece&>
(board[pos.row][pos.column]), Piece(PT_EMPTY)); // Because this position is empty when we move from it
_find_deep_capture_queen<TURN>(moves, move, pos.row, pos.column, capture);
}
}
// Capture-move is mandatory, so we need to check non-capture moves only when we don't have any capture-moves
if (MT == CAPTURE || !moves.empty())
return;
for (int i = 0; i < board.piece_count[turn_simple(TURN)]; ++i)
{
const auto& pos = board.piece_list[turn_simple(TURN)][i];
if (pos.column < 7 && board[TURN == WHITE ? pos.row + 1 : pos.row - 1][pos.column + 1].get_type() == PT_EMPTY)
{
Move move(pos);
move.set_original(board[pos.row][pos.column]);
if (TURN == WHITE)
{
move.add_step(Position(pos.row + 1, pos.column + 1));
move.set_become(pos.row == 6 ? Piece(WHITE_QUEEN) : Piece(WHITE_SIMPLE));
}
else
{
move.add_step(Position(pos.row - 1, pos.column + 1));
move.set_become(pos.row == 1 ? Piece(BLACK_QUEEN) : Piece(BLACK_SIMPLE));
}
moves.emplace(std::move(move));
}
if (pos.column > 0 && board[TURN == WHITE ? pos.row + 1 : pos.row - 1][pos.column - 1].get_type() == PT_EMPTY)
{
Move move(pos);
move.set_original(board[pos.row][pos.column]);
if (TURN == WHITE)
{
move.add_step(Position(pos.row + 1, pos.column - 1));
move.set_become(pos.row == 6 ? Piece(WHITE_QUEEN) : Piece(WHITE_SIMPLE));
}
else
{
move.add_step(Position(pos.row - 1, pos.column - 1));
move.set_become(pos.row == 1 ? Piece(BLACK_QUEEN) : Piece(BLACK_SIMPLE));
}
moves.emplace(std::move(move));
}
}
for (int i = 0; i < board.piece_count[turn_queen(TURN)]; ++i)
{
const auto& pos = board.piece_list[turn_queen(TURN)][i];
constexpr int dx[4] = { 1, 1, -1, -1 }, dy[4] = { 1, -1, 1, -1 };
for (size_t dir = 0; dir < 4; ++dir)
for (int r = pos.row + dy[dir], c = pos.column + dx[dir]; r < 8 && c < 8 && r >= 0 && c >= 0
&& board[r][c].get_type() == PT_EMPTY; r += dy[dir], c += dx[dir])
{
Move move(pos);
move.add_step(Position(r, c));
move.set_original(board[pos.row][pos.column]);
move.set_become(TURN == WHITE ? Piece(WHITE_QUEEN) : Piece(BLACK_QUEEN));
moves.emplace(std::move(move));
}
}
}