bool GiantLocust::onActorTurn_() { if(deadState == ActorDeadState::alive) { if(awareOfPlayerCounter_ > 0) { if(Rnd::percentile() < chanceToSpawnNew) { bool blockers[MAP_W][MAP_H]; MapParse::parse(CellPred::BlocksActor(*this, true, eng), blockers); Pos spawnPos; for(int dx = -1; dx <= 1; dx++) { for(int dy = -1; dy <= 1; dy++) { spawnPos.set(pos + Pos(dx, dy)); if(blockers[spawnPos.x][spawnPos.y] == false) { Actor* const actor = eng.actorFactory->spawnActor(data_->id, spawnPos); GiantLocust* const locust = dynamic_cast<GiantLocust*>(actor); chanceToSpawnNew -= 2; locust->chanceToSpawnNew = chanceToSpawnNew; locust->awareOfPlayerCounter_ = awareOfPlayerCounter_; eng.gameTime->actorDidAct(); return true; } } } } } } return false; }
int solve(){ memset(tick, 0x1f, sizeof(tick)); Pos start = findCh('S'); Pos target = findCh('T'); //start.display("S"); //start.display("T"); queue<Pos> Q; Q.push(start); tick[start.x][start.y][start.color][start.dir] = 0; while (Q.size()){ Pos s = Q.front(); Q.pop(); //s.display("Pop"); for (int i = 0; i < 3; i++){ Pos t = s.action(i); if (!t.isValid()) continue; if (tick[t.x][t.y][t.color][t.dir] != INF) continue; if (grid[t.x][t.y] == '#') continue; tick[t.x][t.y][t.color][t.dir] = tick[s.x][s.y][s.color][s.dir] + 1; Q.push(t); //s.display(" Push"); } } int best = INF; for (int i = 0; i < 4; i++){ target.dir = i; best = min(best, tick[target.x][target.y][target.color][target.dir]); } return best; }
int main() { while(cin >> n && n!=0) { for(int i=0;i!=88888889;i++) check[i] = false; float ok = 0.12345678; finish = (pow(10.0,n))*ok; Pos pos; vector<int> init; for(int i=0;i!=n;i++) init.push_back(0); for(int i=0;i!=n;i++) pos.push_back(init); for(int i=0;i!=n;i++) { int in; cin >> in; (pos[i])[0] = in; } int ans = search(pos,n); if(ans==-1) cout << "IMPOSSIBLE" <<endl; else cout << ans <<endl; } system("pause"); return 0; }
bool Pos::operator==(const Pos& s) const { if (_type == FRAMES) return _frame == s.frame(); else return _tick == s.tick(); }
bool get() { v.resize(D); w.resize(D); cin >> ws; if(cin.peek() == '-') { cin >> v[0]; return false; }
Int generate_path( const PosMatrix& prev, const Pos& start, Path& path ) { Pos cur = start; while ( cur != POS_NONE ) { path.push_back(cur); cur = prev[cur.get_row()][cur.get_col()]; } std::reverse(std::begin(path), std::end(path)); return path.size(); }
Planet(void) { pos.setX(0); pos.setY(0); pos.setZ(0); vel.setX(0); vel.setY(0); vel.setZ(0); this->m = 0; }
void ModButterfly::rotateUntilBorder(RgbVertexC& v, Pos& pos) { assert(v.vp() == pos.v); do { pos.FlipE(); pos.FlipF(); } while (!pos.IsBorder()); assert(v.vp() == pos.v); }
Planet(double x, double y, double z, double vx, double vy, double vz, double m, double r) { pos.setX(x); pos.setY(y); pos.setZ(z); vel.setX(vx); vel.setY(vy); vel.setZ(vz); this->m = m; this->r = r; }
bool Matches::addMatches( char *s, int32_t slen, mf_t flags ) { // . do not breach // . happens a lot with a lot of link info text if ( m_numMatchGroups >= MAX_MATCHGROUPS ) { return true; } // get some new ptrs for this match group Words *wp = &m_wordsArray [ m_numMatchGroups ]; Bits *bp = &m_bitsArray [ m_numMatchGroups ]; Pos *pb = &m_posArray [ m_numMatchGroups ]; // set the words class for this match group if ( !wp->set( s, slen, true ) ) { return false; } // bits vector if ( ! bp->setForSummary ( wp ) ) { return false; } // position vector if ( ! pb->set ( wp ) ) { return false; } // record the start int32_t startNumMatches = m_numMatches; // sometimes it returns true w/o incrementing this int32_t n = m_numMatchGroups; // . add all the Match classes from this match group // . this increments m_numMatchGroups on success bool status = addMatches( wp, NULL, NULL, bp, pb, flags ); // if this matchgroup had some, matches, then keep it if ( m_numMatches > startNumMatches ) { return status; } // otherwise, reset it, useless wp->reset(); bp->reset(); pb->reset(); // do not decrement the counter if we never incremented it if ( n == m_numMatchGroups ) { return status; } // ok, remove it m_numMatchGroups--; return status; }
void PosLen::setPos(const Pos& pos) { switch(pos.type()) { case FRAMES: setFrame(pos.frame()); break; case TICKS: setTick(pos.tick()); break; } }
void MarkerView::tickChanged(const Pos& pos) { MarkerItem* item = (MarkerItem*) table->currentItem(); if (item) { item->setTick(pos.tick()); Pos p(pos.tick(), true); song->setPos(0, p, true, true, false); table->sortByColumn(COL_TICK, Qt::AscendingOrder); } }
void throw_(typename Exception::error_code code, S1 msg, Pos const& pos) { std::stringstream stream; stream << Exception::severity_text(code) << ": " << Exception::error_text(code); if (msg[0] != 0) stream << ": " << msg; stream << std::ends; std::string throwmsg = stream.str(); boost::throw_exception(Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(), pos.get_file().c_str())); }
void PosEdit::setValue(const Pos& time) { if (time > maxValue() || time < minValue()) return; if (_smpte) time.msf(&(sec[0].val), &(sec[1].val), &(sec[2].val), &(sec[3].val)); else time.mbt(&(sec[0].val), &(sec[1].val), &(sec[2].val)); changed = false; updateButtons(); ed->repaint(ed->rect(), false); }
void throw_(Context& ctx, typename Exception::error_code code, S1 msg, Pos const& pos, S2 name) { std::strstream stream; stream << Exception::severity_text(code) << ": " << Exception::error_text(code); if (msg[0] != 0) stream << ": " << msg; stream << std::ends; std::string throwmsg = stream.str(); stream.freeze(false); ctx.get_hooks().throw_exception(ctx.derived(), Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(), pos.get_file().c_str(), name)); }
int simplehero::selectNeighbor(GraphMap* map, int cur_x, int cur_y) { // printf("Selecting neighbor\n"); int x, y, a, b; Pos* goal = findGoal(map, cur_x, cur_y); int g; if(goal == 0) { printf("Couldn't find goal\n"); return 0; } g = map->getVertex(goal->getX(), goal->getY()); int toGo = BFSearch(map, cur_x, cur_y, g); //printf("Done searching\n"); if(toGo == -1) { // printf("No target found\n"); delete goal; return 0; } /* if(p == 0 || p[1]->getX() < 0) { printf("ERRRORRORROR\n"); goal = findGoal(map, cur_x, cur_y); toGo = BFSearch(map ,cur_x, cur_y, goal); }*/ map->getPosition(toGo, x, y); for(int i = 0; i < map->getNumNeighbors(cur_x, cur_y); i++) { map->getNeighbor(cur_x, cur_y, i, a, b); if(x == a && y == b) { delete goal; return i; } } printf("Shouldn't get here"); return 0; }
void printCornerPointsXY(Box* box, FILE* f){ OSGBox* obox = (OSGBox*)box->getOSGPrimitive(); std::list<Pos> ps; Pos dim = obox->getDim(); ps.push_back(Pos(dim.x()* 0.5, dim.y()* 0.5,0)); ps.push_back(Pos(dim.x()* 0.5, dim.y()* -0.5,0)); ps.push_back(Pos(dim.x()* -0.5, dim.y()* -0.5,0)); ps.push_back(Pos(dim.x()* -0.5, dim.y()* 0.5,0)); // for(int i=0; i<8; i++){ // ps.push_back(Pos(dim.x()*( (i&4) ? 0.5: -0.5),dim.y()*( (i&2) ? 0.5: -0.5),dim.z()*( (i&1) ? 0.5: -0.5))); // } // transform them into global coords FOREACH(std::list<Pos>, ps, p){ *p = (*p) * box->getPose(); }
vector<Pos> Board::MoveGung(Pos pos) { vector<Pos> candidates; int curr_id = stage[pos.y][pos.x]; int nx, ny; for (int dy = -1; dy <= 1; dy++) { for (int dx = -1; dx <= 1; dx++) { nx = pos.x + dx; ny = pos.y + dy; if ((pos.x == 3 && (pos.y == 1 || pos.y == 8)) || (pos.x == 4 && (pos.y == 0 || pos.y == 2 || pos.y == 7 || pos.y == 9)) || (pos.x == 5 && (pos.y == 1 || pos.y == 8))) { // movable to only up, right, left, down side if (pos.DistWith(nx, ny) > 1) continue; } if (nx >= 3 && nx <= 5 && ((ny >= 0 && ny <= 2) || (ny >= 7 && ny <= 9))) { if (curr_id <= 6) { if (stage[ny][nx]<0 || stage[ny][nx]>6) { candidates.push_back(Pos(nx, ny)); } } else { if (stage[ny][nx]<0 || stage[ny][nx] <= 6) { candidates.push_back(Pos(nx, ny)); } } } } } return candidates; }
void Filler::GetCluster(Pos pos, std::unordered_set<int>& cluster_out) { if (IsOutside(pos) || visited_.find(pos.GetHash()) != visited_.end() || piece_index_.find(pos.GetHash()) == piece_index_.end()) { return; } visited_.insert(pos.GetHash()); cluster_out.insert(piece_index_[pos.GetHash()]); for (const auto& direction : directions_) { GetCluster({ pos.x + direction.first, pos.y + direction.second }, cluster_out); } }
void Board::removeStone( Pos const& p ) { int idx = p.toIndex(); char data = getData( idx ); assert( data != eEmpty ); mData[ idx ] = eEmpty; for( int dir = 0 ; dir < NumDir ; ++dir ) { int idxCon = calcConIndex( idx , dir ); char dataCon = mData[ idxCon ]; if ( dataCon == EDGE_MARK || dataCon == eEmpty ) continue; if ( dataCon & VISITED_MARK ) continue; if ( dataCon != data ) { addRootLife( getLinkRoot( idxCon ) , 1 ); } else { relink( idxCon ); } } for( int dir = 0 ; dir < NumDir ; ++dir ) { int idxCon = calcConIndex( idx , dir ); if ( mData[ idxCon ] & VISITED_MARK ) removeVisitedMark_R( idxCon ); } }
int Board::fillStone( Pos const& p , DataType color ) { mColorR = color; assert( color != eEmpty ); int idx = p.toIndex(); return fillStone_R( idx ); }
DNALength Locate(DNALength bwtPos) { DNALength seqPos; DNALength offset = 0; while (1) { if (pos.Lookup(bwtPos, seqPos)) { break; } else { DNALength bwtPrevPos; bwtPrevPos = LFBacktrack(bwtPos); if (useDebugData) { assert(saCopy[bwtPos-1] - 1 == saCopy[bwtPrevPos-1]); } bwtPos = bwtPrevPos; assert(bwtPos <= bwtSequence.length); /* * Boundary condition at the beginning of the bwt string. */ if (bwtPos == firstCharPos) { seqPos = 1; break; } } ++offset; } return seqPos + offset; }
virtual void nextResult(Pos& num) { uint current = num->getVal(); if (maxNum_ <= current) num = 0; else num = new Nummy(current+1); }
bool Primitive::restore(FILE* f){ Pose pose; Pos vel; Pos avel; if ( fread ( pose.ptr() , sizeof ( Pose::value_type), 16, f ) == 16 ) if( fread ( vel.ptr() , sizeof ( Pos::value_type), 3, f ) == 3 ) if( fread ( avel.ptr() , sizeof ( Pos::value_type), 3, f ) == 3 ){ setPose(pose); if(body){ dBodySetLinearVel(body,vel.x(),vel.y(),vel.z()); dBodySetAngularVel(body,avel.x(),avel.y(),avel.z()); } return true; } fprintf ( stderr, "Primitve::restore: cannot read primitive from data\n" ); return false; }
void TBV::PrintManSqrSet(const Pos& pos) const { // Print a TBV as a set of chessmen/square pairs bool needspace = false; PrintChar('['); for (tidType tid = 0; tid < tidLen; tid++) if (TestTid(tid)) { const sqrType sqr = pos.GetTidToSqr(tid); const manType man = pos.GetMan(sqr); if (needspace) PrintSpace(); PrintMan(man); PrintChar('/'); PrintSqrBasic(sqr); needspace = true; }; PrintChar(']'); }
PosChange::PosChange(Pos from, Pos to, int repeats) :Change(repeats) ,from(from) ,to(to) ,step(from.stepTo(to)) ,isRelative(false) { resetData(); }
void InitializeFromSuffixArray(T_DNASequence &dnaSeq, DNALength saIndex[], int buildDebug=0) { useDebugData = buildDebug; InitializeBWTStringFromSuffixArray(dnaSeq, saIndex); InitializeDNACharacterCount(); // sequence, major, minor bin sizes. occ.Initialize(bwtSequence, 4096, 64, buildDebug); pos.InitializeFromSuffixArray(saIndex, dnaSeq.length); }
void Solver::DeepSearch::backtrack(uint tile){ Pos<uint> newPos = positions[tile]; uint x, y; for(x=0; x<gameField.getTile(tile).getSizeX(); ++x) for(y=0; y<gameField.getTile(tile).getSizeY(); ++y){ if(gameField.getTile(tile).getField(x, y) == true){ if(currentValue[newPos.getX() + x][newPos.getY() + y] == 0){ currentValue[newPos.getX()+ x][newPos.getY() + y] = gameField.getField().getMod()-1; heuristicValue++; }else if (currentValue[newPos.getX() + x][newPos.getY() + y] == 1){ currentValue[newPos.getX() + x][newPos.getY()+ y] = 0; heuristicValue -= gameField.getField().getMod() -1; } else { currentValue[newPos.getX()+ x][newPos.getY() + y]--; heuristicValue++; } } } }
vector<Pos> Board::MoveJol(Pos pos) { int curr_id = stage[pos.y][pos.x]; vector<Pos> candidates; int nx, ny; // down-ward //if ((curr_id <= 6 && standard_position) || curr_id >6 && !standard_position) { if (curr_id <= 6) { for (int dy = 0; dy <= 1; dy++) { for (int dx = -1; dx <= 1; dx++) { nx = pos.x + dx; ny = pos.y + dy; if (nx >= 0 && nx < kStageWidth && ny >= 0 && ny < kStageHeight && (stage[ny][nx] < 0 || (curr_id <= 6 && stage[ny][nx] > 6) || (curr_id > 6 && stage[ny][nx] <= 6))) { if ((pos.x == 3 && pos.y == 7 && nx == 4 && ny == 8) || (pos.x == 5 && pos.y == 7 && nx == 4 && ny == 8) || (pos.x == 4 && pos.y == 8 && nx == 3 && ny == 9) || (pos.x == 4 && pos.y == 8 && nx == 5 && ny == 9) || pos.DistWith(nx, ny) <= 1.1) { candidates.push_back(Pos(nx, ny)); } } } } } // up-ward else { for (int dy = -1; dy <= 0; dy++) { for (int dx = -1; dx <= 1; dx++) { nx = pos.x + dx; ny = pos.y + dy; if (nx >= 0 && nx < kStageWidth && ny >= 0 && ny < kStageHeight && (stage[ny][nx] < 0 || (curr_id <= 6 && stage[ny][nx] > 6) || (curr_id > 6 && stage[ny][nx] <= 6))) { if ((pos.x == 3 && pos.y == 2 && nx == 4 && ny == 1) || (pos.x == 5 && pos.y == 2 && nx == 4 && ny == 1) || (pos.x == 4 && pos.y == 1 && nx == 3 && ny == 0) || (pos.x == 4 && pos.y == 1 && nx == 5 && ny == 0) || pos.DistWith(nx, ny) <= 1.1) { candidates.push_back(Pos(nx, ny)); } } } } } return candidates; }
void putc(char c) { if (c == '\n') { _pos.newLine(); return; } write(_pos, 0xf, c); gotoxy(++_pos); }