Beispiel #1
0
// Simple benchmark for wallet coin selection. Note that it maybe be necessary
// to build up more complicated scenarios in order to get meaningful
// measurements of performance. From laanwj, "Wallet coin selection is probably
// the hardest, as you need a wider selection of scenarios, just testing the
// same one over and over isn't too useful. Generating random isn't useful
// either for measurements."
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
static void CoinSelection(benchmark::State& state)
{
    auto chain = interfaces::MakeChain();
    const CWallet wallet(*chain, WalletLocation(), WalletDatabase::CreateDummy());
    std::vector<std::unique_ptr<CWalletTx>> wtxs;
    LOCK(wallet.cs_wallet);

    // Add coins.
    for (int i = 0; i < 1000; ++i) {
        addCoin(1000 * COIN, wallet, wtxs);
    }
    addCoin(3 * COIN, wallet, wtxs);

    // Create groups
    std::vector<OutputGroup> groups;
    for (const auto& wtx : wtxs) {
        COutput output(wtx.get(), 0 /* iIn */, 6 * 24 /* nDepthIn */, true /* spendable */, true /* solvable */, true /* safe */);
        groups.emplace_back(output.GetInputCoin(), 6, false, 0, 0);
    }

    const CoinEligibilityFilter filter_standard(1, 6, 0);
    const CoinSelectionParams coin_selection_params(true, 34, 148, CFeeRate(0), 0);
    while (state.KeepRunning()) {
        std::set<CInputCoin> setCoinsRet;
        CAmount nValueRet;
        bool bnb_used;
        bool success = wallet.SelectCoinsMinConf(1003 * COIN, filter_standard, groups, setCoinsRet, nValueRet, coin_selection_params, bnb_used);
        assert(success);
        assert(nValueRet == 1003 * COIN);
        assert(setCoinsRet.size() == 2);
    }
}
// Simple benchmark for wallet coin selection. Note that it maybe be necessary
// to build up more complicated scenarios in order to get meaningful
// measurements of performance. From laanwj, "Wallet coin selection is probably
// the hardest, as you need a wider selection of scenarios, just testing the
// same one over and over isn't too useful. Generating random isn't useful
// either for measurements."
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
static void CoinSelection(benchmark::State &state)
{
    const CWallet wallet;
    std::vector<COutput> vCoins;
    LOCK(wallet.cs_wallet);

    while (state.KeepRunning())
    {
        // Empty wallet.
        for (COutput output : vCoins)
            delete output.tx;
        vCoins.clear();

        // Add coins.
        for (int i = 0; i < 1000; i++)
            addCoin(1000 * COIN, wallet, vCoins);
        addCoin(3 * COIN, wallet, vCoins);

        std::set<CInputCoin> setCoinsRet;
        CAmount nValueRet;
        bool success = wallet.SelectCoinsMinConf(1003 * COIN, 1, 6, 0, vCoins, setCoinsRet, nValueRet);
        assert(success);
        assert(nValueRet == 1003 * COIN);
        assert(setCoinsRet.size() == 2);
    }
}
/**
 * Kill player
 */
void RollingballApplet::killPlayer(bool outside)
{
    mTmrCoinLife->stop();
    mCoinVisible = false;
    mDead = true;
    mLives--;

    if(mLives > 0)
    {
        QSound::play(ROLLINGBALL_SND_OOPS);

        // Died from going out of the board
        if(outside)
        {
            mTmrCoinCycle->stop();
            QTimer::singleShot( 1500, this, SLOT( respawn() ) );
            QTimer::singleShot( 2000, this, SLOT( addCoin() ) );
        }
        else
        {
            mDead = false;
        }
    }
    else
    {
        QSound::play(ROLLINGBALL_SND_GAMEOVER);
        stopGame();
        QTimer::singleShot( 5000, this, SLOT( startGame() ) );
    }
}
Beispiel #4
0
void UpdateController::update() {
	snakeMutex.lock();
    for (auto snake : snakes) {
        moveSnake(*snake);
    }
	snakeMutex.unlock();
    if (coins.size() < NUMBER_OF_COINS) {
        while (coins.size() < NUMBER_OF_COINS) addCoin();
    }
}
RollingballApplet::RollingballApplet(QWidget *parent) : Applet(parent)
{
    mName = ROLLINGBALL_NAME;
    mTitle = ROLLINGBALL_TITLE;

    // load description, marketing and technical text from
    // xml file. Ensure that mName is set before calling this function
    loadTextFromXml();

    //
    // Build filter pipeline
    //
    mCalibrationFilter = new CalibrationFilter();
    reset();

    //
    // User interface
    //
    QPalette palette = this->palette();
    palette.setColor( backgroundRole(), Qt::gray );
    setPalette( palette );

    // images
    mImgBall.load( ":/image/rollingball/spirale.png" );
    mImgReflexion.load( ":/image/rollingball/reflexion.png" );
    mImgShadow.load( ":/image/rollingball/ballShadow.png" );
    mImgCoin.load( ":/image/rollingball/coin.png" );

    QHBoxLayout *layout = new QHBoxLayout( this );
    layout->setAlignment( Qt::AlignTop | Qt::AlignRight );

    mLcd = new QLCDNumber( this );
    mLcd->setNumDigits( 2 );
    mLcd->setFixedHeight( 32 );
    layout->addWidget( mLcd );

    mTmrCoinLife = new QTimer( this );
    mTmrCoinLife->setSingleShot( true );
    connect( mTmrCoinLife, SIGNAL( timeout() ), this, SLOT( killPlayer() ) );

    mTmrCoinCycle = new QTimer( this );
    mTmrCoinCycle->setInterval( ROLLINGBALL_COIN_CYCLE);
    connect( mTmrCoinCycle, SIGNAL( timeout() ), this, SLOT( addCoin() ) );

    qsrand( QTime::currentTime().msec() );

    // Gestures
    setGestures(SWAP_LEFT_RIGHT);
}
/**
 * Start the game
 */
void RollingballApplet::startGame()
{
    // dirty hack to prevent missing event
    if( !this->isVisible() )
    {
        stopGame();
        return;
    }

    // init game variables
    mGameOver = false;
    mScore = 0;
    mLives = 3;
    mLcd->display( mScore );
    mCoinCoeff = 1.0;
    mCoinVisible = false;
    this->respawn();
    QTimer::singleShot( 1000, this, SLOT( addCoin() ) );
}
Beispiel #7
0
UpdateController::UpdateController(std::vector<Snake*>* const snakes, std::vector<Coin>* const coins,
								   const std::vector<Wall>& walls, std::mutex* const snakeMutex,
								   std::mutex* const coinMutex, int periodMs, const Map& map) :
		PUTController(periodMs, true),
		snakes(*snakes),
		coins(*coins),
		walls(walls),
		snakeMutex(*snakeMutex),
		coinMutex(*coinMutex),
		map(map) {
	input = 1;

	std::random_device rd;
	rng = std::mt19937_64(rd());
	uniX = std::uniform_int_distribution<int> {0, map.getX() - 1};
	uniY = std::uniform_int_distribution<int> {0, map.getY() - 1};

	if (this->coins.size() < NUMBER_OF_COINS) {
		while (this->coins.size() < NUMBER_OF_COINS) addCoin();
	}
}