本文整理汇总了C++中Moves类的典型用法代码示例。如果您正苦于以下问题:C++ Moves类的具体用法?C++ Moves怎么用?C++ Moves使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Moves类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SRC
bool ChessBoard::isLegalMove(int mv)
{
int sqSrc, sqDst, pcSrc, pcDst;
sqSrc = SRC(mv);
sqDst = DST(mv);
if (sqSrc==sqDst)
{
return false;
}
pcSrc = m_data[sqSrc];
pcDst = m_data[sqDst];
if (side(pcSrc)==side(pcDst))
{
return false;
}
Moves mvs;
generateMoves(sqSrc, mvs);
for(int i=0; i<mvs.count(); i++)
{
if (mvs[i]==mv)
{
return true;
}
}
return false;
}
示例2: movementOptions
int UltimateTicTacToeMontecarloAI::expand(int leafIndex, Nodes& nodes, int const player) const
{
Node& node = nodes[leafIndex];
node.children.reserve(maxChildren);
Moves options = movementOptions(node.board, node.previousMove);
int turn = node.previousMove > 0 ? otherPlayer(node.board.grids.at(node.previousMove)) : player;
int mostPromisingChildIndex = -1;
int mostPromisingChildScore = 0;
while(node.children.size() < maxChildren && !options.empty())
{
Move move = options.takeAt(qrand() % options.size());
int childIndex = nodes.size();
node.children.append(childIndex);
Board newBoard(node.board);
nodes.append( Node {0, 1, playMove(newBoard, move, turn), move, leafIndex, Node::Children()});
int score = scoreBoard(nodes.last().board, player);
if(score > mostPromisingChildScore || mostPromisingChildIndex < 0)
{
mostPromisingChildIndex = childIndex;
mostPromisingChildScore = score;
}
}
return mostPromisingChildIndex;
}
示例3: gridWinner
UltimateTicTacToeMontecarloAI::Moves UltimateTicTacToeMontecarloAI::movementOptions(Board const& board, int const previousMove) const
{
int gridIndex = previousMove % GRID_SIZE;
bool playAny = previousMove < 0 || gridWinner(board.grids, gridIndex) || gridFull(board.grids, gridIndex);
Moves options;
if(playAny)
{
for(int i = 0; i < BOARD_SIZE; ++i)
{
if(board.grids.at(i) == 0)
{
options.append(i);
}
}
//qDebug() << "Play to any grid," << options.size() << "options";
}
else
{
for(int i = 0; i < GRID_SIZE; ++i)
{
int position = gridIndex * GRID_SIZE + i;
if(board.grids.at(position) == 0)
{
options.append(position);
}
}
//qDebug() << "Play to grid" << gridIndex << "," << options.size() << "options";
}
return options;
}
示例4: ASSERT_MSG
/**
*1手前の指し手を取得
*/
const MoveKif* Notation::getPrevMove() const
{
int pos;
bool ret = false;
pos = this->number() - (*this->current_moves_)[0].number();
ASSERT_MSG(pos >= 0, "内部状態が変?");
MoveKif& move = (*this->current_moves_)[pos];
pos--;
Moves* moves = this->current_moves_;
if (pos < 0 && moves->parent() != nullptr)
{
// 親の分岐を取得
moves = moves->parent();
pos = move.getParentNumber() - (*moves)[0].number();
}
if (pos < 0)
{
return nullptr;
}
return &(*moves)[pos];
}
示例5: Moves
bool Board::IsCheck(Color side)
{
Moves* moves = new Moves();
int j = 0;
for (int i = 0; i < BoardSize * BoardSize; i++)
{
if (this->Chesses[i] != NULL && this->Chesses[i]->GetPlayer()->GetSide() == side)
this->Chesses[i]->GetAvailableMoves(this, moves, true);
for (; j < moves->GetLength(); j++)
{
Move* move = moves->GetMove(j);
Chess* captured = move->GetChessCaptured();
if (captured != NULL && captured->GetChessType() == King)
{
delete moves;
return true;
}
}
}
delete moves;
return false;
}
示例6: generateMoves
int ChessBoard::test1_max(int depth, int& mv)
{
if (depth==0)
{
mv = 0;
return m_vlBlack - m_vlRed;
}
Moves mvs;
//int selfSide = m_sdPlayer;
int best = -999999;
generateMoves(mvs);
for(int i=0; i<mvs.count(); i++)
{
int oldVal = m_vlBlack - m_vlRed;
int pcCapture;
if (makeMove(mvs[i], pcCapture))
{
int temp_mv;
int val = test1_min(depth-1, temp_mv);
if (val>best)
{
best = val;
mv = mvs[i];
}
undoMakeMove(mvs[i], pcCapture);
}
int newVal = m_vlBlack - m_vlRed;
Q_ASSERT(oldVal==newVal);
}
return best;
}
示例7: generateRemove
Moves MoveGenerator::generateOpening(const Board& board) const
{
Moves result;
if(board.getIdleCount() == 0)
{
QMessageBox::critical(0, "error", "idle == 0");
return result;
}
for(int i=0; i<23; ++i)
{
if(board.isEmpty(i))
{
Board next = board.makeChild(); // a clone
next.setManAt(i, board.getSelfColor());
if(next.closeMill(i))
{
Moves removeMoves = generateRemove(next, board.getOpponentColor()); // remove 1 opponent chessman
copy(removeMoves.begin(), removeMoves.end(), back_inserter(result));
}
else
result.push_back(next);
}
}
return result;
}
示例8: generatePawnMoves
void ChessBoard::generatePawnMoves(ChessBoard& board, int sqSrc, Moves& mvs)
{
int sqDst;
if (board.m_sdPlayer != SQ_SIDE(sqSrc))
{
sqDst = sqSrc - 1;
if (IN_BOARD(sqDst) && board.canMove(board, sqSrc, sqDst))
{
mvs.append(ChessBoard::mv(sqSrc, sqDst));
}
sqDst = sqSrc + 1;
if (IN_BOARD(sqDst) && board.canMove(board, sqSrc, sqDst))
{
mvs.append(ChessBoard::mv(sqSrc, sqDst));
}
}
if (board.m_sdPlayer==0)
{
sqDst = sqSrc - 16;
}
else{
sqDst = sqSrc + 16;
}
if (IN_BOARD(sqDst) && board.canMove(board, sqSrc, sqDst))
{
mvs.append(ChessBoard::mv(sqSrc, sqDst));
}
}
示例9: moves
const ConnectThree::Move ConnectThree::CheckTwoOther(const std::bitset<3>& is_player_human) const
{
const Moves moves(GetAllPossibleMoves());
const int nMoves = moves.size();
if (nMoves==0) return CreateInvalidMove();
{
//Get anti-human moves
Moves v;
BOOST_FOREACH(const Move& m, moves)
{
assert(CanDoMove(m));
//Player is human
if (is_player_human[boost::tuples::get<2>(m)])
v.push_back(m);
}
//If there are anti-player moves, choose one at random
if (!v.empty())
{
const Move m = v[std::rand() % v.size()];
assert(CanDoMove(m));
return
boost::tuples::make_tuple(
boost::tuples::get<0>(m),
boost::tuples::get<1>(m),
boost::tuples::get<2>(m));
}
}
示例10: Moves
/*-----------------------------------------------------------------------------*/
void MoveKif::AddBranch(Moves* parent, const Moves& moves)
{
this->branches_.emplace_back(new Moves(moves));
Moves* m = this->branches_.back().get();
m->set_parent(parent);
}
示例11:
Moves BoardC4::get_possible_moves(Token player) const {
Moves moves;
for (Size column=0; column<width; column++) {
if (tokens[column]<=token_for_columns[column]) moves.push_back(new MoveC4(player,column));
}
return moves;
}
示例12: BanAddr
void Shogi::GenerateMoves1Step( Moves& moves, GEN_INFO& info, int dir ){
/************************************************
任意の方向への着手可能手を列挙する。
************************************************/
int from; // 移動元
int to; // 移動先
int n;
int flag;
bool nz;
if( info.dir_p != 0 && dir != info.dir_p && dir != -info.dir_p )
return;
from = info.addr;
to = info.addr + dir;
if( ban[to] == EMPTY || ban[to] & (ksengo^SENGO) ){
if( ( info.flag & MOVE_CAPTURE && ban[to] != EMPTY )
|| ( info.flag & MOVE_NOCAPTURE && ban[to] == EMPTY )
// 新しいGenerateCheckOnBoard内で空き王手のチェックは行う。
/*|| ( info.flag & MOVE_CHECK && IsDiscCheckMove( info.ou2, to, from ) )*/
){
flag = 1;
}
else{
flag = 0;
}
// 着手可能手追加
n = 0;
if( !( info.koma & NARI ) && info.koma != SKI && info.koma != GKI &&
( ( ksengo == SENTE && ( to <= BanAddr(9,3) || from <= BanAddr(9,3) ) ) ||
( ksengo == GOTE && ( to >= BanAddr(1,7) || from >= BanAddr(1,7) ) ) ) )
{
// 成る場合
if( flag || info.flag & MOVE_PROMOTE ||
( info.flag & MOVE_CHECK && IsCheckMove( info.ou2, to, info.koma + NARI ) ) ||
( info.flag & MOVE_NCHECK && !IsCheckMove( info.ou2, to, info.koma + NARI ) )
){
moves.Add( from, to, 1, info.koma );
}
n = 1;
}
nz = !n || Narazu( info.koma, to );
if( !MoveError( info.koma, to ) &&
// 王手の場合でも不成は生成しないように変更
( /*info.flag & MOVE_CHECK ||*/ nz ) )
{
// 成らない場合
if( flag || info.flag & MOVE_NOPROMOTE ||
( info.flag & MOVE_CHECK && IsCheckMove( info.ou2, to, info.koma ) ) ||
( nz && info.flag & MOVE_NCHECK && !IsCheckMove( info.ou2, to, info.koma ) )
){
moves.Add( from, to, 0, info.koma );
}
}
}
}
示例13: showMoves
void ConsoleManager::showMoves() const {
Moves moves;
MoveGenerator::generate(record_.getBoard(), moves);
for (auto ite = moves.begin(); ite != moves.end(); ite++) {
if (record_.getBoard().isValidMoveStrict(*ite)) {
std::cout << ite->toString() << ' ';
}
}
std::cout << std::endl;
}
示例14: HasMove
bool Board::HasMove(Color side)
{
Moves* moves = this->GetAllAvailableMoves(side);
bool has_move = moves->GetLength() > 0;
delete moves;
return has_move;
}
示例15: build_path
void build_path(ull_t v, const Searched & searched, Moves & steps) {
Searched::const_iterator it = searched.find(v);
while (it != searched.end()) {
const State & s = it->second;
steps.push_back(s.step);
it = searched.find(s.parent);
}
//pop up the first step, which must be 0, rather than one of U,D,L,R
steps.pop_back();
reverse(steps.begin(), steps.end());
}