static int nodeCount(const QList<QGLSceneNode*> &list) { int total = 0; QList<QGLSceneNode*>::const_iterator it = list.constBegin(); for ( ; it != list.constEnd(); ++it) total += recursiveCount(*it); return total; }
int Board::recursiveCount(int x, int y, int xdirection, int ydirection, Player current){ x = x + xdirection; y = y + ydirection; if((0 <= x) && (x < this->w()) && (0 <= y) && (y < this->h())){ if(this->_cells[x][y] == current) return (recursiveCount(x, y, xdirection, ydirection, current)+1); return 0; } return 0; }
bool InnerDecklistNode::compareNumber(AbstractDecklistNode *other) const { InnerDecklistNode *other2 = dynamic_cast<InnerDecklistNode *>(other); if (other2) { int n1 = recursiveCount(true); int n2 = other2->recursiveCount(true); return (n1 != n2) ? (n1 > n2) : compareName(other); } else { return false; } }
/*! \internal Returns a count of all the items referenced by this node and all its children. */ static int recursiveCount(QGLSceneNode *top) { int totalItems = 0; if (top) { totalItems = top->count(); QList<QGLSceneNode*> children = top->children(); QList<QGLSceneNode*>::const_iterator it = children.constBegin(); for ( ; it != children.constEnd(); ++it) totalItems += recursiveCount(*it); } return totalItems; }
bool Board::isCellWinningTwo(int x, int y, Player current){ if((recursiveCount(x, y, 0, -1, current) + 1 + recursiveCount(x, y, 0, 1, current) >= this->_patternSize)) return true; //Vertical win if((recursiveCount(x, y, 1, -1, current) + 1 + recursiveCount(x, y, -1, 1, current) >= this->_patternSize)) return true; //bottom left to up right win if((recursiveCount(x, y, 1, 0, current) + 1 + recursiveCount(x, y, -1, 0, current) >= this->_patternSize)) return true; //Horizontal win if((recursiveCount(x, y, 1, 1, current) + 1 + recursiveCount(x, y, -1, -1, current) >= this->_patternSize)) return true; //up left to bottom right win return false; //If nothing }
bool Board::isCellWinning(int x, int y){ // in this function all cell will be call, need to check over the position to determine if we apply the 4 patterns // horizontal rule : x < this->w() - _patternSize // vertical rule : y < this->h() - _patternSize // diagoR rule : x < this->w() - _patternSize && y < this->h() - _patternSize // diagoL rule : x < this->w() - _patternSize && y < this->h() - _patternSize int value = this->get(x,y); if(value == -1){ cout << "Cell " << x << " " << y << " empty, passing ... "<< endl; return false; } bool winning = false; int i = 0; Player current = this->get(x,y); if((recursiveCount(x, y, 0, -1, current) + 1 + recursiveCount(x, y, 0, 1, current) >= this->_patternSize)) winning = true; //Vertical win if((recursiveCount(x, y, 1, -1, current) + 1 + recursiveCount(x, y, -1, 1, current) >= this->_patternSize)) winning = true; //bottom left to up right win if((recursiveCount(x, y, 1, 0, current) + 1 + recursiveCount(x, y, -1, 0, current) >= this->_patternSize)) winning = true; //Horizontal win if((recursiveCount(x, y, 1, 1, current) + 1 + recursiveCount(x, y, -1, -1, current) >= this->_patternSize)) winning = true; //up left to bottom right win return winning; }
bool LockerImpl::isRecursive() const { return recursiveCount() > 1; }