예제 #1
0
//The MC rejection algorithm, returns true for a valid x,y set whose probability is greater than a random number generated between 0 and WMAX
bool XYgenerator::testProbability(double p, double x, double y){
	double test = RNG->Uniform(0.0,WMAX);
	if (getProbability(x,y) > WMAX){
		cout<<"EXCEEDED WMAX!!"<<endl;
	}
	if(getProbability(x,y) > test){
		return true;
	}
	else return false;
}
예제 #2
0
void CBerkeloid::processMoving()
{
  if(blockedd)
    moveUp(10);
  
	if( mTimer < BERKELOID_TIME )
	{
		mTimer++;
		return;
	}
	else
	{
		mTimer = 0;
	}

	// Chance to throw a flame
	if( getProbability(20) )
	{
		setAction( A_BERKELOID_THROW );
		playSound( SOUND_BERKELOID_WINDUP );
		CBerkFlame *flame = new CBerkFlame( getMapPtr(), getXMidPos(), getYUpPos(), xDirection );
		gEventManager.add( new EventSpawnObject( flame ) );
		return;
	}

}
  double RandomNumberGenerator::getRealNumberBetween(double min, double max) {
    double p = getProbability();

    double number = min + (p * (max - min));

    return number;
  }
예제 #4
0
//Find the probability of a value being correct given a mean and standard deviation
float getProbability(int8_t value, float standardDeviation, int8_t mean)
{
	for(uint8_t i = 0; i < probabilityTables.filledEntries; i++)
	{
		if(probabilityTables.entries[i].standardDeviation == standardDeviation)
		{
			return probabilityTables.entries[i].probabilities[abs(value - mean)];
		}
	}
	//No entry for this SD found, generate table
	
	if(probabilityTables.filledEntries < MAX_NUMBER_OF_PROBABILITY_TABLES)
	{
	//	TERMINAL_PRINTF("Generating probability table for a standard deviation of %i\n", (int16_t)(standardDeviation*1000.0f));
		generateProbabilityTable(&probabilityTables.entries[probabilityTables.filledEntries], standardDeviation);
		probabilityTables.filledEntries++;
	}
	else
	{
	//	TERMINAL_PRINTF("Insufficient space for probability arrays, halting");
		while(1);
	}
	//Should successfully get a probability this time
	return getProbability(value, standardDeviation, mean);
	
	//Should never reach here
    //	TERMINAL_PRINTF("Overflowed probabilities array\n");
	while(1);
	return -1;
}
예제 #5
0
void CKorath::processWalking()
{
  // Move normally in the direction
  if( xDirection == RIGHT )
  {
    moveRight( WALK_SPEED );
  }
  else
  {
    moveLeft( WALK_SPEED );
  }
  
  
  mTimer++;
  
  if( mTimer < TIME_TO_SIT)
    return;
  
  mTimer = 0;
  
  if(getProbability(120))
  {
    setAction(A_KORATH_SIT);
  }
  
}
예제 #6
0
bool CAmpton::isNearby(CSpriteObject &theObject)
{
	if( !getProbability(10) )
		return false;

	return true;
}
void CCouncilMember::processWalking()
{
    performCollisions();
    performGravityLow();

    // Check if there is a cliff and move him back in case
    performCliffStop(m_Action.velX<<1);


    if( m_timer < ELDER_MOVE_TIMER )
    {
        m_timer++;
        return;
    }
    else
    {
        m_timer = 0;
    }

    // Chance if he will think
    if( getProbability(25) )
    {
        m_timer = 0;
        mp_processState = &CCouncilMember::processThinking;
        setAction(A_COUNCIL_MEMBER_THINK);
        return;
    }

    // Move normally in the direction
    if( xDirection == RIGHT )
        moveRight( m_Action.velX<<1 );
    else
        moveLeft( m_Action.velX<<1 );

}
예제 #8
0
void CBlueBird::processFlying()
{
	if(inhibitfall)
	{
		if( mTimer % CHANCETOFLY == 0 )
		{
			// Chance to land
			if( getProbability(20) )
				inhibitfall = false;
		}

		mTimer++;

		// Move normally in the direction
		if( xDirection == RIGHT )
			moveRight( FLY_SPEED );
		else
			moveLeft( FLY_SPEED );

		if( yDirection == UP )
			moveUp( FLY_SPEED );
		else
			moveDown( FLY_SPEED );
	}
	else
	{
		if(blockedd)
			setAction(A_EAGLE_WALKING);
	}
}
예제 #9
0
void CSpirogrip::processSpin()
{
  mTimer++;
  if( mTimer < TIME_UNTIL_FLY )
      return;
  
  mTimer = 0;

  playSound(SOUND_SPIROFLY);
  
  // Look at the Player coords and define a direction
  xDirection = yDirection = CENTER;
  if(getProbability(500))
      xDirection = mKeenAlignmentX;
  else
      yDirection = mKeenAlignmentY;
  
  if(xDirection == LEFT)
      setAction(A_GRIP_MOVE_LEFT);
  else if(xDirection == RIGHT)
      setAction(A_GRIP_MOVE_RIGHT);

  if(yDirection == UP)
      setAction(A_GRIP_MOVE_UP);
  else if(yDirection == DOWN)
      setAction(A_GRIP_MOVE_DOWN);
  
}
예제 #10
0
bool CBlueBird::isNearby(CSpriteObject &theObject)
{
            
	if( !getProbability(20) )
		return false;
	
	if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) )
	{
		if( player->getXMidPos() < getXMidPos() )
			xDirection = LEFT;
		else
			xDirection = RIGHT;

		if( player->getYMidPos() < getYMidPos() )
			yDirection = UP;
		else
			yDirection = DOWN;
		
		
		// so the bottom of keen's box has to be >= 3 tiles above the bottom of the bird's box
		// and keen needs to be on the ground -> Quote by Lemm
		const int pYDown = player->getYDownPos();
		const int bYDown = getYDownPos();
		if( player->blockedd && pYDown <= bYDown-(3<<CSF)  )
		{
    			setAction(A_EAGLE_FLYING);
			inhibitfall = true;
		}
	}

	return true;
}
예제 #11
0
bool CSparky::isNearby(CSpriteObject &theObject)
{
	if( !getProbability(10) )
		return false;

	if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) )
	{
		if( player->getXMidPos() < getXMidPos() )
			mKeenAlignment = LEFT;
		else
			mKeenAlignment = RIGHT;
		
		
		const int objX = theObject.getXMidPos();
		const int objY = theObject.getYMidPos();
		const int sparkyX = getXMidPos();
		const int sparkyY = getYMidPos();
		
		mGoodChargeChance = false;
		
		if( objX < sparkyX - CSF_DISTANCE_TO_FOLLOW ||
			objX > sparkyX + CSF_DISTANCE_TO_FOLLOW )
			return false;

		if( objY < sparkyY - CSF_DISTANCE_TO_FOLLOW ||
			objY > sparkyY + CSF_DISTANCE_TO_FOLLOW )
			return false;
		
		mGoodChargeChance = true;
	}

	return true;
}
예제 #12
0
void CWormmouth::processMoving()
{
	if( mTurnAround )
	{
		if( xDirection == LEFT )
			xDirection = RIGHT;
		else
			xDirection = LEFT;
		mTurnAround = false;
		setAction( A_WORMMOUTH_LOOK );
	}

	if( mTimer < LOOK_TIMER )
	{
		mTimer++;
		return;
	}
	else
	{
		mTimer = 0;
	}

	if( getProbability(30) )
		setAction( A_WORMMOUTH_LOOK );
}
예제 #13
0
void cHMM::train(std::vector< std::vector<int> > trainingset){

    for(int data=0; data<trainingset.size(); data++){

        std::vector<int> current = trainingset.at(data);
        double** alpha = forwardProc(current);
        double** beta = backwardProc(current);

        /* aggiornamento pi */
        if(isErgodic){

            double P = getProbability(alpha);

            for(int i=0; i<numStati; i++)
                pi[i] = alpha[i][1] * beta[i][1] / P;
        }

        /* aggiornamento A */
        for(int i=0; i<numStati; i++){

            for(int j=0; j<numStati; j++){

                double up = 0;
                double down = 0;

                for(int t=0; t<current.size()-2; t++){

                    up += alpha[i][t] * A[i][j] * B[j][current.at(t+1)] * beta[j][t+1];
                    down += alpha[i][t] * beta[j][t];

                }//t

                A[i][j] = up / down;

            }//j
        }//i

        /* aggiornamento B */
        for(int j=0; j<numStati; j++){

            for(int k=0; k<numOss; k++){

                double up = 0;
                double down = 0;

                for(int t=0; t<current.size()-1; t++){

                    if(current.at(t) == k)
                        up += alpha[j][t] * beta[j][t];

                    down += alpha[j][t] * beta[j][t];
                }//t

                B[j][k] = up / down;
            }//k
        }//j

    }//data
}
예제 #14
0
bool CThunderCloud::isNearby(CSpriteObject &theObject)
{

	if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) )
	{
		const unsigned int cloudX = getXMidPos();
		const unsigned int playXLeft = player->getXMidPos() - DIST_TO_AWAKE;
		const unsigned int playXRight = player->getXMidPos() + DIST_TO_AWAKE;

		if( playXLeft < cloudX &&
				playXRight > cloudX )
		{
			if( getActionStatus(A_CLOUD_ASLEEP) && getProbability(180) )
				setAction(A_CLOUD_WAKING);
		}
		else
		{
			if( !getActionStatus(A_CLOUD_ASLEEP) )
			{
				setAction(A_CLOUD_ASLEEP);
				setActionSprite();
				return true;
			}

		}


		if( getActionStatus(A_CLOUD_WAKING) )
		{
			if( player->getXMidPos() < getXMidPos() )
				xDirection = LEFT;
			else
				xDirection = RIGHT;
		}
		
		if( getActionStatus(A_CLOUD_MOVING) )
		{

		if( mpBolt == nullptr && player->getYMidPos() > getYMidPos() )
		{		    
			const unsigned int playXStrikeLeft = player->getXMidPos() - DIST_TO_STRIKE;
			const unsigned int playXStrikeRight = player->getXMidPos() + DIST_TO_STRIKE;			

			if( playXStrikeLeft < cloudX &&
					playXStrikeRight > cloudX && (mTimer>TIME_TO_STRIKE_2 || (mSecondTry && mTimer>TIME_TO_STRIKE_1) ) )
			{
				mTimer = 0;
				mSecondTry = !mSecondTry;
				setAction(A_CLOUD_STRIKING);
				playSound(SOUND_THUNDERCLOUD_STRIKE);
                mpBolt = new CThunderBolt( mp_Map, getXLeftPos() + (12<<STC), getYDownPos() + (32<<STC), mSprVar );
				spawnObj( mpBolt );
			}
		}
		}
	}

	return true;
}
예제 #15
0
  int RandomNumberGenerator::getIntNumberBetween(int min,
						 int max) {
    double p = getProbability();
    
    int number = (int)(p * (double)(max - min + 1)) + min;

    return number;
  }
예제 #16
0
void CKorath::processSitting()
{
  xDirection = getProbability(500) ? RIGHT : LEFT;  
  
  if(getActionStatus(A_KORATH_WALK))
  {
    setAction(A_KORATH_WALK);
  }
}
bool CMimrock::isNearby(CSpriteObject &theObject)
{
    if(dead || theObject.dead || mTimer > 0 )
        return true;

    if( !blockedd || getActionStatus(A_MIMROCK_JUMP) || getActionStatus(A_MIMROCK_BOUNCE) )
        return true;

    if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) )
    {
        const int dx = player->getXMidPos() - getXMidPos();

        if( dx>-CSF_DISTANCE_TO_FOLLOW_TOLERANCE &&
                dx<+CSF_DISTANCE_TO_FOLLOW_TOLERANCE )
        {
            if( dx<0 )
                xDirection = LEFT;
            else
                xDirection = RIGHT;

            if( !getProbability(40) )
                return true;

            if( dx>-CSF_DISTANCE_TO_JUMP_TOLERANCE &&
                    dx<+CSF_DISTANCE_TO_JUMP_TOLERANCE )
            {
                if( xDirection == -player->xDirection )
                {
                    setAction(A_MIMROCK_SIT);
                }
                else
                {
                    yinertia = -JUMP_HEIGHT;
                    mTimer = JUMP_TIME;

                    setAction(A_MIMROCK_JUMP);
                }
            }
            else
            {
                if( xDirection == player->xDirection && !blockedr && !blockedl )
                {
                    setAction(A_MIMROCK_WALK);
                }
                else
                {
                    setAction(A_MIMROCK_SIT);
                }
            }
        }

    }
    
    return true;
}
예제 #18
0
double HMM::getLikelihood(const mat &SAMPLES)
{
    double L=0.0;
    colvec s(SAMPLES.n_rows);

    // See Eq. (2.0.4) in doc/TechnicalReport.pdf
    for(uint j=0; j<SAMPLES.n_cols; j++) {
        s = SAMPLES.col(j);
        L += log( getProbability( s ) );
    }
    return L;
}
int DynamicPatriciaTriePolicy::getUnigramProbabilityOfPtNode(const int ptNodePos) const {
    if (ptNodePos == NOT_A_DICT_POS) {
        return NOT_A_PROBABILITY;
    }
    DynamicPatriciaTrieNodeReader nodeReader(&mBufferWithExtendableBuffer,
            getBigramsStructurePolicy(), getShortcutsStructurePolicy());
    nodeReader.fetchNodeInfoInBufferFromPtNodePos(ptNodePos);
    if (nodeReader.isDeleted() || nodeReader.isBlacklisted() || nodeReader.isNotAWord()) {
        return NOT_A_PROBABILITY;
    }
    return getProbability(nodeReader.getProbability(), NOT_A_PROBABILITY);
}
예제 #20
0
void CSpirogrip::processMove()
{
  // Move normally in the direction
  moveXDir( xDirection*MOVE_SPEED );
  moveYDir( yDirection*MOVE_SPEED );
  
  if( blockedl )
  {
    xDirection = RIGHT;
    yDirection = CENTER;
    setAction(A_GRIP_BACK_UP_RIGHT);    
  }
  else if( blockedr )
  {
    xDirection = LEFT;
    yDirection = CENTER;
    setAction(A_GRIP_BACK_UP_LEFT);
  }
	
  if( blockedu )
  {
    xDirection = CENTER;
    yDirection = UP;
    setAction(A_GRIP_BACK_UP_UP);
  }
  else if( blockedd )
  {
    xDirection = CENTER;
    yDirection = DOWN;
    setAction(A_GRIP_BACK_UP_DOWN);
  }
  
  mTimer++;
  if( mTimer < TIME_UNTIL_BACKUP )
      return;
  
  mTimer = 0;
  
  if(getProbability(500))
  {            
      if(xDirection == LEFT)
	  setAction(A_GRIP_BACK_UP_LEFT);
      else if(xDirection == RIGHT)
	  setAction(A_GRIP_BACK_UP_RIGHT);
      
      if(yDirection == UP)
	  setAction(A_GRIP_BACK_UP_UP);
      else if(yDirection == DOWN)
	  setAction(A_GRIP_BACK_UP_DOWN);
  }
      
}
예제 #21
0
bool CArachnut::isNearby(CSpriteObject &theObject)
{
	if( !getProbability(10) )
		return false;

	if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) )
	{
        xDirection = ( player->getXMidPos() < getXMidPos() ) ? LEFT : RIGHT;
        yDirection = ( player->getYMidPos() < getYMidPos() ) ? UP : DOWN;
	}

	return true;
}
예제 #22
0
bool CBobba::isNearby(CSpriteObject& theObject)
{
	if( !getProbability(30) )
		return false;

	if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) )
	{
		if( player->getXMidPos() < getXMidPos() )
			xDirection = LEFT;
		else
			xDirection = RIGHT;
	}

	return true;
}
예제 #23
0
//creates an 2 element array of x,y values where nu^2<x<1 and -beta<y<beta, this function calls the MC rejection algorithm (test probability) and then returns the xy pair if they are valid according to the test algorithm
double* XYgenerator::generateXYpair(){
	static double xy[2];
	
	xy[0] = RNG->Uniform(nu*nu,1);
	xy[1] = RNG->Uniform(-getBeta(xy[0]),getBeta(xy[0]));
	
	//if(testProbability(getProbability(xy[0],xy[1]),xy[0],xy[1]))
	//	return xy;
	//else generateXYpair();
	while(!testProbability(getProbability(xy[0],xy[1]),xy[0],xy[1])){
		xy[0] = RNG->Uniform(nu*nu,1);
		xy[1] = RNG->Uniform(-getBeta(xy[0]),getBeta(xy[0]));
	}
	
	return xy;
}
예제 #24
0
void CRoboRed::processMoving()
{
  // Move normally in the direction
  if( xDirection == RIGHT )
  {
    moveRight( moveHorizSpeed );
  }
  else
  {
    moveLeft( moveHorizSpeed );
  }
  
  if(getProbability(60) && mKeenNearby)
  {
    setAction(A_RED_PAUSE);
  }
}
예제 #25
0
bool COrbatrix::isNearby(CSpriteObject &theObject)
{
    if(!getActionStatus(A_ORBATRIX_FLOAT))
	return true;
    
    if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) )
    {	
	if( getProbability(600) )
	{	    
	    if( player->getXMidPos() < getXMidPos() )
		xDirection = LEFT;
	    else
		xDirection = RIGHT;
	}
    }	
	
    return true;
}
예제 #26
0
void ToneMap::initMap()
{
	float sum = 0;
	for (int i = 0; i < num_tones_; i++)
	{
		float val = getProbability(i);
		tonemap_.push_back(val);
	    sum += tonemap_[i];
	    if (i > 0)
	    {
	      tonemap_[i] += tonemap_[i-1];
	    }
	}
	float normalization = 1.0 / sum;
	for (int i = 0; i < num_tones_; i++)
	{
		tonemap_[i] = normalization * tonemap_[i];
	}
}
예제 #27
0
bool CArachnut::isNearby(CSpriteObject &theObject)
{
    if( !getProbability(80) )
        return false;

    if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) )
    {
        if( player->getXMidPos() < getXMidPos() )
            xDirection = LEFT;
        else
            xDirection = RIGHT;

        if( player->getYMidPos() < getYMidPos() )
            yDirection = UP;
        else
            yDirection = DOWN;
    }

    return true;
}
예제 #28
0
bool CLick::isNearby(CSpriteObject &theObject)
{    
    const bool odd = getProbability(80);
    
    
    if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) )
    {
	const int dy = abs(player->getYMidPos() - getYMidPos());
	const int dx = player->getXMidPos() - getXMidPos();
	
	if( dy > CSF_MIN_DISTANCE_TO_BREATHE )
	    return false;
	
	if( dx<-CSF_DISTANCE_TO_FOLLOW_TOLERANCE && odd )
	    xDirection = LEFT;
	else if( dx>+CSF_DISTANCE_TO_FOLLOW_TOLERANCE && odd )
	    xDirection = RIGHT;
	
	if(getActionNumber(A_LICK_LAND))
	{
	    int absdx = (dx<0) ? -dx : dx;
	    
	    if( absdx < CSF_DISTANCE_TO_FOLLOW_TOLERANCE )
		keenNear = true;
	    else
		keenNear = false;
	    
	    
	    if( absdx < CSF_MIN_DISTANCE_TO_BREATHE && odd )
	    {
		setAction(A_LICK_BREATHE);
		playSound(SOUND_LICK_FIREBREATH);
		m_timer = LICK_BREATHE_TIMER;
	    }
	}
	
    }
    
    return true;
}
예제 #29
0
void CPoisonSlug::processCrawling()
{

    if( m_timer < SLUG_MOVE_TIMER )
    {
	m_timer++;
	return;
    }
    else
    {
	m_timer = 0;
    }

	// Chance to poo
	if( getProbability(30) )
	{
		m_timer = 0;
		setAction( A_SLUG_POOING );
		playSound( SOUND_SLUG_DEFECATE );
		CSlugSlime *slime = new CSlugSlime(mp_Map, 0, getXMidPos(), getYDownPos()-(1<<CSF));
		g_pBehaviorEngine->m_EventList.add( new EventSpawnObject( slime ) );
		
		xDirection = -xDirection;
		return;		
	}

	// Move normally in the direction
	if( xDirection == RIGHT )
	{
		moveRight( m_Action.velX<<1 );
	}
	else
	{
		moveLeft( m_Action.velX<<1 );
	}
}
예제 #30
0
void CPoisonSlug::processCrawling()
{

    if( m_timer < SLUG_MOVE_TIMER )
    {
        m_timer++;
        return;
    }
    else
    {
        m_timer = 0;
    }

    // Chance to poo
    if( getProbability(30) )
    {
        m_timer = 0;
        setAction( A_SLUG_POOING );
        playSound( SOUND_SLUG_DEFECATE );
        CSlugSlime *slime = new CSlugSlime(mp_Map, 0, getXMidPos(), getYDownPos()-(1<<(CSF-1)), 0);
        gEventManager.add( new EventSpawnObject( slime ) );

        xDirection = -xDirection;
        return;
    }

    // Move normally in the direction
    if( xDirection == RIGHT )
    {
        moveRight( 2*m_Action.h_anim_move );
    }
    else
    {
        moveLeft( 2*m_Action.h_anim_move );
    }
}