本文整理汇总了C++中Chain::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Chain::add方法的具体用法?C++ Chain::add怎么用?C++ Chain::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chain
的用法示例。
在下文中一共展示了Chain::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void
Module::set ( Log_Entry &e )
{
for ( int i = 0; i < e.size(); ++i )
{
const char *s, *v;
e.get( i, &s, &v );
if ( ! strcmp( s, ":chain" ) )
{
/* This trickiness is because we may need to know the name of
our chain before we actually get added to it. */
int i;
sscanf( v, "%X", &i );
Chain *t = (Chain*)Loggable::find( i );
assert( t );
chain( t );
}
}
for ( int i = 0; i < e.size(); ++i )
{
const char *s, *v;
e.get( i, &s, &v );
/* if ( ! strcmp( s, ":name" ) ) */
/* label( v ); */
if ( ! strcmp( s, ":parameter_values" ) )
{
set_parameters( v );
}
else if ( ! ( strcmp( s, ":is_default" ) ) )
{
is_default( atoi( v ) );
}
else if ( ! ( strcmp( s, ":active" ) ) )
{
bypass( ! atoi( v ) );
}
else if ( ! strcmp( s, ":chain" ) )
{
int i;
sscanf( v, "%X", &i );
Chain *t = (Chain*)Loggable::find( i );
assert( t );
t->add( this );
}
}
}
示例2: doMove
/*
* Updates the board with a move. Assumes that the move is legal.
*/
void Board::doMove(Player p, Move m) {
if (m == MOVE_PASS)
return;
int x = getX(m);
int y = getY(m);
assert(pieces[index(x, y)] == EMPTY);
assert(chainID[index(x, y)] == 0);
pieces[index(x, y)] = p;
zobristKey ^= zobristTable[zobristIndex(p, x, y)];
Player victim = otherPlayer(p);
Stone east = pieces[index(x+1, y)];
Stone west = pieces[index(x-1, y)];
Stone north = pieces[index(x, y+1)];
Stone south = pieces[index(x, y-1)];
int connectionCount = (east == p) + (west == p) + (north == p) + (south == p);
// If the stone placed is a new chain
if (connectionCount == 0) {
// Record which chain this square is a part of
chainID[index(x, y)] = nextID;
// Add this chain to the list of chains
Chain *cargo = new Chain(p, nextID);
cargo->add(m);
cargo->liberties = 0;
if (east == EMPTY)
cargo->addLiberty(coordToMove(x+1, y));
if (west == EMPTY)
cargo->addLiberty(coordToMove(x-1, y));
if (north == EMPTY)
cargo->addLiberty(coordToMove(x, y+1));
if (south == EMPTY)
cargo->addLiberty(coordToMove(x, y-1));
chainList.add(cargo);
nextID++;
}
// If the stone placed is added to an existing chain
else if (connectionCount == 1) {
// Find the ID of the chain we are adding this stone to
int thisID;
if (east == p)
thisID = chainID[index(x+1, y)];
else if (west == p)
thisID = chainID[index(x-1, y)];
else if (north == p)
thisID = chainID[index(x, y+1)];
else
thisID = chainID[index(x, y-1)];
chainID[index(x, y)] = thisID;
Chain *node = nullptr;
searchChainsByID(node, thisID);
node->add(m);
// The new stone occupies a previous liberty, but adds on however many
// liberties it itself has
node->removeLiberty(node->findLiberty(m));
updateLiberty(node, x, y);
}
// If the stone possibly connects two existing chains
else {
int eastID = (east == p) * chainID[index(x+1, y)];
int westID = (west == p) * chainID[index(x-1, y)];
int northID = (north == p) * chainID[index(x, y+1)];
int southID = (south == p) * chainID[index(x, y-1)];
Chain *node = nullptr;
bool added = false;
if (eastID) {
chainID[index(x, y)] = eastID;
searchChainsByID(node, eastID);
node->add(m);
node->removeLiberty(node->findLiberty(m));
updateLiberty(node, x, y);
added = true;
}
if (westID) {
if (added) {
// If two stones from the same chain are adjacent, do nothing
// If they are from different chains, we need to combine...
if (westID != eastID)
mergeChains(node, westID, m);
}
else {
chainID[index(x, y)] = westID;
searchChainsByID(node, westID);
//.........这里部分代码省略.........