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


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

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


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

示例1: getLocalMoves

MoveList Board::getLocalMoves(Move m) {
    MoveList localMoves;

    if (m == MOVE_PASS)
        return localMoves;
    int x = getX(m);
    int y = getY(m);
    assert(pieces[index(x, y)] != EMPTY);

    Chain *node = nullptr;
    searchChainsByID(node, chainID[index(x, y)]);
    for (int i = 0; i < node->liberties; i++)
        localMoves.add(node->libertyList[i]);

    if (chainID[index(x+1, y)]
     && chainID[index(x+1, y)] != chainID[index(x, y)]) {
        node = nullptr;
        searchChainsByID(node, chainID[index(x+1, y)]);
        for (int i = 0; i < node->liberties; i++)
            localMoves.add(node->libertyList[i]);
    }

    if (chainID[index(x-1, y)]
     && chainID[index(x-1, y)] != chainID[index(x, y)]
     && chainID[index(x-1, y)] != chainID[index(x+1, y)]) {
        node = nullptr;
        searchChainsByID(node, chainID[index(x-1, y)]);
        for (int i = 0; i < node->liberties; i++)
            localMoves.add(node->libertyList[i]);
    }

    if (chainID[index(x, y+1)]
     && chainID[index(x, y+1)] != chainID[index(x, y)]
     && chainID[index(x, y+1)] != chainID[index(x+1, y)]
     && chainID[index(x, y+1)] != chainID[index(x-1, y)]) {
        node = nullptr;
        searchChainsByID(node, chainID[index(x, y+1)]);
        for (int i = 0; i < node->liberties; i++)
            localMoves.add(node->libertyList[i]);
    }

    if (chainID[index(x, y-1)]
     && chainID[index(x, y-1)] != chainID[index(x, y)]
     && chainID[index(x, y-1)] != chainID[index(x+1, y)]
     && chainID[index(x, y-1)] != chainID[index(x-1, y)]
     && chainID[index(x, y-1)] != chainID[index(x, y+1)]) {
        node = nullptr;
        searchChainsByID(node, chainID[index(x, y-1)]);
        for (int i = 0; i < node->liberties; i++)
            localMoves.add(node->libertyList[i]);
    }

    return localMoves;
}
开发者ID:jeffreyan11,项目名称:go-engine,代码行数:54,代码来源:board.cpp

示例2: getLegalMoves

/*
 * Returns a list of every possible legal move in the current board state.
 * This function does not account for suicides and ko rule.
 */
MoveList Board::getLegalMoves(Player p) {
    MoveList result;

    for (int j = 1; j <= boardSize; j++) {
        for (int i = 1; i <= boardSize; i++) {
            // All empty squares are legal moves
            if (pieces[index(i, j)] == EMPTY)
                result.add(coordToMove(i, j));
        }
    }

    return result;
}
开发者ID:jeffreyan11,项目名称:go-engine,代码行数:17,代码来源:board.cpp

示例3: isSurrounded

// Given a coordinate as a move, and a victim color, recursively determines
// whether the victim on this square is part of a surrounded chain
// Precondition: (x, y) is of color victim
bool Board::isSurrounded(Player victim, Player open, int x, int y,
    Stone *visited, MoveList &captured) {
    visited[index(x, y)] = 1;

    Stone east = pieces[index(x+1, y)];
    // If we are next to a non-blocker and non-victim, then we are not surrounded
    if (east == open)
        return false;
    // If we next to victim, we need to recursively see if the entire group
    // is surrounded
    else if (east == victim && visited[index(x+1, y)] == 0)
        if (!isSurrounded(victim, open, x+1, y, visited, captured))
            return false;
    // Else the piece is surrounded by a blocker or edge

    Stone west = pieces[index(x-1, y)];
    if (west == open)
        return false;
    else if (west == victim && visited[index(x-1, y)] == 0)
        if (!isSurrounded(victim, open, x-1, y, visited, captured))
            return false;

    Stone north = pieces[index(x, y+1)];
    if (north == open)
        return false;
    else if (north == victim && visited[index(x, y+1)] == 0)
        if (!isSurrounded(victim, open, x, y+1, visited, captured))
            return false;

    Stone south = pieces[index(x, y-1)];
    if (south == open)
        return false;
    else if (south == victim && visited[index(x, y-1)] == 0)
        if (!isSurrounded(victim, open, x, y-1, visited, captured))
            return false;

    // If we got here, we are surrounded on all four sides
    captured.add(coordToMove(x, y));
    return true;
}
开发者ID:jeffreyan11,项目名称:go-engine,代码行数:43,代码来源:board.cpp

示例4: readGame

void Game::readGame(int maxp, int size)
{
	int cntmove = 1;
	int cntPiece = 0;

	// 1. Version of the file
	short version = rGameFile.readShort();	// # Version (short)

	// 2. Header
	short typeOfData = rGameFile.readShort();	// # DATA_HEADER
	rGameFile.readShort();										// # Header version

	short width = rGameFile.readShort();		// # Width (short)
	short height = rGameFile.readShort();		// # Height (short)
	int seed = rGameFile.readInt();					// # Seed (int)
	int level = rGameFile.readByte();				// # Level (byte)
	int preview = rGameFile.readByte();			// # Preview (byte)
	int piece1 = rGameFile.readByte();      // # Piece1 (byte)
	int piece2 = rGameFile.readByte();      // # Piece2 (byte)

	Board board(width, height, 0, 0);
	Board htmlBoard(width+8, height+5, 0, 0);
	Piece dummy(&board, piece1);					// Initialize static members for width x height.
	MoveList *moveList = board.getMoveList(level);

	htmlBoard.copyWithWalls(&board, preview-1);

	wHtml << "<html>\n"
		    << "<head>\n"
				<< "  <title>Test.</title>\n"
				<< "</head>\n"
				<< "<body>\n"
				<< "  <table border=1>\n";

	while (piece2 != END_PIECE)
	{
		Piece htmlPiece1(&htmlBoard, piece1);
		Piece htmlPiece2(&htmlBoard, piece2);
		htmlPiece1.setPiece(0, 10, 1, width);

		if (level > 1)
			htmlPiece2.setPiece(0, 1, 1, width);
		
		Piece piece(&board, piece1);

		int length = rGameFile.readShort();		// # Number of legal moves.
		int pieceV = rGameFile.readByte();		// # V
		int pieceX = rGameFile.readShort();		// # X
		int pieceY = rGameFile.readShort();		// # Y

		moveList->init(level, preview, board.getMaxEquity());

		if (length == 0)
			break;


		wHtml << "    <tr>\n"
					<< "      <td>\n"
					<< "        <table border=0 cellspacing=0 cellpadding=0>\n"
					<< "        <!-- Board -->\n";

		// 1. Board
		for (int y=0; y<height+5; y++)
		{
			wHtml	<< "          <tr><td>";

			for (int x=0; x<width+8; x++)
			{
				int p = htmlBoard.get(x, y);
				char c = Piece::getHtmlChar(p);

				if (width == 10 && y==height+3)
				{
					if (x==6)
						wHtml << "<IMG src=img/Wdigits.gif height=" << size << ">";
					else if (x >=7 && x<=width+6)
						continue;
				}

				wHtml << "<IMG src=img/" << c << ".gif height=" << size << " width=" << size << ">";
			}

			wHtml	<< "</td></tr>\n";
		}

		wHtml	<< "        </table>\n"
					<< "      </td>\n";


		// 2. Equity list header
		wHtml	<< "      <td>\n"
					<< "        <table border=0>\n"
					<< "        <!-- Equity list -->\n"
					<< "          <tr>\n"
					<< "            <td colspan=2 align=left><font face=Arial size=1>"
					<< cntmove << ".&nbsp;"
					<< Piece::getChar(piece1) << Piece::getChar(piece2)
					<< "</font></td>\n"
					<< "          </tr>\n"
					<< "          <tr>\n"
//.........这里部分代码省略.........
开发者ID:tengstrand,项目名称:tetrisanalyzer,代码行数:101,代码来源:Game.cpp

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