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


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

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


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

示例1: doCaptures

int Board::doCaptures(Player victim, Move seed) {
    if (pieces[index(getX(seed), getY(seed))] != victim)
        return 0;

    Stone *visited = new Stone[arraySize*arraySize];
    for (int i = 0; i < arraySize*arraySize; i++) {
        visited[i] = 0;
    }
    MoveList captured;

    if (isSurrounded(victim, EMPTY, getX(seed), getY(seed), visited, captured)) {
        if (updateBoard) {
            for (unsigned int i = 0; i < captured.size(); i++) {
                Move m = captured.get(i);
                pieces[index(getX(m), getY(m))] = EMPTY;
                zobristKey ^= zobristTable[zobristIndex(victim, getX(m), getY(m))];
            }

            // Record how many pieces were captured for scoring purposes
            if (victim == BLACK)
                whiteCaptures += captured.size();
            else
                blackCaptures += captured.size();
        }
    }

    delete[] visited;
    return captured.size();
}
开发者ID:jeffreyan11,项目名称:go-engine,代码行数:29,代码来源:board.cpp

示例2: _find_deep_capture_queen

void MoveGenEnglish::_find_deep_capture_queen(MoveList& moves, Move& move, int8_t row, int8_t column, bool(&captured)[8][8]) const
{
	static constexpr int d_row[4] = { 1, 1, -1, -1 }, d_column[4] = { 1, -1, 1, -1 };
	for (size_t dir = 0; dir < 4; ++dir)
	{
		// In english checkers we can jump only over adjacent pieces
		const int r1 = row + d_row[dir], c1 = column + d_column[dir], r2 = r1 + d_row[dir], c2 = c1 + d_column[dir];
		if (r2 < 0 || c2 < 0 || r2 > 7 || c2 > 7 || board[r2][c2].get_type() != PT_EMPTY
			|| board[r1][c1].get_colour() != opposite(TURN) || captured[r1][c1])
			continue;
		move.add_step(Position(r2, c2)); // Correct capture-move
		move.add_capture(std::make_pair(Position(r1, c1), board[r1][c1]));
		const size_t old = moves.size();
		captured[r1][c1] = true; // For preventing 'recapturing' piece at (r1; c1) in moves produced by recursive call to this function(next 4 lines)
		_find_deep_capture_queen<TURN>(moves, move, r2, c2, captured);
		if (old == moves.size()) // If in recursive call we haven't found any move, then 'move' is a final capture and is one of possible captures
		{
			move.set_become(Piece(TURN == WHITE ? WHITE_QUEEN : BLACK_QUEEN));
			moves.emplace(move);
		}
		captured[r1][c1] = false; // For correct work on next cycles we should clear changes to 'captured' and 'move' variables
		move.pop_step();
		move.pop_capture();
	}
}
开发者ID:YurkoFlisk,项目名称:checkers,代码行数:25,代码来源:move_gen.cpp

示例3: _find_deep_capture

void MoveGenEnglish::_find_deep_capture(MoveList& moves, Move& move, int8_t row, int8_t column) const
{
	static constexpr int d_row = (TURN == WHITE ? 1 : -1), d_column[2] = { 1, -1 };
	const int r1 = row + d_row, r2 = r1 + d_row;
	if (r2 < 0 || r2 > 7)
		return;
	for (size_t dir = 0; dir < 2; ++dir)
	{
		const int c1 = column + d_column[dir], c2 = c1 + d_column[dir];
		if (c2 < 0 || c2 > 7 || board[r2][c2].get_type() != PT_EMPTY
			|| board[r1][c1].get_colour() != opposite(TURN))
			continue;
		move.add_step(Position(r2, c2)); // Correct capture-move
		move.add_capture(std::make_pair(Position(r1, c1), board[r1][c1]));
		const size_t old = moves.size();
		if (TURN == WHITE ? (r2 == 7) : (r2 == 0)) // We can become queen at this move
		{
			move.set_become(Piece(TURN == WHITE ? WHITE_QUEEN : BLACK_QUEEN)); // In english checkers move is stopped when piece becomes queen
			moves.emplace(move);
		}
		else
		{
			_find_deep_capture<TURN>(moves, move, r2, c2);
			if (old == moves.size()) // If in recursive call we haven't found any move, then 'move' is a final capture and is one of possible captures
			{
				move.set_become(Piece(TURN == WHITE ? WHITE_SIMPLE : BLACK_SIMPLE));
				moves.emplace(move);
			}
		}
		move.pop_step();
		move.pop_capture();
	}
}
开发者ID:YurkoFlisk,项目名称:checkers,代码行数:33,代码来源:move_gen.cpp

示例4: playRandomGame

//------------------------------------------------------------------------------
//-------------------------------MCTS Methods-----------------------------------
//------------------------------------------------------------------------------
void playRandomGame(Player p, Board &b) {
    int movesPlayed = 1;
    int i = 0;
    Move last = MOVE_PASS;

    // Regenerate the movelist up to 4 times
    while (movesPlayed > 0 && i < 4) {
        movesPlayed = 0;
        i++;
        MoveList legalMoves = b.getLegalMoves(p);
        int koCount = 0;

        // While we still have legal moves remaining
        while (legalMoves.size() > 0) {
            // Check if the last move put its own chain into atari
            // Do not do this twice in a row to prevent infinite ko recapture
            if (koCount == 0) {
                Move cap = b.getPotentialCapture(last);
                if (cap != MOVE_PASS) {
                    int ci = legalMoves.find(cap);
                    if (ci != -1)
                        legalMoves.removeFast(ci);
                    
                    b.doMove(p, cap);
                    last = cap;
                    p = otherPlayer(p);
                    movesPlayed++;
                    koCount++;
                    continue;
                }
            }

            // Otherwise, pick a move at random
            std::uniform_int_distribution<int> distribution(0, legalMoves.size()-1);
            int index = distribution(rng);
            Move m = legalMoves.get(index);

            // Only play moves that are not into own eyes and not suicides
            if (!b.isEye(p, m) && b.isMoveValid(p, m)) {
                b.doMove(p, m);
                last = m;
                p = otherPlayer(p);
                movesPlayed++;
                koCount = 0;
            }

            legalMoves.removeFast(index);
        }
    }
}
开发者ID:jeffreyan11,项目名称:go-engine,代码行数:53,代码来源:search.cpp

示例5: printer

DecoratedMoveList::DecoratedMoveList(Position * const parent)
	: move_list_(),
	  best_move_num_(0),
	  n_best_moves_(0),
	  human_(false) {
	if (parent->no_pieces())
		return;

	MoveList * successors = parent->generate_all_moves();
	MovePrinter printer(parent);

	Position * move;
	State state;

	move_list_.reserve(successors->size());

	for (const Move * it = successors->first(); it != nullptr; it = it->next_) {
		parent->do_move(it->move_, state);
		move = new Position(parent);
		parent->undo_move(state);

		move_list_.push_back(new DecoratedPosition(move, printer.decode_move(move, it->move_), NULL_SCORE));
	}

	delete successors;
}
开发者ID:joca-bt,项目名称:Turska,代码行数:26,代码来源:decorators.cpp

示例6: generateMoves

uchar Board0x88::generateOpponentMoves(MoveList & moveList)
{
  uchar sideToMove = mSideToMove;
  mSideToMove = !mSideToMove;
  generateMoves(moveList);
  mSideToMove = sideToMove;
  return moveList.size();
}
开发者ID:jeffmeese,项目名称:simple-chess,代码行数:8,代码来源:board0x88.cpp

示例7: if

uchar Board0x88::generateMoves(MoveList & moveList)
{
  generateCastlingMoves(moveList);

  for (uchar i = 0; i < 8; i++) {
    for (uchar col = 0; col < 8; col++) {

    //for (uchar index = 0; index < 120; index++) {
      uint index = getIndex(7-i, col);
      if (mColors[index] == mSideToMove) {
        if (mPieces[index] == Pawn) {
          generatePawnMoves(index, moveList);
          generatePawnCaptures(index, moveList);
        }
        else {
          uchar pieceType = mPieces[index];
          for (uchar num = 0; num < mNumDirections[pieceType]; num++) {
            for (uchar pos = index;;) {
              pos = pos + mDirectionVectors(pieceType, num);

              if (!isValidSquare(pos))
                break;

              if (mColors[pos] == ColorEmpty) {  // Standard move
                pushMove(index, pos, pieceType, PieceEmpty, MoveNormal, moveList);
              }
              else if (mColors[pos] != mSideToMove) { // Capture move
                pushMove(index, pos, pieceType, mPieces[pos], MoveCapture, moveList);
                break;
              }
              else {
                break;
              }

              // Break on non-sliding pieces (King, Knight)
              if (!mSliders[pieceType])
                break;
            }
          }
        }
      }
    }
  }
  return moveList.size();
}
开发者ID:jeffmeese,项目名称:simple-chess,代码行数:45,代码来源:board0x88.cpp

示例8: perft

/*
 * Performs a PERFT (performance test). Useful for testing/debugging
 * PERFT n counts the number of possible positions after n moves by either side,
 * ex. PERFT 4 = # of positions after 2 moves from each side
 *
 * 7/8/15: PERFT 5, 1.46 s (i5-2450m)
 * 7/11/15: PERFT 5, 1.22 s (i5-2450m)
 * 7/13/15: PERFT 5, 1.08 s (i5-2450m)
 * 7/14/15: PERFT 5, 0.86 s (i5-2450m)
 * 7/17/15: PERFT 5, 0.32 s (i5-2450m)
 * 8/7/15: PERFT 5, 0.25 s, PERFT 6, 6.17 s (i5-5200u)
 * 8/8/15: PERFT 6, 5.90 s (i5-5200u)
 * 8/11/15: PERFT 6, 5.20 s (i5-5200u)
 */
uint64_t perft(Board &b, int color, int depth, uint64_t &captures) {
    if (depth == 0)
        return 1;

    uint64_t nodes = 0;

    MoveList pl;
    b.getAllPseudoLegalMoves(pl, color);
    for (unsigned int i = 0; i < pl.size(); i++) {
        Board copy = b.staticCopy();
        if (!copy.doPseudoLegalMove(pl.get(i), color))
            continue;

        if (isCapture(pl.get(i)))
            captures++;

        nodes += perft(copy, color^1, depth-1, captures);
    }

    return nodes;
}
开发者ID:raimarHD,项目名称:lcec,代码行数:35,代码来源:uci.cpp

示例9: SearchForNewMods

void CMissionManager::SearchForNewMods()
{
	// List all PK4s in the fms/ directory
	MoveList moveList = SearchForNewMods(".pk4");
	MoveList zipMoveList = SearchForNewMods(".zip");

	// Merge the zips into the pk4 list
	if (!zipMoveList.empty())
	{
		moveList.merge(zipMoveList);
	}

	DM_LOG(LC_MAINMENU, LT_INFO)LOGSTRING("Found %d new mission packages.\r", static_cast<int>(moveList.size()));
	gameLocal.Printf("Found %d new mission packages.\n", static_cast<int>(moveList.size()));

	// greebo: The D3 engine should no longer hold locks on those files
	// and we can start moving them into their respective locations
	for (MoveList::const_iterator i = moveList.begin(); i != moveList.end(); ++i)
	{
		fs::path targetPath = i->second;

		// Remove any target file first, to overwrite when moving
		DoRemoveFile(targetPath);

		// Move the file
		DoMoveFile(i->first, targetPath);
		
		// Remove the file portion
		targetPath.remove_leaf();

		// Remove any darkmod.txt, splashimage etc. when copying a new PK4. It may contain updated versions of those.
		DoRemoveFile(targetPath / cv_tdm_fm_desc_file.GetString());
		DoRemoveFile(targetPath / cv_tdm_fm_splashimage_file.GetString());
		DoRemoveFile(targetPath / cv_tdm_fm_notes_file.GetString());
	}
}
开发者ID:jaredmitch,项目名称:executable,代码行数:36,代码来源:MissionManager.cpp

示例10: alphaBeta

int Search::alphaBeta(bool white_turn, int depth, int alpha, int beta, Board& board, Transposition *tt,
		bool null_move_in_branch, Move (&killers)[32][2], int (&history)[64][64], int ply) {

	// If, mate we do not need search at greater depths
	if (board.b[WHITE][KING] == 0) {
		return -10000;
	} else if (board.b[BLACK][KING] == 0) {
		return 10000;
	}
	if (depth == 0) {
		return capture_quiescence_eval_search(white_turn, alpha, beta, board);
	}
	if (depth == 1) {
		// futility pruning. we do not hope for improving a position more than 300 in one move...
		int static_eval = evaluate(board);
		if (white_turn && (static_eval + 300) < alpha) {
			return capture_quiescence_eval_search(white_turn, alpha, beta, board);
		}
		if (!white_turn && (static_eval - 300) > beta) {
			return capture_quiescence_eval_search(white_turn, alpha, beta, board);
		}
	}
	if (depth == 2) {
		// extended futility pruning. we do not hope for improving a position more than 500 in two plies...
		// not really proven to +ELO but does not worse performance at least
		int static_eval = evaluate(board);
		if ((white_turn && (static_eval + 500) < alpha) || (!white_turn && (static_eval - 500) > beta)) {
			return capture_quiescence_eval_search(white_turn, alpha, beta, board);
		}
	}

	// null move heuristic - we do this despite in check..
	if (!null_move_in_branch && depth > 3) {
		// skip a turn and see if and see if we get a cut-off at shallower depth
		// it assumes:
		// 1. That the disadvantage of forfeiting one's turn is greater than the disadvantage of performing a shallower search.
		// 2. That the beta cut-offs prunes enough branches to be worth the time searching at reduced depth
		int R = 2; // depth reduction
		int res = alphaBeta(!white_turn, depth - 1 - R, alpha, beta, board, tt, true, killers, history, ply + 1);
		if (white_turn && res > alpha) {
			alpha = res;
		} else if (!white_turn && res < beta) {
			beta = res;
		}
		if (beta <= alpha) {
			if (white_turn) {
				return alpha;
			}
			return beta;
		}
	}
	MoveList moves = get_children(board, white_turn);
	if (moves.empty()) {
		return 0;
	}
	Transposition tt_pv = tt[board.hash_key % HASH_SIZE];
	for (auto it = moves.begin(); it != moves.end(); ++it) {
		// sort pv moves first
		if (tt_pv.next_move != 0 && tt_pv.hash == board.hash_key && tt_pv.next_move == it->m) {
			it->sort_score += 1100000;
		}
		// ...then captures in MVVLVA order
		if (!is_capture(it->m)) {
			// killer moves are quite moves that has previously led to a cut-off
			if (killers[ply - 1][0].m == it->m) {
				it->sort_score += 999999;
			} else if (killers[ply - 1][1].m == it->m) {
				it->sort_score += 899999;
			} else {
				// "history heuristics"
				// the rest of the quite moves are sorted based on how often they increase score in the search tree
				it->sort_score += history[from_square(it->m)][to_square(it->m)];
			}
		}
	}
	total_generated_moves += moves.size();

	Transposition t;
	t.hash = board.hash_key;
	int next_move = 0;
	for (unsigned int i = 0; i < moves.size(); ++i) {
		// late move reduction.
		// we assume sort order is good enough to not search later moves as deep as the first 4
		if (depth > 5 && i == 10) {
			depth -= 2;
		}

		pick_next_move(moves, i);
		Move child = moves[i];
		node_count++;
		make_move(board, child);

		int res = alphaBeta(!white_turn, depth - 1, alpha, beta, board, tt, null_move_in_branch, killers, history,
				ply + 1);
		unmake_move(board, child);
		if (res > alpha && res < beta) {
			// only cache exact scores

		}

//.........这里部分代码省略.........
开发者ID:phenri,项目名称:gunborg,代码行数:101,代码来源:Search.cpp

示例11: reportPosition

void Reporter::reportPosition(const GamePosition &position, ComputerPlayer *computerPlayer, UVString *report)
{
	UVOStringStream s;

	UVOStringStream titleStream;

	if (!position.gameOver())
		titleStream << position.currentPlayer().name() << MARK_UV(": Turn ") << position.turnNumber() << MARK_UV('\n');

	const Quackle::PlayerList players(position.endgameAdjustedScores());

	for (PlayerList::const_iterator it = players.begin(); it != players.end(); ++it)
	{
		s.width(3);
		s << right << ((*it) == position.currentPlayer()? MARK_UV("->") : MARK_UV(" "));
		s << MARK_UV(' ');
		s.width(24);
		s << left << (*it).name() << MARK_UV(' ');
		s.width(9);
		s << (*it).rack().toString() << MARK_UV(' ');
		s.width(4);
		s << (*it).score();
		s << MARK_UV('\n');
	}

	if (computerPlayer && !position.gameOver())
	{
		computerPlayer->setPosition(position);

		if (position.committedMove().isAMove())
			computerPlayer->considerMove(position.committedMove());

		const unsigned int movesToShow = 10;
		MoveList moves = computerPlayer->moves(movesToShow);

		int ourMoveIndex = 0;
		int i = 1;
		for (Quackle::MoveList::const_iterator it = moves.begin(); it != moves.end(); ++it, ++i)
		{
			if ((*it) == position.committedMove())
			{
				ourMoveIndex = i;
				break;
			}
		}

		bool isUrp = false;

		if (position.committedMove().isAMove())
		{
			// our move not in list
			if (ourMoveIndex == 0)
			{
				if (moves.size() == movesToShow)
					moves.pop_back();

				isUrp = true;
				ourMoveIndex = movesToShow;
				moves.push_back(position.committedMove());
			}
		}

		int highestScore = 0;
		double highestEquity = 0;
		unsigned int widestPositionString = 0;
		unsigned int widestMove = 0;
		bool hasWinPercentages = false;
		const Quackle::MoveList::const_iterator end(moves.end());
		for (Quackle::MoveList::const_iterator it = moves.begin(); it != end; ++it)
		{
			if ((*it).prettyTiles().length() > widestMove)
				widestMove = (*it).prettyTiles().length();
			if ((*it).positionString().length() > widestPositionString)
				widestPositionString = (*it).positionString().length();
			if ((*it).win > 0)
				hasWinPercentages = true;
			if ((*it).equity > highestEquity)
				highestEquity = (*it).equity;
			if ((*it).score > highestScore)
				highestScore = (*it).score;
		}

		s << MARK_UV("--");

		UVOStringStream headerStream;
		headerStream << computerPlayer->name();

		headerStream << "'s choices (your play: ";
		if (isUrp)
			headerStream << "urp";
		else
			headerStream << ourMoveIndex;
		headerStream << ")";

		s.width(43);
		s << setfill(MARK_UV('-'));
		s << left << headerStream.str() << MARK_UV('\n');
		s << setfill(MARK_UV(' '));

		i = 1;
//.........这里部分代码省略.........
开发者ID:cdhowie,项目名称:Quackle,代码行数:101,代码来源:reporter.cpp

示例12: eval

int Board::eval(Color caller) const{
	HeuristicWeight& weight=(caller==BLACK)?heuristicWeight[0]:heuristicWeight[1];

	int score=0;
	int pieceScore=0;
	int cornersScore=0;
	int edgeScore=0;
	int xScore=0;
	int mobilityScore=0;
	int stablePieceScore=0;


	//pieceScore
	int blackPiece,whitePiece;
	countPiece(blackPiece,whitePiece);
	if(caller==BLACK)
		pieceScore= blackPiece-whitePiece;
	else
		pieceScore= whitePiece-blackPiece;

	//endGameSolver
	if(weight.useEndgemeSolver && getState()==ENDGAME){
		return pieceScore;
	}


	
	if(isFull())
		return pieceScore;

	//stability
	if(weight.stablePieceW!=0){
		int blackStablePiece,whiteStablePiece;
		countStablePiece(blackStablePiece,whiteStablePiece);
		if(caller==BLACK)
			stablePieceScore=blackStablePiece-whiteStablePiece;
		else
			stablePieceScore=whiteStablePiece-blackStablePiece;
	}


	Color rival=Rival(caller);

	//special position
	cornersScore=positionCount(caller,corners)-positionCount(rival,corners);
	edgeScore=positionCount(caller,Edges)-positionCount(rival,Edges);
	xScore=positionCount(caller,XSquares)-positionCount(rival,XSquares);

	//mobility
	if(weight.mobilityW!=0){
		MoveList callerMovelist;
		MoveList rivalMoveList;
		getValidMove(caller,callerMovelist,true);
		getValidMove(rival,rivalMoveList,true);
		mobilityScore=callerMovelist.size()-rivalMoveList.size();
	}

	//total
	score=	weight.pieceW*pieceScore+
	  		weight.edgeW*edgeScore+
	  		weight.cornerW*cornersScore+
	  		weight.XSquareW*xScore+
			weight.mobilityW*mobilityScore+
			weight.stablePieceW*stablePieceScore;
	return score;

}
开发者ID:georgemouse,项目名称:othello,代码行数:67,代码来源:board.cpp

示例13: moves

MoveList SmartBogowin::moves(int nmoves)
{
	Stopwatch stopwatch;
	
	if (currentPosition().bag().empty())
    {
        signalFractionDone(0);
		EndgamePlayer endgame;
		endgame.setPosition(currentPosition());
		return endgame.moves(nmoves);
	}

    // TODO
    // Move this all to an Inferrer class
    //
    // Generate all moves for all racks opp could have had.
    // This can be done efficiently by making a big "rack" out of the bag (with the computer
    // player's own rack removed) and generating moves from that big "rack" with some smarts
    // added to the move generator to not create moves that have so many tiles not in the
    // opp's play that they wouldn't have been possible from any of the racks we're looking
    // for. Make a ProbableRackList of racks from which the opp's play is best or nearly
    // (really what we're looking for is least bad). Most heavily weight the leaves for which
    // the play is as close to optimal as possible (an x-point static mistake), and let the
    // weights taper off to zero as the mistakes approach say x+7.
    //
    // Make the Simulator able to select racks randomly from the ProbableRackList
    if (m_parameters.inferring) {
        int numPlayers = currentPosition().players().size();
        UVcout << "numPlayers: " << numPlayers << endl;
        if (numPlayers == 2) {
            bool hasPreviousPosition;
            GamePosition previous = m_simulator.history().previousPosition(&hasPreviousPosition);
            if (hasPreviousPosition) {
                UVcout << "previous position:" << endl;
                UVcout << previous << endl;
            } else {
                UVcout << "no previous position" << endl;
            }
        }
    }

	UVcout << "SmartBogowin generating move from position:" << endl;
	UVcout << currentPosition() << endl;

	const int zerothPrune = 33;
	int plies = 2;
	
	if (currentPosition().bag().size() <= QUACKLE_PARAMETERS->rackSize() * 2)
		plies = -1;

	const int initialCandidates = m_additionalInitialCandidates + nmoves;
	
	currentPosition().kibitz(initialCandidates);
	
	m_simulator.setIncludedMoves(m_simulator.currentPosition().moves());
	m_simulator.pruneTo(zerothPrune, initialCandidates);
	m_simulator.makeSureConsideredMovesAreIncluded();
	m_simulator.setIgnoreOppos(false);
	
	MoveList staticMoves = m_simulator.moves(/* prune */ true, /* sort by equity */ false);
	m_simulator.moveConsideredMovesToBeginning(staticMoves);
	
	//UVcout << "Bogo static moves: " << staticMoves << endl;
	//UVcout << "Bogo considered moves: " << m_simulator.consideredMoves() << endl;
	
	MoveList firstMove;
	MoveList simmedMoves;

	MoveList::const_iterator it = staticMoves.begin();
	
	firstMove.push_back(*it);

	signalFractionDone(0);

	m_simulator.setIncludedMoves(firstMove);
	m_simulator.simulate(plies, minIterations());
	
	Move best = *m_simulator.moves(/* prune */ true, /* sort by win */ true).begin();
	simmedMoves.push_back(best);
	
	double bestbp = bogopoints(best);
	
	//UVcout << "firstMove: " << best << endl;

	for (++it; it != staticMoves.end(); ++it)
	{
		signalFractionDone(max(static_cast<float>(simmedMoves.size()) / static_cast<float>(staticMoves.size()), static_cast<float>(stopwatch.elapsed()) / static_cast<float>(m_parameters.secondsPerTurn)));

		if (shouldAbort())
			goto sort_and_return;

		//UVcout << "best move: " << best << " with " << bestbp  << " bogopoints." << endl;
		MoveList lookFurther;
		lookFurther.push_back(*it);
		m_simulator.setIncludedMoves(lookFurther);
		m_simulator.simulate(plies, minIterations());
		Move move = *m_simulator.moves(/* prune */ true, /* sort by win */ true).begin();
		double movebp = bogopoints(move);
		//UVcout << "we just simmed " << move << "; bogopoints: " << movebp << endl;
	
//.........这里部分代码省略.........
开发者ID:domino14,项目名称:quackle,代码行数:101,代码来源:bogowinplayer.cpp

示例14: generateMove

Move generateMove(Player p, Move lastMove) {
    MoveList legalMoves = game.getLegalMoves(p);
    MoveList localMoves = game.getLocalMoves(lastMove);

    // Pass if every move is either into your own eye, a suicide, or places
    // a chain into atari
    bool playPass = true;
    for (unsigned int n = 0; n < legalMoves.size(); n++) {
        Board copy = Board(game);
        Move m = legalMoves.get(n);

        if (!copy.isMoveValid(otherPlayer(p), m) && copy.isEye(p, m))
            continue;

        if (!copy.isMoveValid(p, m))
            continue;

        copy.doMove(p, m);
        if (copy.isInAtari(m))
            continue;

        playPass = false;
        break;
    }

    if (playPass)
        return MOVE_PASS;


    MCTree searchTree;
    float komiAdjustment = 0.0;
    Move captureLastStone = game.getPotentialCapture(lastMove);
    Move potentialEscape = game.getPotentialEscape(p, lastMove);

    // Add all first-level moves
    for (unsigned int n = 0; n < legalMoves.size(); n++) {
        Board copy = Board(game);
        Player genPlayer = p;

        Move next = legalMoves.get(n);
        // Check legality of moves (suicide)
        if (!copy.isMoveValid(genPlayer, next))
            continue;

        copy.doMove(genPlayer, next);
        // Never place own chain in atari
        if (copy.isInAtari(next))
            continue;

        // Check for ko rule violation
        bool koViolation = false;
        if (next != MOVE_PASS) {
            uint64_t newKey = copy.getZobristKey();
            for (int i = keyStackSize-1; i >= 0; i--) {
                if (newKey == keyStack[i]) {
                    koViolation = true;
                    break;
                }
            }
        }
        if (koViolation)
            continue;

        // First level moves are added to the root
        MCNode *leaf = searchTree.root;
        MCNode *addition = new MCNode();
        addition->parent = leaf;
        addition->m = next;

        // Play out a random game. The final board state will be stored in copy.
        playRandomGame(otherPlayer(genPlayer), copy);

        // Score the game
        float myScore = 0.0, oppScore = 0.0;
        scoreGame(genPlayer, copy, myScore, oppScore);
        if (myScore > oppScore)
            addition->numerator++;
        addition->scoreDiff = ((int) myScore) - ((int) oppScore);
        komiAdjustment += myScore - oppScore;

        // Add the new node to the tree
        leaf->children[leaf->size] = addition;
        leaf->size++;

        // Backpropagate the results
        searchTree.backPropagate(addition);

        // Do priors, if any
        // Own eye and opening priors inspired by Pachi,
        // written by Petr Baudis and Jean-loup Gailly
        int basePrior = boardSize * boardSize / 8;
        // Discourage playing into own eyes
        if (game.isEye(genPlayer, next)) {
            addition->denominator += basePrior;
            // If this eye is not ko-related we almost certainly should not play
            // in it
            if (!game.isMoveValid(otherPlayer(genPlayer), next)) {
                addition->denominator += 10 * basePrior;
                addition->scoreDiff -= 10 * 360;
            }
//.........这里部分代码省略.........
开发者ID:jeffreyan11,项目名称:go-engine,代码行数:101,代码来源:search.cpp


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