void Result() { extern int level, score, life; sf::Event event; sf::Font font; font.loadFromFile("SourceCodePro.ttf"); sf::Text text2; text2.setFont(font); text2.setCharacterSize(20); text2.setColor(sf::Color::Black); if (life <= 0) { sf::RenderWindow window2(sf::VideoMode(300, 80), "Game Over!"); while (window2.isOpen()) { while (window2.pollEvent(event)) { if (event.type == sf::Event::Closed) window2.close(); } window2.display(); char s2[30]; sprintf(s2, "Your Score: %d\nYour level: Level %d", score, level); text2.setString(s2); window2.clear(sf::Color::White); window2.draw(text2); } } if (score == 7500) { sf::RenderWindow window3(sf::VideoMode(300, 80), "You Win!"); while (window3.isOpen()) { while (window3.pollEvent(event)) { if (event.type == sf::Event::Closed) window3.close(); } window3.display(); char s2[30]; sprintf(s2, "Your Score: %d\nYour level: Level %d", score, level); text2.setString(s2); window3.clear(sf::Color::White); window3.draw(text2); } } }
scitbx::af::shared<double> #else bool #endif apd_hitfind(const scitbx::af::const_ref<double>& w, std::size_t wwidth) { #ifdef DEBUG scitbx::af::shared<double> window3( std::max(std::size_t(0), w.size() - wwidth)); #endif double rsum[3] = { 0, 0, 0 }; // running sums for expectations (E) double skew_amax, skew_mean, skew_ssq, skew_stddev, skew_sum; /* * Compute non-central moments up to order three for all windows. * This implementation will accumulate error, but requires only one * flat O(n) pass over the data. * * Compute skewness, the third central moment, in each window and * store in window3. Establish baseline (mean and standard * deviation) over the first samples. This is really a threshold. * Maybe it makes more sense to use the median and make use of * trailing samples as well? * * Remember absolute maximum skewness above the mean outside the * baseline region. */ skew_amax = skew_ssq = skew_sum = 0; for (std::size_t i = 0; i < std::min(wwidth, w.size()); i++) { rsum[0] += w[i]; rsum[1] += w[i] * w[i]; rsum[2] += w[i] * w[i] * w[i]; } for (std::size_t i = wwidth; i < w.size(); i++) { const std::size_t j = i - wwidth; const double c1 = rsum[0] / wwidth; const double c2 = std::max(0.0, rsum[1] / wwidth - c1 * c1); const double c3 = c2 > 0 ? (rsum[2] / wwidth - 3 * c1 * c2 - c1 * c1 * c1) / std::pow(c2, 1.5) : 0; if (j < wwidth) { skew_sum += c3; skew_ssq += c3 * c3; } else { skew_amax = std::max(skew_amax, std::abs(c3 - skew_sum / wwidth)); } #ifdef DEBUG window3[j] = c3; #endif rsum[0] += w[i] - w[j]; rsum[1] += w[i] * w[i] - w[j] * w[j]; rsum[2] += w[i] * w[i] * w[i] - w[j] * w[j] * w[j]; } skew_mean = skew_sum / wwidth; skew_stddev = std::max(0.0, skew_ssq - skew_sum * skew_mean); skew_stddev = std::sqrt( wwidth > 1 ? skew_stddev / (wwidth - 1) : skew_stddev); /* * For actual APD, it may make a lot more sense to look at one-step * transitions. XXX Read specs for the two diodes. */ if (skew_amax > 15 * skew_stddev) { // XXX magic #ifdef DEBUG printf("It's a HIT (amax %f, 15stddev %f)\n", skew_amax, 15 * skew_stddev); #else return (true); #endif } #ifdef DEBUG return window3; #else return (false); #endif }