std::vector<std::pair<int, int> > Grid::getPossibleChainScores(BlockPair blockPair) const { std::vector<std::pair<int, int> > scoreColumnResults; // [score, column] for (int j=0; j<size2_; j++) { int blocksAlike = 0; int blocksDifferent = 0; int height = getPositionsAfterInsert(j).first.first; if (height < 1) { scoreColumnResults.push_back(std::make_pair(blocksAlike, j)); continue; } height++; while (inBounds(height, j) && grid_[height][j] != blockPair.first.color) { height++; blocksDifferent++; } if (blocksDifferent == 0) { scoreColumnResults.push_back(std::make_pair(blocksAlike, j)); continue; } while (inBounds(height, j) && grid_[height][j] == blockPair.first.color) { height++; blocksAlike++; } scoreColumnResults.push_back(std::make_pair(blocksAlike, j)); } return scoreColumnResults; }
void Field::setCell(const Cell & cell, int x, int y) { assert(inBounds(x, y)); if (inBounds(x, y)) cells[x + y * width] = cell; }
std::vector<Point> Grid::getNeighbours(Point position, Block block) const { if (!inBounds(position.first, position.second)) { return std::vector<Point>(); } std::vector<Point> neighbours; for (int i=-1; i<=1; i++) { for (int j=-1; j<=1; j++) { if (i!=0 && j!=0) { continue; } int height = position.first + i; int width = position.second + j; if (!inBounds(height, width)) { continue; } if (grid_[height][width] == block.color) { neighbours.push_back(std::make_pair(height, width)); } } } return neighbours; }
//returns true if there were no prob creating a path //error only occur if there's something wrong with the parameter //can (and will) return true even if there is no way to the destination bool PathPlanner::Planning(int start[2], int goal[2]) { if(!inBounds(start) || !inBounds(goal)) return false; std::vector<Path> pathList; Path init(0,computeHeuristic(start[0],start[1],goal[0],goal[1])); init.nodes.push_back(&nodeMap[start[0]][start[1]]); nodeMap[start[0]][start[1]].state = FRONTIER; pathList.push_back(init); Path newpath; Path toexpand; Node* lastnode; while(pathList.size() != 0 ) { std::sort(pathList.begin(),pathList.end()); toexpand = pathList.back(); pathList.pop_back(); if(toexpand.nodes.back() == &nodeMap[goal[0]][goal[1]]) { path = toexpand; return true; } lastnode = toexpand.nodes.back(); if( lastnode->state != EXPLORED) { //bottom expandNode(toexpand,&pathList,0,1,3,goal); //right expandNode(toexpand,&pathList,1,0,3,goal); // left expandNode(toexpand,&pathList,-1,0,3,goal); //top expandNode(toexpand,&pathList,0,-1,3,goal); //top-left expandNode(toexpand,&pathList,-1,-1,4,goal); //top-right expandNode(toexpand,&pathList,1,-1,4,goal); //bottom-left expandNode(toexpand,&pathList,-1,1,4,goal); //bottom-right expandNode(toexpand,&pathList,1,1,4,goal); toexpand.nodes.back()->state = EXPLORED; } } return false; }
void MapEditor::mouseLeft(int x, int y) { // check if the custom map was clicked if(inBounds(x,y,customMap->limit)) { coordToIndex(&x,&y,customMap); selectedCellX = x; selectedCellY = y; selectedCell = customMap->getTile(selectedCellX,selectedCellY); if(selectedCell == NULL) { selectedCellX = -1; selectedCellY = -1; } else { // copy a graphic tile to the background or foreground of a cell if(selectedTileIndex != -1) { if(selectedCell->b == -1) selectedCell->b = selectedTileIndex; else if(selectedCell->b != selectedTileIndex) selectedCell->f = selectedTileIndex; } } } // check if a graphic tile was clicked, if so select it for copying else if(inBounds(x,y,tileSet->limit)) { coordToIndex(&x,&y,tileSet); selectedTileX = x; selectedTileY = y; selectedTileIndex = getTileArrayIndex(x,y); } else if(saveBtn.inBounds(x,y)) { if(currentMapFilename != NULL) { customMap->save(currentMapFilename); } } else if(closeBtn.inBounds(x,y)) { signalCompletion(); } // check if the scrolling arrows were pressed else { checkButtons(x,y,customMapBtns,customMap); checkButtons(x,y,tileSetBtns,tileSet); } }
bool Level::areConnected(Vec2 p1, Vec2 p2, const MovementType& movement) const { if (!inBounds(p1) || !inBounds(p2)) return false; if (!sectors.count(movement)) { sectors[movement] = Sectors(getBounds()); Sectors& newSectors = sectors.at(movement); for (Vec2 v : getBounds()) if (getSafeSquare(v)->canNavigate(movement)) newSectors.add(v); } return sectors.at(movement).same(p1, p2); }
void states::bishopMoves(int x, int y, move *moves, int &movesIndex, char color){ checkDiag(x, y, moves, movesIndex, multiple, color); if(inBounds(x-1, y) && checkEmpty(x-1, y,color) == 0) scan(x, y, moves, movesIndex, -1, 0, single, color); //north if(inBounds(x+1, y) && checkEmpty(x+1, y, color) == 0) scan(x, y, moves, movesIndex, 1, 0, single, color); //south if(inBounds(x, y+1) && checkEmpty(x, y+1, color) == 0) scan(x, y, moves, movesIndex, 0, 1, single, color); //east if(inBounds(x, y-1) && checkEmpty(x, y-1, color) == 0) scan(x, y, moves, movesIndex, 0, -1, single, color); //west }
void readyScreen::touch(ofPoint touch){ ofPoint buttPos = ofPoint(70,115); float w = 171; float h= 58; cout<<"touched"; float halfRad = 0.5f*radius; ofPoint circPos=ofPoint(x2-halfRad, y2-halfRad ); if(inBounds(buttPos,w,h,touch)){ stop(); } else if(inBounds(circPos,radius,radius,touch)){ stop(); } }
/** * Grab a string representation of data from a buffer * * @param base base representation for data: -> man stroul() * @param bytes_to_grab how many bytes should we grab from the packet * @param data pointer to where to grab the data from * @param start pointer to start range of buffer * @param end pointer to end range of buffer * @param value pointer to store data in * * @returns 0 on success, otherwise failure */ int string_extract(int bytes_to_grab, int base, u_int8_t *ptr, u_int8_t *start, u_int8_t *end, u_int32_t *value) { char byte_array[TEXTLEN]; char *parse_helper; int x; /* counter */ if(bytes_to_grab > (TEXTLEN - 1) || bytes_to_grab <= 0) { return -1; } /* make sure the data to grab stays in bounds */ if(!inBounds(start,end,ptr + (bytes_to_grab - 1))) { return -3; } if(!inBounds(start,end,ptr)) { return -3; } for(x=0;x<bytes_to_grab; x++) { byte_array[x] = *(ptr+x); } byte_array[bytes_to_grab] = '\0'; *value = strtoul(byte_array, &parse_helper, base); if(byte_array == parse_helper) { return -1; } #ifdef TEST_BYTE_EXTRACT printf("[----]\n"); for(x=0;(x<=TEXTLEN) && (byte_array[x] != '\0');x++) printf("%c", byte_array[x]); printf("\n"); printf("converted value: 0x%08X (%u) %s\n", *value, *value, (char *) byte_array); #endif /* TEST_BYTE_EXTRACT */ return 0; }
Cell * Field::getCell(int x, int y) { if (inBounds(x, y)) return &cells[x + y * width]; else return NULL; }
// blurThread should become member function of the class SelLum void blurThread(void *parameter) { ThreadParams *p = (ThreadParams*) parameter; while(1){ WaitForSingleObject(p->startEvent,INFINITE); if (p->terminateThread) // Thread should terminate break; for(p->v = p->startv; p->v <= p->Maxv; p->v += p->step){ for (p->u =- p->m_feathRad; p->u <= p->m_feathRad; p->u++){ if ( !inBounds(p->x+p->u, p->y+p->v, p->m_imageW, p->m_imageH) ) continue; // compute offsets p->index = (p->mapIndex + p->v*p->m_imageW + p->u); if (p->mp_radMap[p->index] != 0.0f){ p->normRadIdx = (p->u+p->m_feathRad) + (p->v+p->m_feathRad)*p->m_normRadMaskW; p->mp_radMap[p->index] = min(p->mp_radMap[p->index], p->m_normRadMask[p->normRadIdx]); } } // for u }// for i SetEvent(p->numDoneEvent); }// while(1) }
void MapEditor::mouseRight(int x, int y) { // deselect a graphic tile if one is selected if(selectedTileX != -1 || selectedTileY != -1 || selectedTileIndex != -1) { selectedTileX = -1; selectedTileY = -1; selectedTileIndex = -1; } // deselect a custom map tile if one is selected else if(selectedCell != NULL || selectedCellX != -1 || selectedCellY != -1) { selectedCell = NULL; selectedCellX = -1; selectedCellY = -1; } // erase a layer of a custom map tile. else if(inBounds(x,y,customMap->limit)) { coordToIndex(&x,&y,customMap); Tile *tempCell = customMap->getTile(x,y); if(tempCell != NULL) { if(tempCell->f != -1) tempCell->f = -1; else tempCell->b = -1; } } }
void Board::set(int i, Square sq) { if (inBounds(i)) at(i) = sq; if(sq == head) samyIndex = i; }
void Cpu::sigueAtacando() { /// PELIAGUDO :D _casillaTiroAnterior = _casillaTiro; // Me guardo el acierto anterior do { if (_resultado == errado) // Si ultimo resultado es errado, pero entro aquí es que tenía un barco en el punto de mira, luego { _casillaTiro = _casillaOrigen; // me coloco en la casilla en la que encontré ese barco y _pilaDirecciones.pop(); // la dirección que llevaba ya no es válida pues erré. } if (!_pilaDirecciones.empty()) // Si no he agotado todas las direcciones { // Compruebo si mi dirección actual me saca del tablero, si me saca, quito esa dirección y me coloco en la casilla // donde acerté inicialmente. Ogre::Vector2 dirActual = _pilaDirecciones.top(); while (!inBounds(_casillaTiro + _pilaDirecciones.top())) _pilaDirecciones.pop(); if (dirActual != _pilaDirecciones.top()) _casillaTiro = _casillaOrigen; _casillaTiro += _pilaDirecciones.top(); } else // Si por el contrario he agotado las direcciones posibles. A la porra, tiramos un dado :D { ataqueAlAzar(); break; // Forzamos la salida del while pues ataqueAlAzar() ya se preocupa de proveer una casilla sin explorar. } } while (_casilleroAtaque[_casillaTiro.x][_casillaTiro.y]._estado != neutro); }
double HeaterMOO::sumNeighbours ( double** img, const uint32_t i, const uint32_t j ) const { double sum = .0; if ( inBounds ( i, j - 1 ) ) { sum += img[i][j - 1]; } if ( inBounds ( i, j + 1 ) ) { sum += img[i][j + 1]; } if ( inBounds ( i - 1, j ) ) { sum += img[i - 1][j]; } if ( inBounds ( i + 1, j ) ) { sum += img[i + 1][j]; } return sum; }
std::pair<Point, Point> Grid::getPositionsAfterInsert(int colNum) const { std::ostringstream dbgMsg; if (!inBounds(0, colNum)) { return std::make_pair(std::make_pair(-1,-1), std::make_pair(-1,-1)); } if (grid_[0][colNum] != '.' || grid_[1][colNum] != '.') { return std::make_pair(std::make_pair(-1,-1), std::make_pair(-1,-1)); } int verticalLowerPos; for (int i=0; i<size1_; i++) { verticalLowerPos = i; if (grid_[i][colNum] != '.') { verticalLowerPos = i-1; break; } } Point lowerPos = std::make_pair(verticalLowerPos, colNum); Point higherPos = std::make_pair(verticalLowerPos-1, colNum); return std::make_pair(lowerPos, higherPos); }
float Terrain::average(UINT i, UINT j) { // Function computes the average height of the ij element. // It averages itself with its eight neighbor pixels. Note // that if a pixel is missing neighbor, we just don't include it // in the average--that is, edge pixels don't have a neighbor pixel. // // ---------- // | 1| 2| 3| // ---------- // |4 |ij| 6| // ---------- // | 7| 8| 9| // ---------- float avg = 0.0f; float num = 0.0f; for(UINT m = i-1; m <= i+1; ++m) { for(UINT n = j-1; n <= j+1; ++n) { if( inBounds(m,n) ) { avg += mHeightmap[m*mInfo.NumCols + n]; num += 1.0f; } } } return avg / num; }
void states::scan(int x, int y, move *moves, int &movesIndex, int dx, int dy, int movement, char color){ int toX = x; int toY = y; while(inBounds(toX + dx, toY + dy)){ //if square is empty 0 or contains opponent 1 int CE = checkEmpty(toX + dx, toY + dy,color); if(CE == 0 || CE == 1 ){ moves[movesIndex].fromSquare.x = x; // new move(x, y, toX + dx, toY + dy); moves[movesIndex].fromSquare.y = y; moves[movesIndex].toSquare.x = toX + dx; moves[movesIndex].toSquare.y = toY + dy; if(CE == 1 || movement == single){ ++movesIndex; break; } else{ toX = toX + dx; toY = toY + dy; ++movesIndex; } } else{ //self is on the square break; } } }
//x=4 y = 1 void PathPlanner::setScaling(int radius) { if(radius < 0) return; else if(radius == 0) { for(int j=0;j<height;j++) { for(int i=0;i<width;i++) { if(nodeMap[i][j].state == SCALING) nodeMap[i][j].state = UNREACHABLE; } } } else { for(int i=0;i<width;i++) { for(int j=0;j<height;j++) { if(nodeMap[i][j].state == UNREACHABLE) { for(int k=-radius;k<=radius;k++) { for(int l=-(radius-k)*(radius+k)/radius;l<=(radius-k)*(radius+k)/radius;l++) { int temp[2] = {i+k,j+l}; if(inBounds(temp)) { if(nodeMap[i+k][j+l].state != UNREACHABLE) { nodeMap[i+k][j+l].state = SCALING; } } } } } } } } }
vector<Square*> Level::getSquares(const vector<Vec2>& pos) { vector<Square*> ret; for (Vec2 v : pos) if (inBounds(v)) ret.push_back(getSafeSquare(v)); return ret; }
void Array<T>::boundsCheck(int i) const { #ifdef SAFE_ARRAYS if ( ! inBounds(i) ) throw OutOfBoundsException(); #endif }
bool Level::canMoveCreature(const Creature* creature, Vec2 direction) const { Vec2 position = creature->getPosition(); Vec2 destination = position + direction; if (!inBounds(destination)) return false; return getSafeSquare(destination)->canEnter(creature); }
void fixBounds() { if (currentBufferInUse == 1) { inBounds(buffer1, selectx, selecty); } if (currentBufferInUse == 2) { inBounds(buffer2, selectx, selecty); } if (currentBufferInUse == 3) { inBounds(buffer3, selectx, selecty); } if (!canDrawTileBool) { selectx--; selecty--; fixBounds(); } }
void states::bPawnMoves(int x, int y, move *moves, int &movesIndex){ if(inBounds(x+1, y) && checkEmpty(x+1, y,'B') == 0){ scan(x, y, moves, movesIndex, 1, 0, single, 'B'); //south } //check for diagonal attack SW SE pawnAttacks(x, y, moves, movesIndex, 1, -1, 'B'); pawnAttacks(x, y, moves, movesIndex, 1, 1, 'B'); }
//WHAT THE HELL?? void states::wPawnMoves(int x, int y, move *moves, int &movesIndex){ if(inBounds(x-1, y) && checkEmpty(x-1, y,'W') == 0){ scan(x, y, moves, movesIndex, -1, 0, single, 'W'); //north } //check for diagonal attack NW NE pawnAttacks(x, y, moves, movesIndex, -1, -1, 'W'); pawnAttacks(x, y, moves, movesIndex, -1, 1, 'W'); }
void xuNodo::update() { if(vivo) { pos +=vel; vivo = inBounds(); } }
void Histogram::removeKernelizedValue(qint8 index, float *histogram) { index -= MIN_HISTOGRAM_INDEX; if (inBounds(index)) histogram[index] -= 0.2042; if (inBounds(index-1)) histogram[index-1] -= 0.1802; if (inBounds(index+1)) histogram[index+1] -= 0.1802; if (inBounds(index-2)) histogram[index-2] -= 0.1238; if (inBounds(index+2)) histogram[index+2] -= 0.1238; if (inBounds(index-3)) histogram[index-3] -= 0.0663; if (inBounds(index+3)) histogram[index+3] -= 0.0663; if (inBounds(index-4)) histogram[index-4] -= 0.0276; if (inBounds(index+4)) histogram[index+4] -= 0.0276; }
Optional<String> CSVData::getItem(const size_t row, const size_t column) const { if (!inBounds(row, column)) { return none; } return m_data[row][column]; }
// Retrieves the value at a provided (w,h) location in the board or returns // INVALID if the provided location is not within the board Piece ConnectX::at(int w, int h) { if( inBounds(w,h) ) { return board[h][w]; } else return INVALID; }
std::vector<int> lookupvector(const std::vector<int> &v, int size) { casadi_assert_message(inBounds(v,size),"lookupvector: out of bounds. Some elements in v fall out of [0,size["); std::vector<int> lookup(size,-1); for (int i=0;i<v.size();i++) { lookup[v[i]] = i; } return lookup; }