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


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

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


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

示例1:

TEST(MoveListTest, Assignement)
{
    MoveList moves;
    Move m;
    for (int i = 0; i < MAX_PLY; ++i) {
        for (int j = 0; j < MAX_MOVES; ++j) {
            ExtendedMove em1(m, i + j);
            moves[j] = em1;
            EXPECT_EQ(em1, moves[j]);
            EXPECT_EQ(em1.value(), moves[j].value());
        }
        moves.inc_ply();
    }
    for (int i = MAX_PLY - 1; i > 0; --i) {
        moves.dec_ply();
        for (int j = 0; j < MAX_MOVES; ++j) {
            ExtendedMove em1(m, i + j);
            EXPECT_EQ(em1, moves[j]);
            EXPECT_EQ(em1.value(), moves[j].value());
        }
    }
    moves.clear();
    for (int i = 0; i < MAX_PLY; ++i) {
        for (int j = 0; j < MAX_MOVES; ++j) {
            ExtendedMove em1(m, i + j);
            EXPECT_EQ(em1, moves[j]);
            EXPECT_EQ(em1.value(), moves[j].value());
        }
        moves.inc_ply();
    }
}
开发者ID:vinc,项目名称:purplehaze,代码行数:31,代码来源:test_moves.cpp

示例2: generateMoves

void Board::generateMoves(MoveList& list)
{
    int actField, f;

    list.clear();
    for(f=0;f<RealFields;f++) {
	actField = order[f];
	if ( field[actField] == color)
	    generateFieldMoves(actField, list);
    }
}
开发者ID:weidendo,项目名称:qenolaba,代码行数:11,代码来源:Board.cpp

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

示例4: if

/*board is the board right now.  lvl is the lvl of the node we are creating,
  row and col is the position of the most recently added piece. row and col are
  not relevant when lvl is 0 and are invalid*/
Cathy::Node* Cathy::GameTree::CreateTree(int board[][NUMSQUARES],int lvl){
  Node* nn=new Node();
  int whowon;	
  int whomoves=(lvl%2)?-player_:player_;
  MoveList p1;
  MoveList p2;
   MoveList flips;
  int nump1,nump2;
  int r,c;
  int newboard[NUMSQUARES][NUMSQUARES];
  
  wchar_t debugStr[255 + 1];

  
  int maxOrMin = lvl%2; // 0 is max, 1 is min


  if(!canMove(board, p1, p2) || boardFull(board)){   //game over, neither player can move
	  getScores(board,nump1,nump2);
	  if(nump1==nump2)
		  whowon=0; 
	  else if(nump1>nump2)
		  whowon=1;
	  else
		  whowon=-1;		  
     //Base case 1: someone has won the game, game is over score is 100
    if(whowon) {
      nn->score_=whowon * player_* MAXSCORE; //if player_ is 1 and they won the whowon would be +ve so
                                             //we have score being +1, otherwise if player_ is -1 and 
                                             //player 2 won, then whowon would be -1 so score will still
                                             //be +1.
    }
  }
  else if(lvl==height_-1){             //tree has reached its max height
	  
	  nn->score_=Eval(board,player_, p1, p2);    //always evaluate for player at root!
  }
  else{
    if(whomoves==1){
		if(p1.numMoves()==0){
			nn->noMove_=CreateTree(board,lvl+1);
		}
		else{
			for(int i=0,prev_r=0,prev_c=0;i<p1.numMoves();i++){
				p1.getRowCol(i,r,c);
				flips.clear();
 			    addPiece(board,r,c,1,flips);
				if( i == 0 ){							// if it is the first node, then create it 
					nn->child_[r][c] = CreateTree(board,lvl+1);
					prev_r = r, prev_c = c;
				}
				else{
					if(maxOrMin == 0){					//otherwise, check before create, depending on lvl
						if(nn->child_[prev_r][prev_c]->score_ < Eval(board,player_,p1,p2) ){
							nn->child_[prev_r][prev_c] = NULL;
							//delete nn->child_[prev_r][prev_c];
							nn->child_[r][c] = CreateTree(board,lvl+1);
							prev_r = r, prev_c = c;
						}
					}
					else if(maxOrMin ==1){
						if(nn->child_[prev_r][prev_c]->score_ > Eval(board,player_,p1,p2) ){
							nn->child_[prev_r][prev_c] = NULL;
							//delete nn->child_[prev_r][prev_c];
							nn->child_[r][c] = CreateTree(board,lvl+1);
							prev_r = r, prev_c = c;
						}

					}
				}
				/*undo the changes before testing the next move*/
				board[r][c]=0;
				for(int j=0;j<flips.numMoves();j++){
					flips.getRowCol(j,r,c);
					board[r][c]=-1;
				}

			}
		}
	}
	else{
		if(p2.numMoves()==0){
			nn->noMove_=CreateTree(board,lvl+1);
		}
		else{
			for(int i=0,prev_r=0,prev_c=0;i<p2.numMoves();i++){
				
				p2.getRowCol(i,r,c);
				flips.clear();
 			    addPiece(board,r,c,-1,flips);
				if( i == 0 ){							// if it is the first node, the create it 
					nn->child_[r][c] = CreateTree(board,lvl+1);
					prev_r = r, prev_c = c;
				}
				else{
					if(maxOrMin == 0){					//otherwise, check before create, depending on lvl
						if(nn->child_[prev_r][prev_c]->score_ < Eval(board,player_,p1,p2) ){
//.........这里部分代码省略.........
开发者ID:Arcanfel,项目名称:OthelloAI,代码行数:101,代码来源:ashinkevich.cpp


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