int _tmain(int argc, _TCHAR* argv[])
{
    asio::io_service ios;

    ip::tcp::socket soc(ios);
    soc.async_connect(ip::tcp::endpoint(ip::address::from_string("127.0.0.1"), 31400),
                      connect_handle);

	for (;;)
	{
		ios.run();
	//	ios.poll();
	//	soc.close();
		Sleep(10);
	}

	return 0;
}
Пример #2
0
/*!This method is the first complete simple team and defines the actions taken
   by all the players on the field (excluding the goalie). It is based on the
   high-level actions taken by the simple team FC Portugal that it released in
   2000. The players do the following:
   - if ball is kickable
       kick ball to goal (random corner of goal)
   - else if i am fastest player to ball 
       intercept the ball
   - else
       move to strategic position based on your home position and pos ball */
SoccerCommand Player::deMeer5(  )
{

  SoccerCommand soc(CMD_ILLEGAL);
  VecPosition   posAgent = WM->getAgentGlobalPosition();
  VecPosition   posBall  = WM->getBallPos();
  int           iTmp;
  
  if( WM->isBeforeKickOff( ) )
  {
    if( WM->isKickOffUs( ) && WM->getPlayerNumber() == 9 ) // 9 takes kick
    {
      if( WM->isBallKickable() )
      {
        VecPosition posGoal( PITCH_LENGTH/2.0,
                             (-1 + 2*(WM->getCurrentCycle()%2)) * 
                             0.4 * SS->getGoalWidth() );
        soc = kickTo( posGoal, SS->getBallSpeedMax() ); // kick maximal
        Log.log( 100, "take kick off" );        
      }
      else
      {
        soc = intercept( false );
        Log.log( 100, "move to ball to take kick-off" );
      }  
      ACT->putCommandInQueue( soc );
      ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
      return soc;
    }  
    if( formations->getFormation() != FT_INITIAL || // not in kickoff formation
        posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 )  
    {
      formations->setFormation( FT_INITIAL );       // go to kick_off formation
      ACT->putCommandInQueue( soc=teleportToPos( WM->getStrategicPosition() ));
    }
    else                                            // else turn to center
    {
      ACT->putCommandInQueue( soc=turnBodyToPoint( VecPosition( 0, 0 ), 0 ) );
      ACT->putCommandInQueue( alignNeckWithBody( ) );
    }
  }
  else
  {
    formations->setFormation( FT_433_OFFENSIVE );
    soc.commandType = CMD_ILLEGAL;
    if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() )
    {
      ACT->putCommandInQueue( soc = searchBall() );   // if ball pos unknown
      ACT->putCommandInQueue( alignNeckWithBody( ) ); // search for it
    }
    else if( WM->isBallKickable())                    // if kickable
    {
		
		VecPosition posGoal( PITCH_LENGTH/2.0,
							(-1 + 2*(WM->getCurrentCycle()%2)) * 0.4 * SS->getGoalWidth() );
			
		soc = kickTo( posGoal, SS->getBallSpeedMax() ); // kick maxima
		
      ACT->putCommandInQueue( soc );
      ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
      Log.log( 100, "kick ball" );
    }
    else if( WM->getFastestInSetTo( OBJECT_SET_TEAMMATES, OBJECT_BALL, &iTmp )
              == WM->getAgentObjectType()  && !WM->isDeadBallThem() )
    {                                                // if fastest to ball
      Log.log( 100, "I am fastest to ball; can get there in %d cycles", iTmp );
      soc = intercept( false );                      // intercept the ball

      if( soc.commandType == CMD_DASH &&             // if stamina low
          WM->getAgentStamina().getStamina() <
             SS->getRecoverDecThr()*SS->getStaminaMax()+200 )
      {
        soc.dPower = 30.0 * WM->getAgentStamina().getRecovery(); // dash slow
        ACT->putCommandInQueue( soc );
        ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
      }
      else                                           // if stamina high
      {
        ACT->putCommandInQueue( soc );               // dash as intended
        ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
      }
     }
     else if( posAgent.getDistanceTo(WM->getStrategicPosition()) >
                  1.5 + fabs(posAgent.getX()-posBall.getX())/10.0)
                                                  // if not near strategic pos
     {
       if( WM->getAgentStamina().getStamina() >     // if stamina high
                            SS->getRecoverDecThr()*SS->getStaminaMax()+800 )
       {
         soc = moveToPos(WM->getStrategicPosition(),
                         PS->getPlayerWhenToTurnAngle());
         ACT->putCommandInQueue( soc );            // move to strategic pos
         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
       }
       else                                        // else watch ball
       {
         ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
       }
     }
     else if( fabs( WM->getRelativeAngle( OBJECT_BALL ) ) > 1.0 ) // watch ball
     {
       ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
     }
     else                                         // nothing to do
       ACT->putCommandInQueue( SoccerCommand(CMD_TURNNECK,0.0) );
   }
  return soc;
}
/******************************************************************************
* Class AccountPage :: command - Catch and process command events.            *
******************************************************************************/
bool AccountPage::command( ICommandEvent& cmdEvent )
{
   IString
      theUser = userId.text(),
      theNode = nodeSys.text();
   LAcctData::Rule
      theRule = LAcctData::na;
   bool
      rc = false;
   unsigned int
      count = 0;

/*-----------------------------------------------------------------------------
| Create a container object cursor based on the selected objects.             |
| Process the command events.                                                 |
-----------------------------------------------------------------------------*/
   IContainerControl::ObjectCursor
      soc( *pCnr, IContainerObject::selected );

   switch ( cmdEvent.commandId() )
   {
/*-----------------------------------------------------------------------------
| User pressed the UNDO button.                                               |
| Reset the account data to the original account data.                        |
| Reset the container.                                                        |
| Reset the entryfields.                                                      |
-----------------------------------------------------------------------------*/
      case ID_BUTTON_UNDO:
      {
         acctData = origAcctData;
         fillCnr();
         userId.setText( "" );
         nodeSys.setText( "" );
         rc = true;
         break;
      }

/*-----------------------------------------------------------------------------
| User pressed the REMOVE button.                                             |
| Iterate through the selected objects,                                       |
|  remove the object from the the database.                                   |
-----------------------------------------------------------------------------*/
      case ID_BUTTON_REMOVE:
      {
         for ( soc.setToFirst();
               soc.isValid();
               soc.setToNext() )
         {
            AcctCnrObj
               *pObj = (AcctCnrObj *) soc.current();
            acctData.putItem( pObj->getUserId(),
                              pObj->getNode(),
                              LAcctData::remove );
            ++count;
         }

/*-----------------------------------------------------------------------------
| If no container objects were selected,                                      |
|  notify the user.                                                           |
-----------------------------------------------------------------------------*/
         if ( ! count )
         {
            IMessageBox
               warning( owner() );
            warning.show( STR_MSG_REMOVE,
                          IMessageBox::enterButton
                          | IMessageBox::informationIcon );
         }
/*-----------------------------------------------------------------------------
| Else remove the selected objects from the container.                        |
| Refresh the container.                                                      |
-----------------------------------------------------------------------------*/
         else
         {
            pCnr->removeSelectedObjects();
            userId.setText( "" );
            nodeSys.setText( "" );
            pCnr->refresh();
         }
         rc = true;
         break;
      }

/*-----------------------------------------------------------------------------
| User pressed the CHANGE button.                                             |
| Ignore all but the first selected container object.                         |
| Update the entryfields with the selected container object information.      |
-----------------------------------------------------------------------------*/
      case ID_BUTTON_CHANGE:
      {
         soc.setToFirst();
         if ( soc.isValid() )
         {
            if ( theUser.length() )
            {
               changeAcct( theUser, theNode, (AcctCnrObj*) soc.current() );
               userId.setText( "" );
               nodeSys.setText( "" );
            }

         }
/*-----------------------------------------------------------------------------
| If no container objects were selected,                                      |
|  notify the user.                                                           |
-----------------------------------------------------------------------------*/
         else
         {
            IMessageBox
               warning( owner() );
            warning.show( STR_MSG_CHANGE,
                          IMessageBox::enterButton
                          | IMessageBox::informationIcon );
         }

/*-----------------------------------------------------------------------------
| Deselect any container objects.                                             |
-----------------------------------------------------------------------------*/
         unMark();
         rc = true;
         break;
      }

/*-----------------------------------------------------------------------------
| User pressed the ADD button.                                                |
| Add the entryfield information to the database and container.               |
| Reset the entryfields.                                                      |
-----------------------------------------------------------------------------*/
      case ID_BUTTON_ADD:
      {
         if ( theUser.length() )
         {
            addAcct( theUser, theNode );
            userId.setText( "" );
            nodeSys.setText( "" );
         }

/*-----------------------------------------------------------------------------
| Deselect any container objects.                                             |
-----------------------------------------------------------------------------*/
         unMark();
         rc = true;
         break;
      }

/*-----------------------------------------------------------------------------
| User pressed the HELP button.                                               |
| Show the help for the account page.                                         |
-----------------------------------------------------------------------------*/
      case ID_BUTTON_HELP:
      {
         IHelpWindow::helpWindow( this )->
            show( IResourceId( ID_ACCOUNT_PAGE ) );
         rc = true;
         break;
      }

   }

   return rc;
};
Пример #4
0
void chol_inv(double a1_re[][4],double a1_im[][4],double b1_re[][4],double b1_im[][4])
{
	//初始化
	double d[4]={0}, L_re[4][4]={0};
	double L_im[4][4]={0},d_i[4]={0},L_i_re[4][4]={0},L_i_im[4][4]={0},L_i_re2[4][4]={0},L_i_im2[4][4]={0},D_i_re[4][4]={0},D_i_im[4][4]={0};
	double c_re[4][4]={0},c_im[4][4]={0};
	double *p_re,*p_im,temp_re,temp_im;
	int i,j;
	p_re=&temp_re;
	p_im=&temp_im;
	for(i=0;i<4;i++)
	{
		L_re[i][i]=1;
		L_i_re[i][i]=1;
	}
	
	//cholesky decomposition,Solution of d and L and d_i
	d[0]=a1_re[0][0];
	d_i[0]=1/d[0];
	L_re[1][0]=a1_re[1][0]/d[0];
	L_im[1][0]=a1_im[1][0]/d[0];
	L_re[2][0]=a1_re[2][0]/d[0];
	L_im[2][0]=a1_im[2][0]/d[0];
	L_re[3][0]=a1_re[3][0]/d[0];
	L_im[3][0]=a1_im[3][0]/d[0];

	d[1]=a1_re[1][1]-d[0]*soc(L_re[1][0],L_im[1][0]);
	d_i[1]=1/d[1];
	mult(L_re[2][0],L_im[2][0],L_re[1][0],-L_im[1][0],p_re,p_im);
	L_re[2][1]=(a1_re[2][1]-d[0]*temp_re)/d[1];
	L_im[2][1]=(a1_im[2][1]-d[0]*temp_im)/d[1];
	mult(L_re[3][0],L_im[3][0],L_re[1][0],-L_im[1][0],p_re,p_im);
	L_re[3][1]=(a1_re[3][1]-d[0]*temp_re)/d[1];
	L_im[3][1]=(a1_im[3][1]-d[0]*temp_im)/d[1];

	d[2]=a1_re[2][2]-d[0]*soc(L_re[2][0],L_im[2][0])-d[1]*soc(L_re[2][1],L_im[2][1]);
	d_i[2]=1/d[2];
	mult(L_re[3][0],L_im[3][0],L_re[2][0],-L_im[2][0],p_re,p_im);
	L_re[3][2]=a1_re[3][2]-d[0]*temp_re;
	L_im[3][2]=a1_im[3][2]-d[0]*temp_im;
	mult(L_re[3][1],L_im[3][1],L_re[2][1],-L_im[2][1],p_re,p_im);
	L_re[3][2]=(L_re[3][2]-d[1]*temp_re)/d[2];
	L_im[3][2]=(L_im[3][2]-d[1]*temp_im)/d[2];

	d[3]=a1_re[3][3]-d[0]*soc(L_re[3][0],L_im[3][0])-d[1]*soc(L_re[3][1],L_im[3][1])-d[2]*soc(L_re[3][2],L_im[3][2]);
	d_i[3]=1/d[3];
	


	//L_i
	L_i_re[1][0]=-L_re[1][0];
	L_i_im[1][0]=-L_im[1][0];

	mult(L_re[2][1],L_im[2][1],L_i_re[1][0],L_i_im[1][0],p_re,p_im);
	L_i_re[2][0]=-(temp_re+L_re[2][0]);
	L_i_im[2][0]=-(temp_im+L_im[2][0]);

	mult(L_re[3][1],L_im[3][1],L_i_re[1][0],L_i_im[1][0],p_re,p_im);
	L_i_re[3][0]=L_re[3][0]+temp_re;
	L_i_im[3][0]=L_im[3][0]+temp_im;
	mult(L_re[3][2],L_im[3][2],L_i_re[2][0],L_i_im[2][0],p_re,p_im);
	L_i_re[3][0]=-(L_i_re[3][0]+temp_re);
	L_i_im[3][0]=-(L_i_im[3][0]+temp_im);
	
	L_i_re[2][1]=-L_re[2][1];
	L_i_im[2][1]=-L_im[2][1];

	mult(L_re[3][2],L_im[3][2],L_i_re[2][1],L_i_im[2][1],p_re,p_im);
	L_i_re[3][1]=-(temp_re+L_re[3][1]);
	L_i_im[3][1]=-(temp_im+L_im[3][1]);

	L_i_re[3][2]=-L_re[3][2];
	L_i_im[3][2]=-L_im[3][2];

	//D_i
	for(i=0;i<4;i++)
	{
		D_i_re[i][i]=d_i[i];
	}
	//(L_i)'
	for(i=0;i<4;i++)
	{
		for(j=0;j<4;j++)
		{
			L_i_re2[i][j]=L_i_re[j][i];
			L_i_im2[i][j]=-L_i_im[j][i];
		}
	}
	//inverse matrix:(L_i)'*D_i*L_i
    Matrix_mult444(L_i_re2,L_i_im2,D_i_re,D_i_im,c_re,c_im);
    Matrix_mult444(c_re,c_im,L_i_re,L_i_im,b1_re,b1_im);
/*
    FILE *fp1,*fp2;
    fp1 = fopen("data.txt","w");
    for( int i = 0 ; i < 4 ; i++){
        for( int j = 0 ; j < 4 ; j++ ){
            fprintf(fp1,"%lf\t",b1_re[i][j]);
        }fprintf(fp1,"\n");
    }

    for( int i = 0 ; i < 4 ; i++){
        for( int j = 0 ; j < 4 ; j++ ){
            fprintf(fp1,"%lf\t",b1_im[i][j]);
        }fprintf(fp1,"\n");
    }
    fclose(fp1);
    */
}