当前位置: 首页>>代码示例>>C++>>正文


C++ MoveList::Size方法代码示例

本文整理汇总了C++中MoveList::Size方法的典型用法代码示例。如果您正苦于以下问题:C++ MoveList::Size方法的具体用法?C++ MoveList::Size怎么用?C++ MoveList::Size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MoveList的用法示例。


在下文中一共展示了MoveList::Size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
	}
开发者ID:niklasf,项目名称:chessx,代码行数:32,代码来源:guess.cpp

示例2: 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;
}
开发者ID:GordCaswell,项目名称:lucaschessportable,代码行数:29,代码来源:notation.cpp

示例3: IsGameOver

bool Position::IsGameOver(std::string& message)
{
  bool hasMoves = false;
  MoveList mvlist;
  mvlist.GenAllMoves(*this);
  for (int i = 0; i < mvlist.Size(); ++i)
  {
    if (MakeMove(mvlist[i].m_mv))
    {
      hasMoves = true;
      UnmakeMove();
      break;
    }
  }
  
  if (hasMoves == false)
  {
    if (InCheck())
      message = (m_side == WHITE)? "0-1 {Black mates}" : "1-0 {White mates}";
    else
      message = "1/2-1/2 {Draw: stalemate}";
    return true;
  }

  if (EstimateDraw(*this) == EVAL_THEORETICAL_DRAW)
  {
    message = "1/2-1/2 {Draw: material}";
    return true;
  }

  if (GetRepetitions() >= 3)
  {
    message = "1/2-1/2 {Draw: 3rd repetition}";
    return true;
  }

  return false;
}
开发者ID:GordCaswell,项目名称:lucaschessportable,代码行数:38,代码来源:position.cpp

示例4: pickBest

    // Use chess engine to decide if (from1,to1) is better than (from2,to2) move
	//  it will start from the position given in fen and think for ms milliseconds
	//  0 is returned if the first move is better or 1 if the second is better
	//  -1 is returned on error
	int pickBest(const char* fen, int from1, int to1, int from2, int to2, int ms)
	{
		Position pos;
		pos.ReadFromFEN(fen);

		MoveList mlist;
		pos.GenerateMoves(&mlist);

		mlist.SelectBySquares(from1, to1, from2, to2);
		if (mlist.Size() == 2) {
			Engine * engine = new Engine();
			engine->SetSearchTime(ms);    // Do a "ms" millisecond search
			engine->SetPosition(&pos);
			engine->Think(&mlist);
			delete engine;
			simpleMoveT * sm = mlist.Get(0);
			if (sm->from == from1 && sm->to == to1)
				return 0;
			if (sm->from == from2 && sm->to == to2)
				return 1;
		}
		return -1;
	}
开发者ID:niklasf,项目名称:chessx,代码行数:27,代码来源:guess.cpp

示例5: MoveToStrShort

std::string MoveToStrShort(Move mv, Position& pos)
{
	if (mv == Move(E1, G1, KW) || mv == Move(E8, G8, KB))
		return "O-O";
	if (mv == Move(E1, C1, KW) || mv == Move(E8, C8, KB))
		return "O-O-O";

	PIECE piece = mv.Piece();
	FLD from = mv.From();
	FLD to = mv.To();
	PIECE captured = mv.Captured();
	PIECE promotion = mv.Promotion();
	std::string strFrom, strTo, strPiece, strCaptured, strPromotion;

	switch (piece)
	{
	case PW: case PB:
		if (captured)
			strFrom = FldToStr(from).substr(0, 1);
		break;
	case NW: case NB: strPiece = "N"; break;
	case BW: case BB: strPiece = "B"; break;
	case RW: case RB: strPiece = "R"; break;
	case QW: case QB: strPiece = "Q"; break;
	case KW: case KB: strPiece = "K"; break;
	default: break;
	}

	if (captured)
		strCaptured = "x";

	strTo = FldToStr(to);

	switch (promotion)
	{
	case QW: case QB: strPromotion = "=Q"; break;
	case RW: case RB: strPromotion = "=R"; break;
	case BW: case BB: strPromotion = "=B"; break;
	case NW: case NB: strPromotion = "=N"; break;
	default: break;
	}

	// resolve ambiguity

	int uniq_col = 1;
	int uniq_row = 1;
	bool ambiguity = false;

	int row0 = Row(from);
	int col0 = Col(from);

	MoveList mvlist;
	mvlist.GenAllMoves(pos);

	for (int i = 0; i < mvlist.Size(); ++i)
	{
		Move mvi = mvlist[i].m_mv;

		if (mvi.To() != to)
			continue;
		if (mvi.Piece() != piece)
			continue;
		if (mvi.From() == from)
			continue;
		if (!pos.MakeMove(mvi))
			continue;
		pos.UnmakeMove();

		ambiguity = true; // two or more pieces of the same type can move to field
		int row1 = Row(mvi.From());
		int col1 = Col(mvi.From());

		if (row0 == row1)
			uniq_row = 0;

		if (col0 == col1)
			uniq_col = 0;
	}

	if (ambiguity)
	{
		if (uniq_col)
			strFrom = FldToStr(from).substr(0, 1);
		else if (uniq_row)
			strFrom = FldToStr(from).substr(1, 1);
		else
			strFrom = FldToStr(from);
	}

	return strPiece + strFrom + strCaptured + strTo + strPromotion;
}
开发者ID:GordCaswell,项目名称:lucaschessportable,代码行数:91,代码来源:notation.cpp


注:本文中的MoveList::Size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。