std::multimap<float, Identifier> GLRenderer::hits(const GroupNode *group, const Vector3f &rayOrigin, const Vector3f &rayEnd, const Vector3f &rayDirection) const { std::multimap<float, Identifier> result; if (!group) return result; for (std::vector<Node *>::const_iterator it = group->children().begin(); it != group->children().end(); ++it) { std::multimap<float, Identifier> loopHits; const Node *itNode = *it; const GroupNode *childGroup = dynamic_cast<const GroupNode *>(itNode); if (childGroup) { loopHits = hits(childGroup, rayOrigin, rayEnd, rayDirection); result.insert(loopHits.begin(), loopHits.end()); continue; } const GeometryNode *childGeometry = (*it)->cast<GeometryNode>(); if (childGeometry) { loopHits = hits(childGeometry, rayOrigin, rayEnd, rayDirection); result.insert(loopHits.begin(), loopHits.end()); continue; } } return result; }
void Obstacle::hitCheck(Player* player) { if(!mHitPlayer) { const sf::Vector2f& pos=player->getSprite().GetPosition(); if(hits(sf::FloatRect(pos.x, pos.y-10, pos.x+5, pos.y-5)) && hits(sf::FloatRect(pos.x, pos.y+10, pos.x+5, pos.y+15))) { // Bam, Headshot. player->doLife(-1.1f); mHitPlayer=true; } } }
/* Calculate a list of keys which clash, plus the number of clashes they are involved in */ std::vector<std::pair<bit_vector,int> > find_clashing_keys(const BitHash &bh, const key_value_set &problem) { std::vector<std::vector<bit_vector> > hits(1<<bh.wO); for(const auto &kv : problem) { unsigned h=bh(kv.first); hits[h].push_back(kv.first); } std::map<bit_vector,int> clashes; for(const auto &h : hits){ if(h.size() > 1){ for(const auto &k : h){ clashes[k]++; } } } std::vector<std::pair<bit_vector,int> > res(clashes.begin(), clashes.end()); std::sort(res.begin(), res.end(), [](const std::pair<bit_vector,int> &a, const std::pair<bit_vector,int> &b) { return a.second > b.second; } ); return res; }
std::multimap<float, Identifier> GLRenderer::hits(int x, int y) const { // Our ray: const Vector3f origin(m_camera.unProject(Vector3f(static_cast<float>(x), static_cast<float>(y), 0.f))); const Vector3f end(m_camera.unProject(Vector3f(static_cast<float>(x), static_cast<float>(y), 1.f))); const Vector3f direction((end - origin).normalized()); return hits(&m_scene.rootNode(), origin, end, direction); }
int Stats::score() const { // Balancing factors // a = shot-balance // b = water-balance double a = 3; double b = 0.5; double score = (a * hits() - b * misses()) / (shots() + misses()) * 1000; int res = static_cast<int>(score); if (res <= 0) { res = 1; } return res; }
int main() { int i, j; long long flag; clrscr(); printf("Enter the size of the matrix : "); scanf("%d", &n); for(i = 1; i < n-1; i++) { for(j = 1; j < n-1; j++) { c[i][j] = ' '; } } food(); c[s][x] = '>'; while(1) { clrscr(); c[g][h] = '$'; prints(); if(kbhit()) { hits(); if(checks()) { printf("\nGAME OVER.\n"); getch(); return 0; } delay(500); continue; } blank(); c[g][h] = ' '; pressed_key(); eat(); if(checks()) { printf("\nGAME OVER.\n"); getch(); return 0; } add_length(); delay(500); } }
int sp_drainodem(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; troop dt; troop at; int force, enemies; int drained = 0; int killed = 0; const char *damage; message *m; /* 11-26 HP */ damage = spell_damage(4); /* Jungdrache 3->54, Drache 6->216, Wyrm 12->864 Treffer */ force = lovar(get_force(power, 6)); enemies = count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW - 1, SELECT_ADVANCE); if (!enemies) { m = msg_message("battle::out_of_range", "mage spell", fi->unit, sp); message_all(b, m); msg_release(m); return 0; } at.fighter = fi; at.index = 0; while (force && drained < enemies) { dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW - 1, SELECT_ADVANCE); assert(dt.fighter); if (hits(at, dt, NULL)) { drain_exp(dt.fighter->unit, 90); ++drained; killed += terminate(dt, at, AT_COMBATSPELL, damage, false); } --force; } m = msg_message("cast_drainlife_effect", "mage spell amount", fi->unit, sp, drained); message_all(b, m); msg_release(m); return level; }
void updateData(char board[], char mask[], int *missilesFired, int *missilesRemaining, int *score, char previousMove[], char currentMove[]) { *missilesRemaining -= 1; *missilesFired += 1; int check = hits(currentMove); strcpy(previousMove, currentMove); if (mask[check] == 0) { board[check] = 'X'; } else { if (mask[check] == 'S' || mask[check] == 'D' || mask[check] == 'C' || mask[check] == 'F' || mask[check] == '[' || mask[check] == '=' || mask[check] == '>'){ if (board[check] == '~') { board[check] = mask[check]; *score += 5; } } } }
//================================================================ ClustersByPlane constructPlaneClusters(int maxPlaneNumber, const TDCHitWPPtrCollection& inhits) { ClustersByPlane res(1+maxPlaneNumber); TDCHitWPPtrCollection hits(inhits); std::sort(hits.begin(), hits.end(), TDCHitWPCmpGeom()); for(unsigned i=0; i<hits.size(); ) { TDCHitWPPtrCollection tmphits; tmphits.push_back(hits[i]); const int plane = hits[i]->plane(); for(++i; i<hits.size();++i) { if(plane != hits[i]->plane()) break; if(tmphits.back()->cell() + 1 < hits[i]->cell()) break; tmphits.push_back(hits[i]); } res[plane].push_back(WireCluster(tmphits)); } return res; }
void Obstacle::hitCheck(Enemy* enemy) { const sf::Vector2f& pos=enemy->getSprite().GetPosition(); if(hits(sf::FloatRect(pos.x, pos.y, pos.x+5, pos.y+5))) enemy->destroy(); }
int main(int argc, char const * argv[]) { // Additional checks seqan::ArgumentParser parser = buildParser(); seqan::ArgumentParser::ParseResult res = seqan::parse(parser, argc, argv); // Check if input was successfully parsed. if (res != seqan::ArgumentParser::PARSE_OK) return res == seqan::ArgumentParser::PARSE_ERROR; // Check if one or two input files (single or paired-end) were given. int fileCount = getArgumentValueCount(parser, 0); if (fileCount < 1) { printShortHelp(parser); return 1; } unsigned int radius = 1; getOptionValue(radius, parser, "r"); seqan::CharString readsFileName; getOptionValue(readsFileName, parser, "i"); // Open input file, BamFileIn can read SAM and BAM files. seqan::BamFileIn bamFileIn(seqan::toCString(readsFileName)); seqan::CharString _filterChromosomes; seqan::getOptionValue(_filterChromosomes, parser, "fc"); std::string filterChromosomes = seqan::toCString(_filterChromosomes); OccurenceMap occurenceMap; Statistics stats; std::cout << "read bam file... "; auto t1 = std::chrono::steady_clock::now(); seqan::BamAlignmentRecord record; seqan::BamHeader header; readHeader(header, bamFileIn); const auto chromosomeFilterSet = calculateChromosomeFilter(filterChromosomes, contigNames(context(bamFileIn))); const auto chromosomes = contigNames(context(bamFileIn)); processBamFile(bamFileIn, chromosomeFilterSet, occurenceMap, stats); auto t2 = std::chrono::steady_clock::now(); std::cout << std::chrono::duration_cast<std::chrono::duration<float>>(t2 - t1).count() << "s" << std::endl; std::vector<std::pair<unsigned int, unsigned int>> hits(radius * 2 + 1); t1 = std::chrono::steady_clock::now(); std::cout << "calculating 5'-ends around peaks... "; for (unsigned int fileIndex = 0;fileIndex < static_cast<unsigned int>(fileCount); ++fileIndex) { seqan::CharString fileName_; getArgumentValue(fileName_, parser, fileIndex, 0); const std::string fileName = seqan::toCString(fileName_); std::ifstream infile(fileName); std::string chromosome, dummy; unsigned int start, end; while (infile >> chromosome >> start >> end >> dummy) { int rID = -1; for (unsigned int i = 0;i < length(chromosomes);++i) if (chromosomes[i] == chromosome) { rID = i; break; } if (rID == -1) { std::cout << "invalid chromosome name: " << chromosome << " in file " << fileName << std::endl; return -1; } seqan::BamAlignmentRecord record; record.beginPos = std::max<int>(start - radius, 0); record.rID = rID; record.flag = 0; unsigned int index = 0; if (start < radius) index += radius - start; while (record.beginPos <= static_cast<__int32>(start + radius)) { BamRecordKey<NoBarcode> pos(record); auto el = occurenceMap.find(pos); if(el != occurenceMap.end()) hits[index].first += el->second; pos.init(pos.getRID(), pos.get5EndPosition(), true); el = occurenceMap.find(pos); if (el != occurenceMap.end()) hits[index].second += el->second; ++record.beginPos; ++index; } } std::string outFilename = getFilePrefix(fileName) + std::string("_5PrimeEnds.tab"); if (seqan::isSet(parser, "o")) { seqan::CharString outFileName_; getOptionValue(outFileName_, parser, "o"); outFilename = seqan::toCString(outFileName_); } std::fstream fs; std::cout << "writing " << outFilename << std::endl; #ifdef _MSC_VER fs.open(outFilename, std::fstream::out, _SH_DENYNO); #else fs.open(outFilename, std::fstream::out); #endif int i = - static_cast<int>(radius); for (const auto& hit : hits) fs << i++ << "\t" << hit.first << "\t" << hit.second << std::endl; fs.close(); } t2 = std::chrono::steady_clock::now(); std::cout << std::chrono::duration_cast<std::chrono::duration<float>>(t2 - t1).count() << "s" << std::endl; return 0; }
Integer* InlineCacheEntry::hits_prim(STATE) { return Integer::from(state, hits()); }
Integer* RespondToCache::hits_prim(STATE) { return Integer::from(state, hits()); }
std::vector< Vector > CIsoSurfaceBase::getSurfaceVoxelPositions() { // TODO selection iso check this out if ( m_threshold == 0.0 || m_threshold == 1.0 ) { m_svPositions.clear(); return m_svPositions; } if ( !m_positionsCalculated ) { DatasetManager *pDM( DatasetManager::getInstance() ); Vector v( 0, 0, 0 ); size_t nSize = pDM->getColumns() * pDM->getRows() * pDM->getFrames(); std::vector< Vector > accu( nSize, v ); std::vector< int > hits( nSize, 0 ); std::vector< Vector > vertices = m_tMesh->getVerts(); m_svPositions.clear(); for ( size_t i = 0; i < vertices.size(); ++i ) { v = vertices[i]; int index = (int) v.x + (int) v.y * pDM->getColumns() + (int) v.z * pDM->getColumns() * pDM->getRows(); if ( !( index < 0 || index > pDM->getColumns() * pDM->getRows() * pDM->getFrames()) ) { accu[index].x += v.x; accu[index].y += v.y; accu[index].z += v.z; hits[index] += 1; } } int pointsInVoxels = 0; int voxelsHit = 1; for ( size_t i = 0; i < nSize; ++i ) { if ( hits[i] > 0 ) { ++voxelsHit; pointsInVoxels += hits[i]; } } pointsInVoxels /= voxelsHit; int threshold = pointsInVoxels / 2; for ( size_t i = 0; i < nSize; ++i ) { if ( hits[i] > threshold ) { accu[i].x /= hits[i]; accu[i].y /= hits[i]; accu[i].z /= hits[i]; if ( (int) accu[i].x ) { accu[i].x = wxMin( pDM->getColumns(), wxMax ( accu[i].x, 0 ) ); accu[i].y = wxMin( pDM->getRows(), wxMax ( accu[i].y, 0 ) ); accu[i].z = wxMin( pDM->getFrames(), wxMax ( accu[i].z, 0 ) ); Vector v( accu[i].x, accu[i].y, accu[i].z ); m_svPositions.push_back( v ); } } } m_positionsCalculated = true; } return m_svPositions; }
/***************************************************************************** // The knn matching with k = 2 // This code performs the matching and the refinement. // @paraam query_image: the input image // @param matches_out: a pointer that stores the output matches. It is necessary for // pose estimation. */ int knn_match(cv::Mat& query_image, std::vector< cv::DMatch> * matches_out) { // variabels that keep the query keypoints and query descriptors std::vector<cv::KeyPoint> keypointsQuery; cv::Mat descriptorQuery; // Temporary variables for the matching results std::vector< std::vector< cv::DMatch> > matches1; std::vector< std::vector< cv::DMatch> > matches2; std::vector< std::vector< cv::DMatch> > matches_opt1; ////////////////////////////////////////////////////////////////////// // 1. Detect the keypoints // This line detects keypoints in the query image _detector->detect(query_image, keypointsQuery); // If keypoints were found, descriptors are extracted. if(keypointsQuery.size() > 0) { // extract descriptors _extractor->compute( query_image, keypointsQuery, descriptorQuery); } ////////////////////////////////////////////////////////////////////////////// // 2. Here we match the descriptors with the database descriptors. // with k-nearest neighbors with k=2 _matcher.knnMatch(descriptorQuery , matches1, 2); #ifdef DEBUG_OUT std::cout << "Found " << matches1.size() << " matching feature descriptors out of " << _matcher.getTrainDescriptors().size() << " database descriptors." << std::endl; #endif ////////////////////////////////////////////////////////////////////////////// // 3 Filter the matches. // Accept only matches (knn with k=2) which belong ot one images // The database tree within _matcher contains descriptors of all input images. // We expect that both nearest neighbors must belong to one image. // Otherwise we can remove the result. // Along with this, we count which reference image has the highest number of matches. // At this time, we consinder this image as the searched image. // we init the variable hit with 0 std::vector<int> hits(_num_ref_images); for (int i=0; i<_num_ref_images; i++) { hits[i] = 0; } // the loop runs through all matches and comparees the image indes // imgIdx. The must be equal otherwise the matches belong to two // different reference images. for (int i=0; i<matches1.size(); i++) { // The comparison. if(matches1[i].at(0).imgIdx == matches1[i].at(1).imgIdx) { // we keep it matches_opt1.push_back(matches1[i]); // and count a hit hits[matches1[i].at(0).imgIdx]++; } } #ifdef DEBUG_OUT std::cout << "Optimized " << matches_opt1.size() << " feature descriptors." << std::endl; #endif // Now we search for the highest number of hits in our hit array // The variable max_idx keeps the image id. // The variable max_value the amount of hits. int max_idx = -1; int max_value = 0; for (int i=0; i<_num_ref_images; i++) { #ifdef DEBUG_OUT std::cout << "for " << i << " : " << hits[i] << std::endl; #endif if(hits[i] > max_value) { max_value = hits[i]; max_idx = i; } } /////////////////////////////////////////////////////// // 4. The cross-match // At this time, we test the database agains the query descriptors. // The variable max_id stores the reference image id. Thus, we test only // the descriptors that belong to max_idx agains the query descriptors. _matcher.knnMatch(_descriptorsRefDB[max_idx], descriptorQuery, matches2, 2); /////////////////////////////////////////////////////// // 5. Refinement; Ratio test // The ratio test only accept matches which are clear without ambiguity. // The best hit must be closer to the query descriptors than the second hit. int removed = ratioTest(matches_opt1); #ifdef DEBUG_OUT std::cout << "Removed " << removed << " matched." << std::endl; #endif removed = ratioTest(matches2); #ifdef DEBUG_OUT std::cout << "Removed " << removed << " matched." << std::endl; #endif /////////////////////////////////////////////////////// // 6. Refinement; Symmetry test // We only accept matches which appear in both knn-matches. // It should not matter whether we test the database against the query desriptors // or the query descriptors against the database. // If we do not find the same solution in both directions, we toss the match. std::vector<cv::DMatch> symMatches; symmetryTest( matches_opt1, matches2, symMatches); #ifdef DEBUG_OUT std::cout << "Kept " << symMatches.size() << " matches after symetry test test." << std::endl; #endif /////////////////////////////////////////////////////// // 7. Refinement; Epipolar constraint // We perform a Epipolar test using the RANSAC method. if(symMatches.size() > 25) { matches_out->clear(); ransacTest( symMatches, _keypointsRefDB[max_idx], keypointsQuery, *matches_out); } #ifdef DEBUG_OUT std::cout << "Kept " << matches_out->size() << " matches after RANSAC test." << std::endl; #endif /////////////////////////////////////////////////////// // 8. Draw this image on screen. cv::Mat out; cv::drawMatches(feature_map_database[max_idx]._ref_image , _keypointsRefDB[max_idx], query_image, keypointsQuery, *matches_out, out, cv::Scalar(255,255,255), cv::Scalar(0,0,255)); std::string num_matches_str; std::strstream conv; conv << matches_out->size(); conv >> num_matches_str; std::string text; text.append( num_matches_str); text.append("( " + _num_ref_features_in_db_str + " total)"); text.append(" matches were found in reference image "); text.append( feature_map_database[max_idx]._ref_image_str); putText(out, text, cvPoint(20,20), cv::FONT_HERSHEY_COMPLEX_SMALL, 1.0, cvScalar(0,255,255), 1, CV_AA); cv::imshow("result", out); if (run_video) cv::waitKey(1); else cv::waitKey(); // Delete the images query_image.release(); out.release(); return max_idx; }
short effect::act() { short temp; Sint32 xd, yd, distance, generic; oblink *foelist, *here; walker *newob; short numfoes; // Make sure everyone we're poshorting to is valid if (foe && foe->dead) foe = NULL; if (leader && leader->dead) leader = NULL; if (owner && owner->dead) owner = NULL; collide_ob = NULL; // always start with no collison.. // Any special actions .. switch (family) // determine what to do.. { case FAMILY_GHOST_SCARE: if (owner) center_on(owner); break; case FAMILY_MAGIC_SHIELD: // revolve around owner if (!owner || owner->dead) { dead = 1; death(); break; } switch (drawcycle % 16) { case 0: xd = 0; yd = -24; break; case 1: xd = -9; yd = -22; break; case 2: xd = -17; yd = -17; break; case 3: xd = -22; yd = -9; break; case 4: xd = -24; yd = 0; break; case 5: xd = -22; yd = 9; break; case 6: xd = -17; yd = 17; break; case 7: xd = -9; yd = 22; break; case 8: xd = 0; yd = 24; break; case 9: xd = 9; yd = 22; break; case 10: xd = 17; yd = 17; break; case 11: xd = 22; yd = 9; break; case 12: xd = 24; yd = 0; break; case 13: xd = 22; yd = -9; break; case 14: xd = 17; yd = -17; break; case 15: xd = 9; yd = -22; break; } center_on(owner); setxy( (short)( xpos+xd ), (short) (ypos+yd) ); foelist = screenp->find_foe_weapons_in_range( screenp->oblist, sizex, &temp, this); here = foelist; while (foelist) // first weapons { stats->hitpoints -= foelist->ob->damage; foelist->ob->dead = 1; foelist->ob->death(); foelist = foelist->next; } delete_list(here); foelist = screenp->find_foes_in_range( screenp->oblist, sizex, &temp, this); here = foelist; while (foelist) // second enemies { stats->hitpoints -= foelist->ob->damage; attack(foelist->ob); dead = 0; foelist = foelist->next; } delete_list(here); if ( (stats->hitpoints <= 0) || (lifetime-- < 0) ) { dead = 1; death(); } break; // end of magic shield case case FAMILY_BOOMERANG: // fighter's boomerang // Zardus: FIX: if the drawcycle is in its >253s, the boomerang dies. This will fix the bug where // the boomerang comes back to 0 (owner) after spiraling around all the way if the owner has // that good of an ability (to keep its life so high). This caps boomerang ability, though... Another // fix could be to make the drawcycle var an int or at least something with more capacity than char. if (!owner || owner->dead || drawcycle > 253) { dead = 1; death(); break; } switch (drawcycle % 16) { case 0: xd = 0; yd = -24; break; case 1: xd = -9; yd = -22; break; case 2: xd = -17; yd = -17; break; case 3: xd = -22; yd = -9; break; case 4: xd = -24; yd = 0; break; case 5: xd = -22; yd = 9; break; case 6: xd = -17; yd = 17; break; case 7: xd = -9; yd = 22; break; case 8: xd = 0; yd = 24; break; case 9: xd = 9; yd = 22; break; case 10: xd = 17; yd = 17; break; case 11: xd = 22; yd = 9; break; case 12: xd = 24; yd = 0; break; case 13: xd = 22; yd = -9; break; case 14: xd = 17; yd = -17; break; case 15: xd = 9; yd = -22; break; } xd *= (drawcycle+4); xd /= 48; yd *= (drawcycle+4); yd /= 48; center_on(owner); setxy((short) (xpos+xd), (short) (ypos+yd) ); foelist = screenp->find_foe_weapons_in_range( screenp->oblist, sizex*2, &temp, this); here = foelist; while (foelist) // first weapons { stats->hitpoints -= foelist->ob->damage; foelist->ob->dead = 1; foelist->ob->death(); foelist = foelist->next; } delete_list(here); foelist = screenp->find_foes_in_range( screenp->oblist, sizex, &temp, this); here = foelist; while (foelist) // second enemies { stats->hitpoints -= foelist->ob->damage; attack(foelist->ob); dead = 0; foelist = foelist->next; } delete_list(here); if ( (stats->hitpoints <= 0) || (lifetime-- < 0) ) { dead = 1; death(); } break; // end of boomerang case case FAMILY_KNIFE_BACK: // returning blade if (!owner || owner->dead) { dead = 1; break; } distance = distance_to_ob(owner); if (distance > 10) { xd = yd = 0; // zero out distance movements if (owner->xpos > xpos) { if ( (owner->xpos - xpos) > stepsize ) xd = stepsize; else xd = owner->xpos - xpos; } else if (owner->xpos < xpos) { if ( (xpos - owner->xpos) > stepsize ) xd = -stepsize; else xd = owner->xpos - xpos; } if (owner->ypos > ypos) { if ( (owner->ypos - ypos) > stepsize ) yd = stepsize; else yd = owner->ypos - ypos; } else if (owner->ypos < ypos) { if ( (ypos - owner->ypos) > stepsize ) yd = -stepsize; else yd = owner->ypos - ypos; } setxy((short) (xpos+xd), (short) (ypos+yd) ); newob = screenp->add_ob(ORDER_WEAPON, FAMILY_KNIFE); newob->damage = damage; newob->owner = owner; newob->team_num = team_num; newob->death_called = 1; // to ensure no spawning of more .. newob->setxy(xpos, ypos); if (!screenp->query_object_passable((short) (xpos+xd), (short) (ypos+yd), newob)) { newob->attack(newob->collide_ob); damage /= 4; //setxy(xpos-(2*xd)+random(xd), ypos-(2*yd)+random(yd)); } newob->dead = 1; } else { owner->weapons_left++; //if (owner->user != -1) //{ // sprintf(message, "Knives now %d", owner->weapons_left); // screenp->do_notify(message, owner); //} ani_type = ANI_WALK; dead = 1; } break; case FAMILY_CLOUD: // poison cloud if (lifetime > 0) lifetime--; else { dead = 1; death(); } if (lifetime < 8) invisibility_left +=3; if (invisibility_left > 0) invisibility_left--; // Hit any nearby foes (not friends, for now) foelist = screenp->find_foes_in_range( screenp->oblist, sizex, &temp, this); here = foelist; while (foelist) // { if (hits(xpos, ypos, sizex, sizey, // this is the cloud foelist->ob->xpos, foelist->ob->ypos, foelist->ob->sizex, foelist->ob->sizey) ) { attack(foelist->ob); } // end of actual hit foelist = foelist->next; } delete_list(here); // Are we performing some action? if (stats->commandlist) temp = stats->do_command(); else { xd = yd = 0; while (xd == 0 && yd == 0) { xd = random(3)-1; yd = random(3)-1; } stats->add_command(COMMAND_WALK, (short) random(20), (short) xd, (short) yd); } break; // end of cloud case FAMILY_CHAIN: // chain lightning .. if (!leader || lineofsight<1 || !owner) // lost our leader, etc.? kill us .. { dead = 1; death(); return 1; } // Are we at our leader? If so, attack him :) if (hits(xpos, ypos, sizex, sizey, leader->xpos, leader->ypos, leader->sizex, leader->sizey)) { // Do things .. newob = screenp->add_ob(ORDER_FX, FAMILY_EXPLOSION); if (!newob) { dead = 1; death(); return 1; // failsafe } newob->owner = owner; newob->team_num = team_num; newob->stats->level = stats->level; newob->damage = damage; newob->ani_type = ANI_EXPLODE; newob->center_on(this); leader->skip_exit += 3; // can't hit us for 3 rounds .. if (on_screen()) screenp->soundp->play_sound(SOUND_EXPLODE); // Now make new objects to seek out foes .. // First, are our offspring powerful enough at 1/2 our power? generic = (damage)/2; if (owner->myguy) foelist = screenp->find_foes_in_range(screenp->oblist, 240+(owner->myguy->intelligence/2), &temp, this); else foelist = screenp->find_foes_in_range(screenp->oblist, 240+stats->level*5, &temp, this); if (temp && generic>20) // more foes to find .. { here = foelist; numfoes = random(owner->stats->level)+1; while (here && numfoes--) { if (here->ob != leader && here->ob->skip_exit<1) // don't hit current guy, etc. { newob = screenp->add_ob(ORDER_FX, FAMILY_CHAIN); if (!newob) { delete_list(foelist); return 0; // failsafe } newob->owner = owner; // our caster newob->leader = here->ob; // guy to attack newob->stats->level = stats->level; newob->stats->set_bit_flags(BIT_MAGICAL, 1); newob->damage = generic; newob->team_num = team_num; newob->center_on(this); } // end of wasn't current guy case here = here->next; } // end of loop for nearby foes we found } // end of check for nearby foes // Clean up our list .. ? // Zardus: TAG: nah, lets use delete_list /*here = foelist->next; while (here) { delete foelist; foelist = here; here = here->next; } delete foelist;*/ delete_list(foelist); dead = 1; death(); return 1; } // Move toward our leader .. lineofsight--; distance = distance_to_ob_center(leader); if (distance > stepsize*2) { xd = yd = 0; // zero out distance movements if (leader->xpos > xpos) { if ( (leader->xpos - xpos) > stepsize ) xd = stepsize; else xd = leader->xpos - xpos; } else if (leader->xpos < xpos) { if ( (xpos - leader->xpos) > stepsize ) xd = -stepsize; else xd = leader->xpos - xpos; } if (leader->ypos > ypos) { if ( (leader->ypos - ypos) > stepsize ) yd = stepsize; else yd = leader->ypos - ypos; } else if (leader->ypos < ypos) { if ( (ypos - leader->ypos) > stepsize ) yd = -stepsize; else yd = leader->ypos - ypos; } // Set our facing? curdir = facing(xd, yd); set_frame(ani[curdir][0]); } // end of big step else { //xd = leader->xpos; //yd = leader->ypos; center_on(leader); return 1; } setxy((short) (xpos+xd), (short) (ypos+yd) ); return 1; // so as not to animate, etc. //break; // end of FAMILY_CHAIN case FAMILY_DOOR_OPEN: // Here is how doors work. They start out as a FAMILY_DOOR // from ORDER_WEAPON under the weaplist. When the door is // collided with, the obmap marks the door as dead, and spawns // the FAMILY_DOOR_OPEN on the weaplist (this object). It // animates ANI_DOOR_OPEN, and when it is done, it dies and // spawns a FAMILY_DOOR_OPEN on the fxlist. The amusing part // is that now that it is on the fxlist, it won't act anymore, // thus preventing it from continuously respawning itself. if (ani_type != ANI_WALK) return animate(); newob = screenp->add_fx_ob(ORDER_FX, FAMILY_DOOR_OPEN); if (!newob) break; newob->ani_type = ANI_WALK; newob->setxy(xpos, ypos); newob->stats->level = stats->level; newob->team_num = team_num; newob->ignore = 1; newob->curdir = curdir; // set correct frame newob->animate(); dead = 1; death(); return 1; break; default: break; } // Complete previous animations (like firing) if (ani_type != ANI_WALK) return animate(); switch (family) // determine what to do.. { default: dead = 1; death(); break; } return 0; }
int main(void) { char * name=loadFile("name.txt"); char * buf= init(name); //get starting message int sockfd, numbytes; struct addrinfo hints, *servinfo, *p; int rv; char s[INET6_ADDRSTRLEN]; memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if ((rv = getaddrinfo(HOST, PORT, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } // loop through all the results and connect to the first we can for(p = servinfo; p != NULL; p = p->ai_next) { if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { perror("client: socket"); continue; } if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) { close(sockfd); perror("client: connect"); continue; } break; } if (p == NULL) { fprintf(stderr, "client: failed to connect\n"); return 2; } inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s, sizeof s); freeaddrinfo(servinfo); // all done with this structure send(sockfd, buf, strlen(buf)+1, 0); char str[MAXDATASIZE]; if ((numbytes = recv(sockfd, str, MAXDATASIZE-1, 0)) == -1) { perror("recv"); exit(1); } str[numbytes] = '\0'; //Determine my player token char * temptok = strstr(strstr(strstr(str, "playerToken"), ":"), "\"")+1; char * tempend = strstr(temptok, "\""); tempend[0]=0; char * token=malloc(tempend-temptok+1); strcpy(token, temptok); tempend[0]='\"'; int res; while(1){ res=getTurn(buf, token, responseCode(str), resources(str), ships(str), errors(str), hits(str), actionResponses(str), pings(str)); if(res==1) break; if(res==2) { send(sockfd, buf, strlen(buf)+1, 0); } if ((numbytes = recv(sockfd, str, MAXDATASIZE-1, 0)) == -1) { perror("recv"); exit(1); } str[numbytes] = '\0'; } close(sockfd); free(buf); free(token); free(name); return 0; }
void InlineCacheRegistry::print_stats(STATE) { int total = 0; std::vector<int> sizes(cTrackedICHits + 1); int overflow = 0; for(CacheHash::iterator hi = caches_.begin(); hi != caches_.end(); ++hi) { for(CacheVector::iterator vi = hi->second.begin(); vi != hi->second.end(); ++vi) { InlineCache* ic = *vi; int seen = ic->classes_seen(); if(ic->seen_classes_overflow() > 0) { total++; overflow++; } else if(seen > 0) { total++; sizes[seen]++; } } } std::cerr << "IC Stats:\n"; for(int i = 1; i < cTrackedICHits + 1; i++) { std::cerr << " " << i << ": " << sizes[i] << " " << ratio(sizes[i], total) << "%\n"; } std::cerr << cTrackedICHits << "+: " << overflow << " " << ratio(overflow, total) << "%\n"; // Stats that take the number of hits into account std::vector<int> hits(cTrackedICHits + 1); int overflow_hits = 0; int total_hits = 0; for(CacheHash::iterator hi = caches_.begin(); hi != caches_.end(); ++hi) { for(CacheVector::iterator vi = hi->second.begin(); vi != hi->second.end(); ++vi) { InlineCache* ic = *vi; int seen = ic->classes_seen(); if(ic->seen_classes_overflow() > 0) { int these_hits = (ic->total_hits() + ic->seen_classes_overflow()); overflow_hits += these_hits; total_hits += these_hits; } else if(seen > 0) { hits[seen] += ic->total_hits(); total_hits += ic->total_hits(); } } } std::cerr << "Hits per classes tracked: (" << total_hits << ")\n"; for(int i = 1; i < cTrackedICHits + 1; i++) { std::cerr << " " << i << ": " << hits[i] << " " << ratio(hits[i], total_hits) << "%\n"; } std::cerr << cTrackedICHits << "+: " << overflow_hits << " " << ratio(overflow_hits, total_hits) << "%\n"; // print out the mega-morphic ones std::cerr << "\nMegamorphic call sites:\n"; for(CacheHash::iterator hi = caches_.begin(); hi != caches_.end(); ++hi) { for(CacheVector::iterator vi = hi->second.begin(); vi != hi->second.end(); ++vi) { InlineCache* ic = *vi; if(ic->seen_classes_overflow() > 0) { ic->print(state, std::cerr); std::cerr << "location: "; ic->print_location(state, std::cerr); std::cerr << "\n\n"; } } } }
void* threadSearchDatabase(void* params) { auto thread_data = (ThreadSearchData*) params; thread_data->candidates.resize(thread_data->queries_length); std::vector<uint32_t> kmer_vector; std::vector<std::vector<int32_t>> hits(thread_data->queries_length); std::vector<float> min_scores(thread_data->min_scores); uint32_t log_counter = 0; uint32_t log_size = (thread_data->database_end - thread_data->database_begin) / (100. / log_step_percentage); float log_percentage = log_step_percentage; for (uint32_t i = thread_data->database_begin; i < thread_data->database_end; ++i) { if (thread_data->log && log_percentage < 100.0) { ++log_counter; if (log_size != 0 && log_counter % log_size == 0) { databaseLog(thread_data->part, thread_data->part_size, log_percentage); log_percentage += log_step_percentage; } } createKmerVector(kmer_vector, thread_data->database[i], thread_data->kmer_length); for (uint32_t j = 0; j < kmer_vector.size(); ++j) { if (j != 0 && kmer_vector[j] == kmer_vector[j - 1]) { continue; } Hash::Iterator begin, end; thread_data->query_hash->hits(begin, end, kmer_vector[j]); for (; begin != end; ++begin) { hits[begin->id].emplace_back(begin->position); } } for (uint32_t j = 0; j < thread_data->queries_length; ++j) { if (hits[j].empty()) { continue; } float similartiy_score = longestIncreasingSubsequence(hits[j]) / (float) chainGetLength(thread_data->database[i]); if (thread_data->candidates[j].size() < thread_data->max_candidates || similartiy_score > min_scores[j]) { thread_data->candidates[j].emplace_back(similartiy_score, i); min_scores[j] = std::min(min_scores[j], similartiy_score); } std::vector<int32_t>().swap(hits[j]); } } for (uint32_t i = 0; i < thread_data->queries_length; ++i) { std::sort(thread_data->candidates[i].begin(), thread_data->candidates[i].end()); if (thread_data->candidates[i].size() > thread_data->max_candidates) { std::vector<Candidate> tmp(thread_data->candidates[i].begin(), thread_data->candidates[i].begin() + thread_data->max_candidates); thread_data->candidates[i].swap(tmp); } } delete thread_data; return nullptr; }