本文整理汇总了C++中MoveList::end方法的典型用法代码示例。如果您正苦于以下问题:C++ MoveList::end方法的具体用法?C++ MoveList::end怎么用?C++ MoveList::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoveList
的用法示例。
在下文中一共展示了MoveList::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getAttackMove
MoveList ChessPiece::getAttackMove(MoveList curMoveList) {
MoveList moveList = permissibleMove();
MoveList attackList;
for (auto move : moveList)
if (std::find(curMoveList.begin(), curMoveList.end(), move) == curMoveList.end())
attackList.push_back(move);
return attackList;
}
示例2: GetBestMove
//==============================================================================
Move MoveSelector::GetBestMove(const value_type &maxDepth) const
{
BitBoardPtr spBoard = m_wpBoard.lock();
ValidMoveSet vms(m_wpMoveSet, spBoard);
MoveList moves = vms.GetMyValidMoves();
value_type bestValue = s_negInfinity;
Move bestMove;
for (auto it = moves.begin(); it != moves.end(); ++it)
{
BitBoardPtr spResult = result(spBoard, *it);
value_type oldVal = bestValue;
value_type min = minValue(spResult, maxDepth, s_negInfinity, s_posInfinity);
bestValue = std::max(bestValue, min);
if (bestValue > oldVal)
{
bestMove = *it;
}
}
return bestMove;
}
示例3: Quiescence
int Minimax::Quiescence(Board *board, GameInfo *gameInfo, int depth, int alpha, int beta) {
// Evaluate the node in its current state. If it causes a beta-cutoff, assume that there will be no move further down the
//game tree that will result in a better evaluation. Otherwise, set it as the lower bound, alpha.
int nodeEvaluation = Eval(board, gameInfo);
if (nodeEvaluation >= beta) return beta;
if (nodeEvaluation > alpha) alpha = nodeEvaluation;
MoveList moveList;
// If the node is in check, consider every move. Otherwise, just consider captures/promotions.
moveList.generate(gameInfo->turn, board, gameInfo, !MoveList::InCheck(gameInfo->turn, board));
moveList.prune((Piece::Color)!gameInfo->turn, board);
for (MoveList::iterator moveItr = moveList.begin(); moveItr != moveList.end(); moveItr++) {
Move move = *moveItr;
board->executeMove(move);
// Save any irreversible game info before making a move.
GameInfo::Irreversible irreversible(gameInfo);
gameInfo->executeMove(move);
int childEval = 0;
// If we are at depth 0, just get the score of the board (The score is negated as it is measured relative to the opposite color).
if (depth == 0) childEval = -Eval(board, gameInfo);
else childEval = -Quiescence(board, gameInfo, depth - 1, -beta, -alpha);
board->reverseMove(move);
gameInfo->reverseMove(irreversible);
if (childEval >= beta) return beta;
if (childEval > alpha) alpha = childEval;
}
return alpha;
}
示例4: minValue
//==============================================================================
value_type MoveSelector::minValue(
const BitBoardPtr &spBoard,
const value_type &depth,
value_type alpha,
value_type beta
) const
{
ValidMoveSet vms(m_wpMoveSet, spBoard);
value_type score = m_evaluator.Score(spBoard, vms);
if (reachedEndState(depth, score))
{
return score;
}
MoveList moves = vms.GetMyValidMoves();
value_type v = s_posInfinity;
for (auto it = moves.begin(); it != moves.end(); ++it)
{
BitBoardPtr spResult = result(spBoard, *it);
v = std::min(v, maxValue(spResult, depth-1, alpha, beta));
if (score <= alpha)
{
return v;
}
beta = std::min(beta, v);
}
return v;
}
示例5: sortNonReverse
void MoveList::sortNonReverse(MoveList &list, SortType type)
{
switch (type)
{
case Win:
stable_sort(list.begin(), list.end(), winComparator);
break;
case Equity:
stable_sort(list.begin(), list.end(), equityComparator);
break;
case Score:
stable_sort(list.begin(), list.end(), scoreComparator);
break;
case Alphabetical:
stable_sort(list.begin(), list.end(), alphabeticalComparator);
break;
}
}
示例6: pick_next_move
/**
* selection sort algorithm
*
* The algorithm divides the input list into two parts: the sublist of items already sorted,
* which is built up from left to right at the front (left) of the list,
* and the sublist of items remaining to be sorted that occupy the rest of the list.
*
* swaps the best, non-sorted, move to next index
*/
void pick_next_move(MoveList& moves, const int no_sorted_moves) {
int max_sort_score = INT_MIN;
int max_index = no_sorted_moves;
int i = no_sorted_moves;
for (auto it = moves.begin() + no_sorted_moves; it != moves.end(); ++it) {
if (it->sort_score >= max_sort_score) {
max_index = i;
max_sort_score = it->sort_score;
}
i++;
}
std::swap(moves[no_sorted_moves], moves[max_index]);
}
示例7: initGame
int initGame( const std::string& fen,
const MoveList& moves )
{
//if ( ! fen.empty() ) return hoxAI_RC_NOT_SUPPORTED;
m_engine.reset( new folHOXEngine( ""/*fen*/ ) );
for ( MoveList::const_iterator it = moves.begin();
it != moves.end(); ++it)
{
m_engine->OnHumanMove( *it );
}
return hoxAI_RC_OK;
}
示例8: initGame
int initGame( const std::string& fen,
const MoveList& moves )
{
//if ( ! fen.empty() ) return hoxAI_RC_NOT_SUPPORTED;
::InitGame();
for ( MoveList::const_iterator it = moves.begin();
it != moves.end(); ++it)
{
std::string stdMove = _hoxToMove( *it );
::OnOpponentMove( stdMove.c_str() );
}
return hoxAI_RC_OK;
}
示例9: AlphaBeta
int Minimax::AlphaBeta(Board *board, GameInfo *gameInfo, Move &move, int depth, const int quiescenceDepth, int alpha, int beta) {
// If we are at the end of the normal alpha beta search, perform a quiescence search with the given quiescence depth.
if (depth == 0) return Quiescence(board, gameInfo, quiescenceDepth, alpha, beta);
MoveList moveList;
// Generate move list and check game state.
GameInfo::State state = gameInfo->updateState(board, moveList);
switch (state) {
case GameInfo::STALEMATE:
case GameInfo::FIFTY_MOVE_RULE:
// Returns a score which will always be disregarded.
return LARGEST_NUM + 1;
case GameInfo::CHECKMATE:
// Return arbitrarily large negative score (But not -LARGEST_NUM, as it would be cut off).
return -LARGE_NUM;
}
MoveList::iterator bestMoveItr = moveList.begin();
for (MoveList::iterator moveItr = moveList.begin(); moveItr != moveList.end(); moveItr++) {
Move childMove = *moveItr;
board->executeMove(childMove);
// Save any irreversible game info before making a move.
GameInfo::Irreversible irreversible(gameInfo);
gameInfo->executeMove(childMove);
// Here, the child's evaluation is taken to be the negation of its return value, so that seperate if statements for maximising and minimising
//aren't required.
int childEval = -AlphaBeta(board, gameInfo, move, depth - 1, quiescenceDepth, -beta, -alpha);
board->reverseMove(childMove);
gameInfo->reverseMove(irreversible);
// If the child evaluates to a score greater than or equal to beta, there is a beta cutoff. This means that there is no further point exploring this
// node's moves, as it is known that this node will at least be as bad if not worse than another node elsewhere in the game tree.
if (childEval >= beta) {
// If a non-capture move caused a beta-cutoff, increase its history weighting. The depth squared is added to the heuristic so that moves near
//the leaf nodes don't dominate the heuristic (Leaf node score would be 0 * 0).
if (!move.isCapture()) Move::HistoryHeuristic[move.subject_from][move.subject_to] += depth * depth;
move = *bestMoveItr;
return beta;
}
// If the child's evaluation is greater than alpha, this is the best move at the moment.
if (childEval > alpha) {
alpha = childEval;
bestMoveItr = moveItr;
}
}
move = *bestMoveItr;
return alpha;
}
示例10: MakeMove
//==============================================================================
bool ChessGame::MakeMove(Move &move) const
{
ValidMoveSet vms(m_wpMoveSet, m_spBoard);
MoveList list = vms.GetMyValidMoves();
// Check all valid moves - if this move is valid, make it
for (auto it = list.begin(); it != list.end(); ++it)
{
if (move == *it)
{
LOGD(m_gameId, "Made valid move: %s", move);
m_spBoard->MakeMove(move);
return true;
}
}
LOGD(m_gameId, "Made invalid move: %s", move);
return false;
}
示例11: positionCount
int Board::positionCount(Color my,MoveList& positions) const{
int occupy=0;
MoveList::iterator mit=positions.begin();
for(;mit!=positions.end();++mit){
if(piece((*mit).pos)!=my)
continue;
PositionList checkList=(*mit).getOffsets();
PositionList::iterator pit=checkList.begin();
if(checkList.size()==0){
++occupy;
continue;
}
bool support=false;
for(;pit!=checkList.end();++pit){
if(piece(*pit)==my){
support=true;
break;
}
}
if(!support)
++occupy;
}
return occupy;
}
示例12: 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());
}
}
示例13: sort
void MoveList::sort(MoveList &list, SortType type)
{
sortNonReverse(list, type);
reverse(list.begin(), list.end());
}
示例14: moves
MoveList SmartBogowin::moves(int nmoves)
{
Stopwatch stopwatch;
if (currentPosition().bag().empty())
{
signalFractionDone(0);
EndgamePlayer endgame;
endgame.setPosition(currentPosition());
return endgame.moves(nmoves);
}
// TODO
// Move this all to an Inferrer class
//
// Generate all moves for all racks opp could have had.
// This can be done efficiently by making a big "rack" out of the bag (with the computer
// player's own rack removed) and generating moves from that big "rack" with some smarts
// added to the move generator to not create moves that have so many tiles not in the
// opp's play that they wouldn't have been possible from any of the racks we're looking
// for. Make a ProbableRackList of racks from which the opp's play is best or nearly
// (really what we're looking for is least bad). Most heavily weight the leaves for which
// the play is as close to optimal as possible (an x-point static mistake), and let the
// weights taper off to zero as the mistakes approach say x+7.
//
// Make the Simulator able to select racks randomly from the ProbableRackList
if (m_parameters.inferring) {
int numPlayers = currentPosition().players().size();
UVcout << "numPlayers: " << numPlayers << endl;
if (numPlayers == 2) {
bool hasPreviousPosition;
GamePosition previous = m_simulator.history().previousPosition(&hasPreviousPosition);
if (hasPreviousPosition) {
UVcout << "previous position:" << endl;
UVcout << previous << endl;
} else {
UVcout << "no previous position" << endl;
}
}
}
UVcout << "SmartBogowin generating move from position:" << endl;
UVcout << currentPosition() << endl;
const int zerothPrune = 33;
int plies = 2;
if (currentPosition().bag().size() <= QUACKLE_PARAMETERS->rackSize() * 2)
plies = -1;
const int initialCandidates = m_additionalInitialCandidates + nmoves;
currentPosition().kibitz(initialCandidates);
m_simulator.setIncludedMoves(m_simulator.currentPosition().moves());
m_simulator.pruneTo(zerothPrune, initialCandidates);
m_simulator.makeSureConsideredMovesAreIncluded();
m_simulator.setIgnoreOppos(false);
MoveList staticMoves = m_simulator.moves(/* prune */ true, /* sort by equity */ false);
m_simulator.moveConsideredMovesToBeginning(staticMoves);
//UVcout << "Bogo static moves: " << staticMoves << endl;
//UVcout << "Bogo considered moves: " << m_simulator.consideredMoves() << endl;
MoveList firstMove;
MoveList simmedMoves;
MoveList::const_iterator it = staticMoves.begin();
firstMove.push_back(*it);
signalFractionDone(0);
m_simulator.setIncludedMoves(firstMove);
m_simulator.simulate(plies, minIterations());
Move best = *m_simulator.moves(/* prune */ true, /* sort by win */ true).begin();
simmedMoves.push_back(best);
double bestbp = bogopoints(best);
//UVcout << "firstMove: " << best << endl;
for (++it; it != staticMoves.end(); ++it)
{
signalFractionDone(max(static_cast<float>(simmedMoves.size()) / static_cast<float>(staticMoves.size()), static_cast<float>(stopwatch.elapsed()) / static_cast<float>(m_parameters.secondsPerTurn)));
if (shouldAbort())
goto sort_and_return;
//UVcout << "best move: " << best << " with " << bestbp << " bogopoints." << endl;
MoveList lookFurther;
lookFurther.push_back(*it);
m_simulator.setIncludedMoves(lookFurther);
m_simulator.simulate(plies, minIterations());
Move move = *m_simulator.moves(/* prune */ true, /* sort by win */ true).begin();
double movebp = bogopoints(move);
//UVcout << "we just simmed " << move << "; bogopoints: " << movebp << endl;
//.........这里部分代码省略.........
示例15: allWordsFormedBy
MoveList Board::allWordsFormedBy(const Move &move) const
{
MoveList ret;
if (move.tiles().length() > 1)
ret.push_back(move);
if (move.action == Move::Place)
{
if (m_empty)
{
ret.push_back(move);
}
else
{
LetterString word;
if (move.horizontal)
{
int i = 0;
const LetterString::const_iterator end(move.tiles().end());
for (LetterString::const_iterator it = move.tiles().begin(); it != end; ++it, ++i)
{
if (m_letters[move.startrow][i + move.startcol] == QUACKLE_NULL_MARK)
{
word.clear();
word += *it;
int startRow = 0;
for (int j = move.startrow - 1; j >= 0; --j)
{
if (m_letters[j][i + move.startcol] == QUACKLE_NULL_MARK)
{
startRow = j + 1;
break;
}
else
{
word = m_letters[j][i + move.startcol] + word;
}
}
for (int j = move.startrow + 1; j < m_height; ++j)
{
if (m_letters[j][i + move.startcol] == QUACKLE_NULL_MARK)
j = m_height;
else
word += m_letters[j][i + move.startcol];
}
if (word.length() > 1)
{
ret.push_back(Move::createPlaceMove(startRow, (i + move.startcol), /* vertical */ false, word));
}
}
}
}
else
{
int i = 0;
const LetterString::const_iterator end(move.tiles().end());
for (LetterString::const_iterator it = move.tiles().begin(); it != end; ++it, ++i)
{
if (m_letters[i + move.startrow][move.startcol] == QUACKLE_NULL_MARK)
{
word.clear();
word += *it;
int startColumn = 0;
for (int j = move.startcol - 1; j >= 0; --j)
{
if (m_letters[i + move.startrow][j] == QUACKLE_NULL_MARK)
{
startColumn = j + 1;
break;
}
else
{
word = m_letters[i + move.startrow][j] + word;
}
}
for (int j = move.startcol + 1; j < m_width; ++j)
{
if (m_letters[i + move.startrow][j] == QUACKLE_NULL_MARK)
j = m_width;
else
word += m_letters[i + move.startrow][j];
}
if (word.length() > 1)
{
ret.push_back(Move::createPlaceMove((i + move.startrow), startColumn, /* horizontal */ true, word));
}
}
}
}
}
}
//.........这里部分代码省略.........