Exemple #1
0
void InterruptHandler( void )
{
  BYTE bTmp;
  if ( INTCONbits.INT0IF ) {
    // devo rever se é isso mesmo....
    // realiza a leitura do modem
    bTmp = getcUART( );

    ProcessaProtocolo( bTmp );

    INTCONbits.INT0IF = 0;
  }
  
  if ( PIR1bits.TMR2IF )
	{
		IncTickCount( );
		PIR1bits.TMR2IF = 0;
	}

	while ( PIR1bits.RCIF ) {
  	
  	if ( RCSTAbits.FERR ) {
    	//RCSTAbits.FERR = 0;
    	SerialGetchar();
    	break;
    }

    if ( RCSTAbits.OERR ) {
    	//RCSTAbits.OERR = 0;
    	RCSTAbits.CREN ^= 1;
    	Nop();
      RCSTAbits.CREN ^= 1;    	
    	break;
    }
    
  	if ( isrSerialFunc ){
      bTmp = SerialGetchar();
      (*isrSerialFunc)( bTmp ); 
    }  	
  }
}
Exemple #2
0
void Arena::Simulate()
{
    double tAngle;
    int mX;
    int mY;
    int movement;

    do
    {
        m1 = GetMemberOne();
        m2 = GetMemberTwo();
        Coord c1 = m1->GetCoord();
        Coord c2 = m2->GetCoord();

        FillIXArray(m1,m2,this);
        FillIXArray(m2,m1,this);

        double score1 =0;

        Action act1 = m1->GetAction(this);
      //  Action act2 = m2->GetAction(ar);

        if (act1.ActionCode==_ACTION_TURN)
        {
            if (abs(act1.ActionRate)<=GetMaxAngle())
                movement = act1.ActionRate;
            else
                movement = (GetMaxAngle()*sign(act1.ActionRate));
            c1.Angle+=movement;
            if (c1.Angle<0)
                c1.Angle+=360;
            if (c1.Angle>=360)
                c1.Angle-=360;
            m1->SetCoord(c1);
            score1+=0.0002;
        }
        else if (act1.ActionCode==_ACTION_MOVE)
        {
            if (abs(act1.ActionRate)<=GetMaxMove())
                movement = act1.ActionRate;
            else
                movement = GetMaxMove()*sign(act1.ActionRate);
            tAngle = c1.Angle*_180_DIV_PI;
            mX = floor(cos(tAngle)*movement);
            mY = floor(sin(tAngle)*movement);
            c1.X+=mX;
            c1.Y-=mY;
            if (c1.X<1)
                c1.X=1;
            if (c1.Y<1)
                c1.Y=1;
            if (c1.X>(GetArenaSizeX()-1))
                c1.X=GetArenaSizeX()-1;
            if (c1.Y>(GetArenaSizeY()-1))
                c1.Y=GetArenaSizeY()-1;
            m1->SetCoord(c1);
            score1+=0.0002;
        }
        else if (act1.ActionCode==_ACTION_HALT)
        {//do nothing
        }

        SetScoreOne(GetScoreOne()+score1);
        ////ОЧКИ ЗА АКТИВНОСТЬ НА АРЕНЕ


    /*      if (act2.ActionCode==_ACTION_TURN)
        {
            if (abs(act2.ActionRate)<=GetMaxAngle())
                movement = act2.ActionRate;
            else
                movement = (GetMaxAngle()*sign(act2.ActionRate));
            c2.Angle+=movement;
            if (c2.Angle<0)
                c2.Angle+=360;
            if (c2.Angle>=360)
                c2.Angle-=360;
            m2->SetCoord(c2);
            score2+=0.0002;
        }
        else if (act2.ActionCode==_ACTION_MOVE)
        {
            if (abs(act2.ActionRate)<=GetMaxMove())
                movement = act2.ActionRate;
            else
                movement = GetMaxMove()*sign(act2.ActionRate);

            tAngle= c2.Angle*_180_DIV_PI;
            mX = trunc(cos(tAngle)*movement);
            mY = trunc(sin(tAngle)*movement);
            c2.X+=mX;
            c2.Y-=mY;
            if (c2.X<1)
                c2.X=1;
            if (c2.Y<1)
                c2.Y=1;
            if (c2.X>(GetArenaSizeX()-1))
                c2.X=GetArenaSizeX()-1;
            if (c2.Y>(GetArenaSizeY()-1))
                c2.Y=GetArenaSizeY()-1;
            m2->SetCoord(c2);
        }
        else if (act2.ActionCode==_ACTION_HALT)
        {//do nothing
        }
    */
        SetMemberOne(m1);
        SetMemberTwo(m2);

        //посчитаем очки
        double distance = hypot((c1.X-c2.X),(c1.Y-c2.Y));
        score1 = 1/distance;
        double score2 = score1; //пока так
        SetScoreOne(GetScoreOne()+score1);
        SetScoreTwo(GetScoreTwo()+score2);
        IncTickCount();
    }
    while (GetBattleTime()<_BATTLE_TIME);

    p->members[counter-1]->SetFitness(trunc(GetScoreOne()*10000));
//    cout<<counter-1<<endl;
//    cout<<"Fitness = "<<p->members[counter-1]->GetFitness()<<endl;
//    cout<<"DNA usage(%) = "<<(int)((m1->GetDNAUsage()*100)/_DNASIZE)<<endl;

}