本文整理汇总了C++中MoveList类的典型用法代码示例。如果您正苦于以下问题:C++ MoveList类的具体用法?C++ MoveList怎么用?C++ MoveList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MoveList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bool
void MoveGenEnglish::_find_deep_capture_queen(MoveList& moves, Move& move, int8_t row, int8_t column, bool(&captured)[8][8]) const
{
static constexpr int d_row[4] = { 1, 1, -1, -1 }, d_column[4] = { 1, -1, 1, -1 };
for (size_t dir = 0; dir < 4; ++dir)
{
// In english checkers we can jump only over adjacent pieces
const int r1 = row + d_row[dir], c1 = column + d_column[dir], r2 = r1 + d_row[dir], c2 = c1 + d_column[dir];
if (r2 < 0 || c2 < 0 || r2 > 7 || c2 > 7 || board[r2][c2].get_type() != PT_EMPTY
|| board[r1][c1].get_colour() != opposite(TURN) || captured[r1][c1])
continue;
move.add_step(Position(r2, c2)); // Correct capture-move
move.add_capture(std::make_pair(Position(r1, c1), board[r1][c1]));
const size_t old = moves.size();
captured[r1][c1] = true; // For preventing 'recapturing' piece at (r1; c1) in moves produced by recursive call to this function(next 4 lines)
_find_deep_capture_queen<TURN>(moves, move, r2, c2, captured);
if (old == moves.size()) // If in recursive call we haven't found any move, then 'move' is a final capture and is one of possible captures
{
move.set_become(Piece(TURN == WHITE ? WHITE_QUEEN : BLACK_QUEEN));
moves.emplace(move);
}
captured[r1][c1] = false; // For correct work on next cycles we should clear changes to 'captured' and 'move' variables
move.pop_step();
move.pop_capture();
}
}
示例2: guessMove
Result guessMove(const char* fen, int square, MoveList& mlist, int thinkTime)
{
Result r;
r.error = -1;
r.score = 0;
squareT sq = square;
Position pos;
pos.ReadFromFEN(fen);
pos.GenerateMoves(&mlist);
mlist.SelectBySquare(sq);
if (mlist.Size() == 0)
return r;
if (mlist.Size() > 1) {
Engine * engine = new Engine();
engine->SetSearchTime(thinkTime);
engine->SetPosition(&pos);
r.score = engine->Think(&mlist);
delete engine;
}
simpleMoveT * sm = mlist.Get(0);
ASSERT (sq == sm->from || sq == sm->to);
r.from = sm->from;
r.to = sm->to;
r.error = 0;
return r;
}
示例3: search
void Engine::search(ChessBoard& board, MoveList& moves, SEARCHTYPE searchtype, int wtime, int winc, int btime, int binc, int movestogo)
{
if (!process)
return;
QString cmd;
QStringList list;
ChessBoard b;
int i;
currentBoard = board;
for (i = 0; i < moves.size; i++)
{
list.append(currentBoard.makeMoveText(moves.at(i),UCI).c_str());
if (!currentBoard.doMove(moves.at(i), true))
break;
}
string s=board.getFen();
cmd = "position fen ";
if (board.startposition())
cmd += "startfen";
else
cmd += board.getFen(true).c_str();
if (list.size())
{
cmd += " moves";
QStringList::iterator lit = list.begin();
while (lit != list.end())
{
cmd += " ";
cmd += *lit;
++lit;
}
}
// If engine playing white it is most probaly not ready yet.
if (readyok)
write(cmd);
else
waitCommand += cmd;
cmd="go";
if (searchtype == PONDER_SEARCH)
cmd += " ponder";
if (searchtype == INFINITE_SEARCH)
{
cmd += " infinite";
}
else
{
cmd += " wtime " + QString().setNum(wtime);
cmd += " btime " + QString().setNum(btime);
cmd += " winc " + QString().setNum(winc);
cmd += " binc " + QString().setNum(binc);
}
if (movestogo)
cmd += "movestogo " + QString().setNum(movestogo);
cmd += "\n";
if (readyok)
write(cmd);
else
waitCommand += cmd;
}
示例4: Eval
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;
}
示例5: _find_deep_capture
void MoveGenEnglish::_find_deep_capture(MoveList& moves, Move& move, int8_t row, int8_t column) const
{
static constexpr int d_row = (TURN == WHITE ? 1 : -1), d_column[2] = { 1, -1 };
const int r1 = row + d_row, r2 = r1 + d_row;
if (r2 < 0 || r2 > 7)
return;
for (size_t dir = 0; dir < 2; ++dir)
{
const int c1 = column + d_column[dir], c2 = c1 + d_column[dir];
if (c2 < 0 || c2 > 7 || board[r2][c2].get_type() != PT_EMPTY
|| board[r1][c1].get_colour() != opposite(TURN))
continue;
move.add_step(Position(r2, c2)); // Correct capture-move
move.add_capture(std::make_pair(Position(r1, c1), board[r1][c1]));
const size_t old = moves.size();
if (TURN == WHITE ? (r2 == 7) : (r2 == 0)) // We can become queen at this move
{
move.set_become(Piece(TURN == WHITE ? WHITE_QUEEN : BLACK_QUEEN)); // In english checkers move is stopped when piece becomes queen
moves.emplace(move);
}
else
{
_find_deep_capture<TURN>(moves, move, r2, c2);
if (old == moves.size()) // If in recursive call we haven't found any move, then 'move' is a final capture and is one of possible captures
{
move.set_become(Piece(TURN == WHITE ? WHITE_SIMPLE : BLACK_SIMPLE));
moves.emplace(move);
}
}
move.pop_step();
move.pop_capture();
}
}
示例6: destIndex
void Board8x8::generateMoves(
std::list<uint> & indexList,
uint row,
uint col,
MoveList & moveList,
bool isSlider)
{
for (std::list<uint>::iterator itr = indexList.begin(); itr != indexList.end(); ++itr) {
uint destIndex(*itr);
uint destRow = destIndex >> 3;
uint destCol = destIndex & 7;
PieceType otherPiece = mPieceType[destIndex];
if (otherPiece != NoPiece) {
if ( (mWhiteToMove && isBlackPiece(otherPiece)) || (!mWhiteToMove && isWhitePiece(otherPiece)) ) {
Move newMove(row, col, destRow, destCol, otherPiece);
moveList.addMove(newMove);
}
if (isSlider)
break;
}
else {
Move newMove(row, col, destRow, destCol);
moveList.addMove(newMove);
}
}
}
示例7: StrToMove
Move StrToMove(const std::string& str, Position& pos)
{
for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
{
if (isdigit(*it) || *it == 'O')
break;
if (*it == ' ' || *it == 0)
return 0;
}
MoveList mvlist;
mvlist.GenAllMoves(pos);
for (int n = 0; n < mvlist.Size(); ++n)
{
Move mv = mvlist[n].m_mv;
if (MoveToStrLong(mv) == str)
return mv;
}
for (int n = 0; n < mvlist.Size(); ++n)
{
Move mv = mvlist[n].m_mv;
if (MoveToStrShort(mv, pos) == str)
return mv;
}
return 0;
}
示例8: vms
//==============================================================================
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;
}
示例9: getRow
void Board0x88::pushMove(uchar fromSquare, uchar toSquare, uchar fromPiece, uchar capturePiece, char flags, MoveList & moveList)
{
uchar sourceRow = getRow(fromSquare);
uchar sourceCol = getCol(fromSquare);
uchar destRow = getRow(toSquare);
uchar destCol = getCol(toSquare);
char epCol = (mEpIndex != -1) ? getCol(mEpIndex) : -1;
Move newMove;
newMove.sourceRow = sourceRow;
newMove.sourceCol = sourceCol;
newMove.destRow = destRow;
newMove.destCol = destCol;
newMove.fromPiece = fromPiece;
newMove.toPiece = fromPiece;
newMove.castlingRights = mCastlingRights;
newMove.halfMoveClock = mHalfMoveClock;
newMove.enPassantCol = epCol;
newMove.flags = flags;
newMove.capturePiece = capturePiece;
if ( fromPiece == Pawn && toSquare == mEpIndex )
newMove.flags = MoveEpCapture;
if ( fromPiece == Pawn && ( ( destRow == 0 ) || ( destRow == 7) ) ) {
newMove.flags |= MovePromotion;
for (uchar promoPiece = Queen; promoPiece <= Knight; promoPiece++) {
newMove.toPiece = promoPiece;
moveList.addMove(newMove);
}
}
else
moveList.addMove(newMove);
}
示例10: TEST
TEST(MovesTest, Constructor)
{
Board board;
Pieces pieces;
Position position;
MoveList list;
Move m;
ExtendedMove em(m, 50);
list[0] = em;
EXPECT_EQ(em.value(), list[0].value());
EXPECT_EQ(0, list.cur_ply());
Moves moves(board, pieces, position, list);
// Test if MoveList::inc_ply() has been implicitly called by Moves()
EXPECT_EQ(1, list.cur_ply());
EXPECT_EQ(BEST, moves.state());
EXPECT_EQ(0, moves.count(BEST));
EXPECT_EQ(0, moves.count(GOOD_CAPTURES));
EXPECT_EQ(0, moves.count(KILLERS));
EXPECT_EQ(0, moves.count(BAD_CAPTURES));
EXPECT_EQ(0, moves.count(QUIET_MOVES));
for (int i = 0; i < MAX_PLY; ++i) {
EXPECT_EQ(0, list[i].value());
}
list.dec_ply();
EXPECT_EQ(em.value(), list[0].value());
}
示例11: move_list_
DecoratedMoveList::DecoratedMoveList(Position * const parent)
: move_list_(),
best_move_num_(0),
n_best_moves_(0),
human_(false) {
if (parent->no_pieces())
return;
MoveList * successors = parent->generate_all_moves();
MovePrinter printer(parent);
Position * move;
State state;
move_list_.reserve(successors->size());
for (const Move * it = successors->first(); it != nullptr; it = it->next_) {
parent->do_move(it->move_, state);
move = new Position(parent);
parent->undo_move(state);
move_list_.push_back(new DecoratedPosition(move, printer.decode_move(move, it->move_), NULL_SCORE));
}
delete successors;
}
示例12: currentPosition
MoveList EndgamePlayer::moves(int nmoves)
{
if (currentPosition().bag().size() > 0)
{
#ifdef DEBUG_ENDGAME
UVcout << "EndgamePlayer returning statically evaluated play." << endl;
#endif
m_simulator.currentPosition().kibitz(nmoves);
#ifdef DEBUG_ENDGAME
UVcout << "EndgamePlayer returns " << m_simulator.currentPosition().moves() << endl;
#endif
return m_simulator.currentPosition().moves();
}
m_endgame.setPosition(currentPosition());
if (nmoves > 1) return m_endgame.moves(nmoves);
#ifdef DEBUG_ENDGAME
UVcout << "EndgamePlayer solving endgame from position:" << endl;
UVcout << currentPosition() << endl;
#endif
MoveList ret;
Move solution = m_endgame.solve(currentPosition().nestedness());
ret.push_back(solution);
#ifdef DEBUG_ENDGAME
UVcout << "EndgamePlayer returns solved endgame:" << ret << endl;
#endif
return ret;
}
示例13: PerformIntegrityCheck
void PerformIntegrityCheck (
LearnTree &tree,
INT32 baseOffset )
{
char temp [256];
assert (EditBoard != NULL);
assert (UnmoveTable != NULL);
int ply = EditBoard->GetCurrentPlyNumber();
assert ( ply == EditPly );
MoveList ml;
EditBoard->GenMoves (ml);
if ( ml.num == 0 || EditBoard->IsDefiniteDraw() )
return;
LearnBranch branch;
for ( INT32 offset = baseOffset; offset >= 0; offset = branch.sibling )
{
int ignoreNode = 0;
if ( !tree.read(offset,branch) )
{
lprintf ( "Error reading branch at offset %ld\n", long(offset) );
return;
}
++branch.reserved[0];
tree.write(offset,branch);
if ( !ml.IsLegal(branch.move) )
{
ignoreNode = 1;
if ( branch.move.source != 0 )
{
IllegalMoveFormat ( branch.move, temp );
lprintf ( "Illegal move=%s offset=%ld path=",
temp, long(offset) );
DumpMovePath();
lprintf ( "\n" );
}
}
if ( branch.child >= 0 && !ignoreNode )
{
MoveTable[EditPly] = branch.move;
EditBoard->MakeMove ( branch.move, UnmoveTable[EditPly] );
EditOffset[EditPly] = offset;
EditOffset[++EditPly] = branch.child;
PerformIntegrityCheck ( tree, branch.child );
--EditPly;
EditBoard->UnmakeMove ( branch.move, UnmoveTable[EditPly] );
}
}
EditOffset[EditPly] = baseOffset;
}
示例14: getBlockMove
MoveList ChessPiece::getBlockMove(Move blockMove, MoveList curMoveList) {
MoveList res;
for (auto move : curMoveList)
if (move == blockMove)
res.push_back(move);
return res;
}
示例15: GlobalExchangeEvaluation
Score GlobalExchangeEvaluation(Board &board, std::vector<Move> &pv, Score currentEval, Score lowerBound, Score upperBound)
{
assert(pv.empty());
// try standpat
if (currentEval >= upperBound)
{
return currentEval;
}
else if (currentEval > lowerBound)
{
lowerBound = currentEval;
}
MoveList captures;
board.GenerateAllLegalMoves<Board::VIOLENT>(captures);
std::vector<Move> subPv;
for (size_t i = 0; i < captures.GetSize(); ++i)
{
Score see = StaticExchangeEvaluation(board, captures[i]);
// we only want to search positive SEEs (not even neutral ones), and only if it can possibly improve lowerBound
if ((see < 0) || ((currentEval + see) <= lowerBound))
{
continue;
}
subPv.clear();
PieceType capturedPt = board.GetCapturedPieceType(captures[i]);
board.ApplyMove(captures[i]);
Score score = -GlobalExchangeEvaluation(board, subPv, -(currentEval + SEE_MAT[capturedPt]), -upperBound, -lowerBound);
board.UndoMove();
if (score >= upperBound)
{
return score;
}
if (score > lowerBound)
{
lowerBound = score;
pv.clear();
pv.push_back(captures[i]);
pv.insert(pv.end(), subPv.begin(), subPv.end());
}
}
return lowerBound;
}