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


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

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


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

示例1: alphabeta

/*
 * Alpha/Beta search
 *
 * - first, start with principal variation
 * - depending on depth, we only do depth search for some move types
 */
int ABIDStrategy::alphabeta(int depth, int alpha, int beta)
{
	int currentValue = -14999+depth, value;
	Move m;
	Move bestMove;
	MoveList list;
	bool depthPhase, doDepthSearch;
	int i=0;
	int movecounter =-1;
	int flag=0;

	/* We make a depth search for the following move types... */
	int maxType = (depth < _currentMaxDepth-1)  ? Move::maxMoveType :
		(depth < _currentMaxDepth)    ? Move::maxPushType :
		Move::maxOutType;

	_board->generateMoves(list);

	if (_sc && _sc->verbose()) {
		char tmp[100];
		sprintf(tmp, "Alpha/Beta [%d;%d], %d moves (%d depth)", alpha, beta,
				list.count(Move::none), list.count(maxType));
		_sc->startedNode(depth, tmp);
	}

	/* check for an old best move in principal variation */
	if (_inPV) {
		m = _pv[depth];

		if ((m.type != Move::none) &&
				(!list.isElement(m, 0, true)))
			m.type = Move::none;

		if (m.type == Move::none) _inPV = false;
	}

	// first, play all moves with depth search
	depthPhase = true;

	while (1) {

		pretty_print("movecounter", movecounter);
		movecounter++;
		// get next move
		if (m.type == Move::none) {
			if (depthPhase)
				depthPhase = list.getNext(m, maxType);
			if (!depthPhase)
				if (!list.getNext(m, Move::none)) break;
		}
		if((thread_rank == movecounter% num_threads) || (depth > 0))// we could start with a non-depth move from principal variation
		{
			doDepthSearch = depthPhase && (m.type <= maxType);

			_board->playMove(m);

			/* check for a win position first */
			if (!_board->isValid()) {

				/* Shorter path to win position is better */
				value = 14999-depth;
			}
			else {

				if (doDepthSearch) {
					/* opponent searches for its maximum; but we want the
					 * minimum: so change sign (for alpha/beta window too!)
					 */
					value = -alphabeta(depth+1, -beta, -alpha);
				}
				else {
					value = evaluate();
				}
			}

			_board->takeBack();

			/* best move so far? */
			if (value > currentValue) {
				currentValue = value;
				_pv.update(depth, m);

				if (_sc) _sc->foundBestMove(depth, m, currentValue);
				if (depth == 0)
					_currentBestMove = m;

				/* alpha/beta cut off or win position ... */
				if (currentValue>14900 || currentValue >= beta) {
					if (_sc) _sc->finishedNode(depth, _pv.chain(depth));
					flag = 1;
					break;
					//return currentValue;
				}

//.........这里部分代码省略.........
开发者ID:gkernel,项目名称:supercomputer_lab,代码行数:101,代码来源:search-parallel-abid.cpp

示例2: pv_split

int ABIDStrategy::pv_split(int alpha0, int beta0)
{   
	bool cutoff;
	int depth;
	int value;
    	int currentValue = -15000;
	int slave_id;
	int num_slaves;
	int pending_jobs;
	Slave_Input slave_input;
	Slave_Output *slave_output;
	MPI_Request *rcv_rq;
	MoveList list;
	Move m, *movechain;
	int *alpha, *beta;

	rcv_rq = (MPI_Request *) malloc (num_threads * sizeof(MPI_Request));
	slave_output = (Slave_Output *) malloc (num_threads * sizeof(Slave_Output));
	movechain = (Move*) malloc ((_currentMaxDepth+1)* sizeof (Move));
	alpha = (int*) malloc((_currentMaxDepth+2)*sizeof(int));
	beta = (int*) malloc((_currentMaxDepth+2)*sizeof(int));


	alpha[0] = alpha0;
	beta[0] = beta0;
    	_currentBestMove.type = Move::none;

	// Play moves from the pv until you reach the lowest level
	// If pv-moves are not possible use random moves
	// Store the sequence of moves in movechain
	depth = 0;
	while (depth < (_currentMaxDepth-1)) 
	{
		list.clear();
	    	_board->generateMoves(list);
		m = _pv[depth];

		// check if pv-move is possible
		if ((m.type != Move::none) && (!list.isElement(m, 0, false)))
			m.type = Move::none;
		
		// get random move if pv-move is not possible
		if (m.type == Move::none)
			list.getNext(m, Move::none);

		_board->playMove(m);
		movechain[depth] = m;

		alpha[depth+1] = -beta[depth];
		beta[depth+1] = -alpha[depth];

		depth++;
	}

	// Start at the second lowest level and move back up the gametree
	// Devide the work at each level
	depth = _currentMaxDepth-1;
	while (depth >= 0)
    	{	
		slave_id = 0;
		list.clear();
		_board->generateMoves(list);
		// delete the move we already checked from the list
		if (depth < _currentMaxDepth-1)
			list.isElement(movechain[depth], 0, true);

		strcpy(slave_input.boardstate,_board->getState());
		slave_input.alpha = -beta[depth];
		slave_input.beta = -alpha[depth];
		slave_input.depth = depth+1;
		slave_input.currentMaxDepth = _currentMaxDepth;

		printf("Thread 0 testing %d moves at depth = %d\n",list.getLength(), depth);
		while ( list.getNext(m, Move::none) ) 
		{
			slave_input.move = m;	
			MPI_Send(&slave_input, sizeof(Slave_Input), MPI_BYTE, slave_id+1, 10, MPI_COMM_WORLD);
			MPI_Irecv(&slave_output[slave_id], sizeof(Slave_Output), MPI_BYTE, slave_id+1,
				10, MPI_COMM_WORLD, &rcv_rq[slave_id]);

			slave_id++;

			if (slave_id >= (num_threads-1))
				break;
		}

		num_slaves = slave_id;
		pending_jobs = num_slaves;
		cutoff = false;

		while (pending_jobs > 0)
		{
				MPI_Waitany(num_slaves, rcv_rq, &slave_id, MPI_STATUS_IGNORE);
				_sc->_leavesVisited += slave_output[slave_id].num_leaves;
				_sc->_nodesVisited += slave_output[slave_id].num_nodes;
				value = slave_output[slave_id].eval;
				if (value > currentValue)
				{
					currentValue = value;
					_pv = slave_output[slave_id].pv;
//.........这里部分代码省略.........
开发者ID:gkernel,项目名称:supercomputer_lab,代码行数:101,代码来源:search-abid.cpp

示例3: search

/*
 * We always try the maximize the board value
 */
int Board::search(int depth, int alpha, int beta)
{
    int actValue= -14999+depth, value;
    Move m;
    MoveList list;
    bool depthPhase, doDepthSearch;

    searchCalled++;

    /* We make a depth search for the following move types... */
    int maxType = (depth < maxDepth-1)  ? Move::maxMoveType() :
					  (depth < maxDepth)    ? Move::maxPushType() :
								  Move::maxOutType();

    generateMoves(list);

#ifdef MYTRACE

    int oldRatedPositions;
    int oldWonPositions;
    int oldSearchCalled;
    int oldMoveCount;
    int oldNormalCount;
    int oldPushCount;
    int oldOutCount;
    int oldCutoffCount;

    spyDepth = depth;

    moveCount += list.getLength();

    /*
	  if (spyLevel>1) {
	  indent(depth);
	  qDebug("%s (%6d .. %6d) MaxType %s\n", depth,
	  (color==color1)?"O":"X", alpha,beta,
		 (depth < maxDepth-1) ? "Moving" :
		 (depth < maxDepth)? "Pushing" : "PushOUT" );
	}
	*/
#endif

    /* check for a old best move in main combination */
    if (inPrincipalVariation) {
	m = pv[depth];

	if ((m.type != Move::none) &&
	    (!list.isElement(m, 0, true)))
	    m.type = Move::none;

	if (m.type == Move::none)
	    inPrincipalVariation = false;

#ifdef MYTRACE
	else {
	    if (spyLevel>1) {
		indent(spyDepth);
		qDebug("Got from pv !\n" );
	    }
	}
#endif
    }

    // first, play all moves with depth search
    depthPhase = true;

    while (1) {

	// get next move
	if (m.type == Move::none) {
	    if (depthPhase)
		depthPhase = list.getNext(m, maxType);
	    if (!depthPhase)
		if (!list.getNext(m, Move::none)) break;
	}
	// we could start with a non-depth move from principal variation
	doDepthSearch = depthPhase && (m.type <= maxType);

#ifdef MYTRACE

	if (m.isOutMove()) outCount++;
	else if (m.isPushMove()) pushCount++;
	else normalCount++;

	if (doDepthSearch) {
	    oldRatedPositions = ratedPositions;
	    oldWonPositions = wonPositions;
	    oldSearchCalled = searchCalled;
	    oldMoveCount = moveCount;
	    oldNormalCount = normalCount;
	    oldPushCount = pushCount;
	    oldOutCount = outCount;
	    oldCutoffCount = cutoffCount;

	    if (spyLevel>1) {
		indent(spyDepth);
		qDebug("%s [%6d .. %6d] ",
//.........这里部分代码省略.........
开发者ID:weidendo,项目名称:qenolaba,代码行数:101,代码来源:Board.cpp

示例4: search

/*
 * We always try the maximize the board value
 */
int Board::search(int depth, int alpha, int beta)
{
	int actValue=-16000, value;
	Move m;
	MoveList list;
	bool stop = false;

	/* We make a depth search for the following move types... */
	int maxType = (depth < maxDepth/2) ? Move::maxMoveType() :
	              (depth < maxDepth)   ? Move::maxPushType() : 
                                             Move::maxOutType();

	generateMoves(list);

#ifdef MYTRACE
	printf(">>>>>>>> Depth %d\n", depth);
#endif
	
	/* check for a old best move in main combination */
	if (inMainCombination) {
		m = mc[depth];
		if (!list.isElement(m, 0)) 
		  m.type = Move::none;
		if (m.type == Move::none)
		  inMainCombination = false;
		if (m.type > maxType)
		  m.type = Move::none;
	}
	if (m.type == Move::none)
	  stop = !list.getNext(m, maxType);

	/* depth first search */
	while(!stop) {

#ifdef MYTRACE
	  indent(depth);
	  m.print();
	  printf("\n");
#endif	
		
#ifdef SPION
	  	if (bUpdateSpy) emit update(depth, 0, m, false);
#endif
		playMove(m);
		if (!isValid())
		  value = ((depth < maxDepth) ? 15999:14999) - depth;
		else {
		  /* opponent searches for his maximum; but we won't the
		   * minimum: so change sign (for alpha/beta window too!)
		   */
		  value = - search(depth+1,-beta,-alpha);
		}
		takeBack();

		/* For GUI response */
		if (maxDepth - depth >2)
		  emit searchBreak();		

#ifdef MYTRACE	
		indent(depth);
		printf("=> (%d - %d): Value %d [ %d ] for ",
		       alpha, beta, value,actValue);
		m.print();
	  printf("\n");
#endif

#ifdef SPION
		if (bUpdateSpy) {
		  if (value > actValue)
		    emit updateBest(depth, value, m, value >= beta);
		  emit update(depth, value, m, true);
		}		  
#endif
		if (value > actValue) {
			actValue = value;
			mc.update(depth, m);

			if (bUpdateSpy && depth == 0)
			  emit updateBestMove(m, actValue);
			
			if (actValue >= beta) {
#ifdef MYTRACE
			  indent(depth);
			  printf("CUTOFF\n");
#endif
			  return actValue;
			}			
			if (actValue > alpha) alpha = actValue;
		}
		
		stop = (!list.getNext(m, maxType)) || breakOut;
	}
	
	/* other moves: calculate rating */
	while(list.getNext(m, Move::none)) {
		
		playMove(m);
//.........这里部分代码省略.........
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:101,代码来源:Board.cpp


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