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


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

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


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

示例1: randomMove

Move Board::randomMove()
{
    Move m;
    MoveList list;

    generateMoves(list);
    int l = list.getLength();

    int j = (::rand() % l) +1;

    while(j != 0) {
        list.getNext(m, Move::none);
        j--;
    }

    return m;
}
开发者ID:gkernel,项目名称:supercomputer_lab,代码行数:17,代码来源:board.cpp

示例2: randomMove

Move Board::randomMove()
{
    Move m;
    MoveList list;

    generateMoves(list);
    int l = list.getLength();

    // FIXME: start with random seed using qsrand() somewhere
    int j = (qrand() % l) +1;

    while(j != 0) {
	list.getNext(m, Move::none);
	j--;
    }

    return m;
}
开发者ID:weidendo,项目名称:qenolaba,代码行数:18,代码来源:Board.cpp

示例3: randomMove

Move Board::randomMove()
{
	static int i = 999;
	unsigned int j,l;

	Move m;
	MoveList list;
	
	/* we prefer to use QT... */
	j = (QTime::currentTime()).msec();
	
	generateMoves(list);
	l = list.getLength();

	j = (j + i) % l +1;
	if ( (i+=7)>10000) i-=10000;
	
	while(j != 0) {
		list.getNext(m, Move::none);
		j--;
	}	
	
	return m;
}
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:24,代码来源:Board.cpp

示例4: 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

示例5: 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

示例6: moveToReach

Move Board::moveToReach(Board* b, bool fuzzy)
{
    Move m;

    /* can not move from invalid position */
    int state = validState();
    if ((state != valid1) && (state != valid2))
        return m;

    if (!fuzzy) {
        if (b->moveNo() != _moveNo+1) {
            if (_verbose)
                printf("Board::moveToReach: moveNo %d => %d ?!\n",
                       _moveNo, b->moveNo());
            return m;
        }
        /* only time left for player can have decreased */
        int opponent = (color == color1) ? color2 : color1;
        if (_msecsToPlay[opponent] != b->msecsToPlay(opponent)) {
            if (_verbose)
                printf("Board::moveToReach: Opponent time changed ?!\n");
            return m;
        }
        if (_msecsToPlay[color] < b->msecsToPlay(color)) {
            if (_verbose)
                printf("Board::moveToReach: Player time increased ?!\n");
            return m;
        }
    }

    /* detect move drawn */
    MoveList l;
    generateMoves(l);

    if (_verbose) {
        printf("Board::moveToReach - %d allowed moves:\n",
               l.getLength());
        Move found;
        int type = Move::none;
        while(l.getNext(m, Move::maxMoveType)) {
            playMove(m);

            bool isSame = hasSameFields(b);
            takeBack();
            if (isSame) found = m;

            if (m.type != type) {
                type = m.type;
                printf(" %s:\n", m.typeName());
            }
            printf("  %s%s\n", m.name(), isSame ? " <== Choosen":"");
        }
        m = found;
    }
    else {
        while(l.getNext(m, Move::maxMoveType)) {
            playMove(m);

            bool isSame = hasSameFields(b);
            takeBack();
            if (isSame) break;
        }
    }

    return m;
}
开发者ID:gkernel,项目名称:supercomputer_lab,代码行数:66,代码来源:board.cpp

示例7: play


//.........这里部分代码省略.........


					break;
				}

				if (sliding != gameSettings->getSliding() && bestMove > 0)
				{
					sliding = gameSettings->getSliding();
					board->setSliding(sliding);

					initTime();
					playAgain = 1;
					break;
				}

				::Sleep(10);
			}
		} while (playAgain);

		if (gameSettings->isStepModeOn())
			gameSettings->setStepWait();

		if (!animate && bestMove > 0)
		{
			bestPiece.setPiece();

			if (bestPiece.getClearedLines() > 0)
				board->clearLines(bestPiece.getY(), bestPiece.getHeight());
		}

		Move *move;
		int index = 0;

		int length = moveList->getLength();

		totalMoves += length;

		if (animate && bestMove > 0)
		{
			// Animate the moves.
			MovePath *movePath = board->getMovePath(level);
			MovePathStep *s = movePath->getPath(bestMove->getV(), bestMove->getX(), bestMove->getY());

			int skipFirst = 0;

			int prevy = -1;

			while (s > 0)
			{
				//----
				// Calculate the number of steps for the current line (y value).
				MovePathStep *s1 = s;
				int y1 = s1->y;
				int cnt;

				if (prevy != y1)
				{
					cnt = 0;

					while (s1 > 0 && s1->y == y1) {
						cnt++;
						s1 = s1->next;
					}
					prevy = y1;
				}
				//----
开发者ID:tengstrand,项目名称:tetrisanalyzer,代码行数:67,代码来源:Game.cpp


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