示例#1
0
ChronoDuino::ChronoDuino(QWidget * a_parent)
	: QMainWindow(a_parent)
{
	m_main_window.setupUi(this);

	//UI
	m_result_inspector = new ResultInspector(this);
	setCentralWidget(m_result_inspector);

	m_competitor_inspector = new CompetitorInspector(this);
	addDockWidget(Qt::RightDockWidgetArea, m_competitor_inspector);

	m_round_inspector = new RoundInspector(this);
	addDockWidget(Qt::RightDockWidgetArea, m_round_inspector);

	//Connect
	connect(m_main_window.m_action_new, SIGNAL(triggered()), SLOT(newRaceAction()));
	connect(m_main_window.m_action_open, SIGNAL(triggered()), SLOT(openRaceAction()));
	connect(m_main_window.m_action_preferences, SIGNAL(triggered()), SLOT(editPreferencesAction()));
	connect(m_main_window.m_action_about, SIGNAL(triggered()), SLOT(aboutAction()));
	connect(m_main_window.m_action_print, SIGNAL(triggered()), SLOT(printAction()));
	connect(m_main_window.m_action_test, SIGNAL(triggered()), SLOT(testAction()));

	initDbConnection();
}
示例#2
0
	void StateItem::print() const {
		std::cout << "complete" << std::endl;
		for (int i = 0; i < m_nNextWord; ++i) {
			std::cout << "index : " << i << " head : " << m_lHeads[i] << " label : " << m_lLabels[i] << std::endl;
		}
		if (m_nStackBack >= 0) std::cout << "stack :";
		for (int i = 0; i <= m_nStackBack; ++i) {
			std::cout << " " << m_lStack[i];
		}
		if (m_nStackBack >= 0) std::cout << std::endl;
		std::cout << "last action is ";
		printAction(m_nLastAction);
		std::cout << "score is " << m_nScore << std::endl;
	}
示例#3
0
void ExprSMTLIBLetPrinter::generateOutput() {
  if (p == NULL || query == NULL || o == NULL) {
    std::cerr << "Can't print SMTLIBv2. Output or query bad!" << std::endl;
    return;
  }

  generateBindings();

  if (isHumanReadable())
    printNotice();
  printOptions();
  printSetLogic();
  printArrayDeclarations();
  printLetExpression();
  printAction();
  printExit();
}
示例#4
0
void ExprSMTLIBPrinter::generateOutput() {
  if (p == NULL || query == NULL || o == NULL) {
    std::cerr << "ExprSMTLIBPrinter::generateOutput() Can't print SMTLIBv2. "
                 "Output or query bad!" << std::endl;
    return;
  }

  if (humanReadable)
    printNotice();
  printOptions();
  printSetLogic();
  printArrayDeclarations();
  printConstraints();
  printQuery();
  printAction();
  printExit();
}
示例#5
0
void	toCompare(const std::string& reference, char *entree)
{
  int		i;
  eState	etat = S0;
  eState       	etatTemp;
  int		alphaPos;

  for (i = 0; entree[i]; i++)
    {
      std::cout << "token read " << entree[i] << std::endl;
      alphaPos = reference.find(entree[i]);
      etatTemp = gStateTable[etat][alphaPos];
      std::cout << "etat suivant = " << etatTemp << std::endl;
      if (etatTemp == STATE_ERROR)
	std::cout << "State error" << std::endl;
      else 
	{
	  printAction(gActionTable[etat][alphaPos]);
	  std::cout << "passage a l etat " << etatTemp << std::endl;
	  etat = etatTemp;
	}
    }
}
示例#6
0
文件: dealer.c 项目: jmr/acpc_dealer
/* returns >= 0 if match should continue, -1 on failure */
static int logTransaction( const Game *game, const State *state,
			   const Action *action,
			   const struct timeval *sendTime,
			   const struct timeval *recvTime,
			   FILE *file )
{
  int c, r;
  char line[ MAX_LINE_LEN ];

  c = printAction( game, action, MAX_LINE_LEN, line );
  if( c < 0 ) {

    fprintf( stderr, "ERROR: transaction message too long\n" );
    return -1;
  }

  r = snprintf( &line[ c ], MAX_LINE_LEN - c,
		" %"PRIu32" %zu.%06zu %zu.%06zu\n",
		state->handId, sendTime->tv_sec, sendTime->tv_usec,
		recvTime->tv_sec, recvTime->tv_usec );
  if( r < 0 ) {

    fprintf( stderr, "ERROR: transaction message too long\n" );
    return -1;
  }
  c += r;

  if( fwrite( line, 1, c, file ) != c ) {

    fprintf( stderr, "ERROR: could not write to transaction file\n" );
    return -1;
  }
  fflush( file );

  return c;
}
示例#7
0
int main( int argc, char **argv )
{
  int sock, len, r;
  int32_t min, max;
  uint16_t port;
  Game *game;
  MatchState state;
  Action action;
  struct sockaddr_in addr;
  struct hostent *hostent;
  FILE *file, *toServer, *fromServer;
  char line[ MAX_LINE_LEN ];

  if( argc < 4 ) {

    fprintf( stderr, "usage: player game server port\n" );
    exit( EXIT_FAILURE );
  }

  file = fopen( argv[ 1 ], "r" );
  if( file == NULL ) {

    fprintf( stderr, "ERROR: could not open game %s\n", argv[ 1 ] );
    exit( EXIT_FAILURE );
  }
  game = readGame( file );
  if( game == NULL ) {

    fprintf( stderr, "ERROR: could not read game %s\n", argv[ 1 ] );
    exit( EXIT_FAILURE );
  }
  fclose( file );

  hostent = gethostbyname( argv[ 2 ] );
  if( hostent == NULL ) {

    fprintf( stderr, "ERROR: could not look up address for %s\n", argv[ 2 ] );
    exit( EXIT_FAILURE );
  }

  if( sscanf( argv[ 3 ], "%"SCNu16, &port ) < 1 ) {

    fprintf( stderr, "ERROR: invalid port %s\n", argv[ 3 ] );
    exit( EXIT_FAILURE );
  }

  if( ( sock = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ) {

    fprintf( stderr, "ERROR: could not open socket\n" );
    exit( EXIT_FAILURE );
  }

  addr.sin_family = AF_INET;
  addr.sin_port = htons( port );
  memcpy( &addr.sin_addr, hostent->h_addr_list[ 0 ], hostent->h_length );

  if( connect( sock, (struct sockaddr *)&addr, sizeof( addr ) ) < 0 ) {

    fprintf( stderr, "ERROR: could not open connect to %s:%"PRIu16"\n",
	     argv[ 2 ], port );
    exit( EXIT_FAILURE );
  }

  toServer = fdopen( sock, "w" );
  fromServer = fdopen( sock, "r" );
  if( toServer == NULL || fromServer == NULL ) {

    fprintf( stderr, "ERROR: could not get socket streams\n" );
    exit( EXIT_FAILURE );
  }

  if( fprintf( toServer, "VERSION:%"PRIu32".%"PRIu32".%"PRIu32"\n",
	       VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION ) != 14 ) {

    fprintf( stderr, "ERROR: could not get send version to server\n" );
    exit( EXIT_FAILURE );
  }
  fflush( toServer );

  while( fgets( line, MAX_LINE_LEN, fromServer ) ) {

    /* ignore comments */
    if( line[ 0 ] == '#' || line[ 0 ] == ';' ) {
      continue;
    }

    len = readMatchState( line, game, &state );
    if( len < 0 ) {

      fprintf( stderr, "ERROR: could not read state %s", line );
      exit( EXIT_FAILURE );
    }

    if( stateFinished( &state.state ) ) {
      /* ignore the game over message */

      continue;
    }

    if( currentPlayer( game, &state.state ) != state.viewingPlayer ) {
      /* we're not acting */

      continue;
    }

	int bucket = computeHandValue(game,&state.state,state.viewingPlayer,min,max);
    
	/* add a colon (guaranteed to fit because we read a new-line in fgets) */
    line[ len ] = ':';
    ++len;

    //if( ( random() % 2 ) && raiseIsValid( game, &state.state, &min, &max ) ) {
      /* raise */
    if ((bucket >= 3) && raiseIsValid(game, &state.state, &min, &max)) {  
	  action.type = raise;
      action.size = min + random() % ( max - min + 1 );
    } else if (bucket >=2) {
      /* call */

      action.type = call;
      action.size = 0;
    }
	else{
		action.type = fold;
		action.size = 0;
	}

    if( !isValidAction( game, &state.state, 0, &action ) ) {

      fprintf( stderr, "ERROR: chose an invalid action\n" );
      exit( EXIT_FAILURE );
    }

    r = printAction( game, &action, MAX_LINE_LEN - len - 1,
		     &line[ len ] );
    if( r < 0 ) {

      fprintf( stderr, "ERROR: line too long after printing action\n" );
      exit( EXIT_FAILURE );
    }
    len += r;
    line[ len ] = '\n';
    ++len;

    if( fwrite( line, 1, len, toServer ) != len ) {

      fprintf( stderr, "ERROR: could not get send response to server\n" );
      exit( EXIT_FAILURE );
    }
    fflush( toServer );
  }

  return EXIT_SUCCESS;
}
int main(int argc, char* argv[]) {

    double discountFactor;
    unsigned int maxNbEvaluations;
    char isTerminal = 0;
    char keepingTree = 0;
    int nbTimestep = -1;
    unsigned int branchingFactor = 0;

#ifdef USE_SDL
    char isDisplayed = 1;
    char isFullscreen = 1;
    char verbose = 0;
    char resolution[255] = "640x480";
#else
    char verbose = 1;
#endif

    uniform_instance* instance = NULL;

    state* crtState = NULL;
    state* nextState = NULL;
    double reward = 0.0;
    action* optimalAction = NULL;

    struct arg_dbl* g = arg_dbl1("g", "discountFactor", "<d>", "The discount factor for the problem");
    struct arg_int* n = arg_int1("n", "nbEvaluations", "<n>", "The number of evaluations");
    struct arg_int* s = arg_int0("s", "nbtimestep", "<n>", "The number of timestep");
    struct arg_int* b = arg_int0("b", "branchingFactor", "<n>", "The branching factor of the problem");
    struct arg_lit* k = arg_lit0("k", NULL, "Keep the subtree");
    struct arg_str* i = arg_str0(NULL, "state", "<s>", "The initial state to use");

#ifdef USE_SDL
    struct arg_lit* d = arg_lit0("d", NULL, "Display the viewer");
    struct arg_lit* f = arg_lit0("f", NULL, "Fullscreen");
    struct arg_lit* v = arg_lit0("v", NULL, "Verbose");
    struct arg_str* r = arg_str0(NULL, "resolution", "<s>", "The resolution of the display window");
    void* argtable[11];
    int nbArgs = 10;
#else
    void* argtable[7];
    int nbArgs = 6;
#endif

    struct arg_end* end = arg_end(nbArgs+1);
    int nerrors = 0;

    s->ival[0] = -1;
    b->ival[0] = 0;

    argtable[0] = g; argtable[1] = n; argtable[2] = s; argtable[3] = k; argtable[4] = b; argtable[5] = i;

#ifdef USE_SDL
    argtable[6] = d;
    argtable[7] = f;
    argtable[8] = v;
    argtable[9] = r;
#endif

    argtable[nbArgs] = end;

    if(arg_nullcheck(argtable) != 0) {
        printf("error: insufficient memory\n");
        arg_freetable(argtable, nbArgs+1);
        return EXIT_FAILURE;
    }

    nerrors = arg_parse(argc, argv, argtable);

    if(nerrors > 0) {
        printf("%s:", argv[0]);
        arg_print_syntax(stdout, argtable, "\n");
        arg_print_errors(stdout, end, argv[0]);
        arg_freetable(argtable, nbArgs+1);
        return EXIT_FAILURE;
    }

    discountFactor = g->dval[0];
    maxNbEvaluations = n->ival[0];

    branchingFactor = b->ival[0];

    initGenerativeModelParameters();
    if(branchingFactor)
        K = branchingFactor;
    initGenerativeModel();
    if(i->count)
        crtState = makeState(i->sval[0]);
    else
        crtState = initState();

#if USE_SDL
    isDisplayed = d->count;
    isFullscreen = f->count;
    verbose = v->count;
    if(r->count)
        strcpy(resolution, r->sval[0]);
#endif

    nbTimestep = s->ival[0];
    keepingTree = k->count;

    arg_freetable(argtable, nbArgs+1);

    instance = uniform_initInstance(crtState, discountFactor);

#ifdef USE_SDL
    if(isDisplayed) {
        if(initViewer(resolution, uniform_drawingProcedure, isFullscreen) == -1)
            return EXIT_FAILURE;
        viewer(crtState, NULL, 0.0, instance);
    }
#endif

    do {
        if(keepingTree)
            uniform_keepSubtree(instance);
        else
            uniform_resetInstance(instance, crtState);

        optimalAction = uniform_planning(instance, maxNbEvaluations);

        isTerminal = nextStateReward(crtState, optimalAction, &nextState, &reward);
        freeState(crtState);
        crtState = nextState;

        if(verbose) {
            printState(crtState);
            printAction(optimalAction);
            printf("reward: %f depth: %u\n", reward, uniform_getMaxDepth(instance));
        }

#ifdef USE_SDL
    } while(!isTerminal && (nbTimestep < 0 || --nbTimestep) && !viewer(crtState, optimalAction, reward, instance));
#else
    } while(!isTerminal && (nbTimestep < 0 || --nbTimestep));
void serverStateClass::update()
{
    int tmpNumber;

    sf::Event event;
    while(global::window.pollEvent(event))
    {
        if(event.type == sf::Event::Closed)
        {
            global::run = false;
        }
        else if(event.type == sf::Event::KeyPressed)
        {
            if(event.key.code == sf::Keyboard::Escape)
            {
                global::gameStateStack.set(new mainMenuStateClass);
                return;
            }
        }
    }

    if(server.getGameReady() == false)
    {
        global::gameStateStack.set(new mainMenuStateClass);
        return;
    }

    myWidgetManager.update();

    if(playerReady == true)
    {
        action tmpAction;
        sf::Packet newPacket;
        server.update(&newPacket);
        tmpAction = server.getCurrentAction();
        if(currentAction.action != tmpAction.action || currentAction.player != tmpAction.player)
        {
            currentAction = tmpAction;
            printAction();
        }

        if(newPacket.getDataSize() != 0)
        {
            sendToAll(newPacket);
        }
    }

    waitConnection();

    for(std::list<std::shared_ptr<client>>::iterator ite = listClientMainThread.begin(); ite != listClientMainThread.end(); )
    {
        if((*ite)->isConnected == false)
        {
            if((*ite)->player != NO_PLAYER)
            {
                playerIsReady[(*ite)->player] = false;
                playerReady = false;
                --numberOfPlayer;
            }
            else
            {
                --numberOfSpectator;
            }

            nbPlayer->setMessage(intToStr(numberOfPlayer));
            nbSpec->setMessage(intToStr(numberOfSpectator));
            myWidgetManager.widgetHasChanged();

            selector.remove((*ite)->socket);
            listClientMainThread.erase(ite++);
            continue;
        }
        ++ite;
    }

    tmpNumber = server.getMoveForPlayer();
    if(tmpNumber != numberMoveTotal)
    {
        sf::Packet packet;
        numberMoveTotal = tmpNumber;
        packet << static_cast<sf::Uint8>(SET_MOVE_TOTAL);
        packet << static_cast<sf::Uint8>(numberMoveTotal);
        sendToAll(packet);
    }
    tmpNumber = server.getMoveForNumber();
    if(tmpNumber != numberMoveNumber)
    {
        sf::Packet packet;
        numberMoveNumber = tmpNumber;
        packet << static_cast<sf::Uint8>(SET_MOVE_NUMBER);
        packet << static_cast<sf::Uint8>(numberMoveNumber);
        sendToAll(packet);
    }
}
示例#10
0
文件: main.c 项目: elomage/santa-test
// --------------------------------------------
// --------------------------------------------
void onRadioRecv(void)
{
    static bool flRxProcessing=false;
    if(flRxProcessing){
#ifdef PRINT_PACKETS
        PRINTF("RX Locked\n");
#endif
        return;
    }
    flRxProcessing=true;    // There is a chance for a small race condition

#ifdef PRINT_PACKETS
    uint32_t rxTime = getTimeMs();
#endif
    int16_t rxLen;
    rssi_t rssi;
    lqi_t lqi;

    rxIdx++;
    if( rxIdx < 0 ) rxIdx=0;


    led1Toggle();

    // rxLen = radioRecv( &(DB_REC(db)), DB_REC_SIZE(db));
    // DB_REC(db).recLen = rxLen;
    rxLen = radioRecv(&radioBuffer, sizeof(radioBuffer));
    rssi = radioGetLastRSSI();
    lqi = radioGetLastLQI();

#ifdef PRINT_PACKETS
    PRINTF("%d\t%d\t%d\t%d\t%ld\t", (int)rxIdx, (int)rxLen, (int)rssi, (int)lqi, (long)rxTime);
#endif
#ifdef PRINT_PACKETS
    if (rxLen < 0) {
        PRINTF("RX failed\n");
    }
    else if (rxLen > 0 ) {
        debugHexdump((uint8_t *) &radioBuffer, rxLen);
        // debugHexdump((uint8_t *) &(DB_REC(db)), rxLen);
    }
#endif
    if (rxLen < 0) {
        led2Toggle();
        flRxProcessing=false;
        return;
    }

    if( ! MSG_SIGNATURE_OK(radioBuffer) ) { flRxProcessing = false; return; }

    // Anticipated payload types.
    MSG_NEW_PAYLOAD_PTR(radioBuffer, phaser_ping_t, test_data_p);
    MSG_NEW_PAYLOAD_PTR(radioBuffer, phaser_control_t, ctrl_data_p);
    MSG_NEW_PAYLOAD_PTR(radioBuffer, msg_text_data_t, msg_text_p);
    MSG_NEW_PAYLOAD_PTR(radioBuffer, test_config_t, test_config_p);

    int act = MSG_ACT_CLEAR;
    bool flOK=true;

    switch( radioBuffer.id ){
    case PH_MSG_Test:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, phaser_ping_t, flOK=false );
        if( !flOK ){
            PRINTF("BadChk\n");
            break;
        }
        // Check if new experiment iteration started.
        if(lastExpIdx != test_data_p->expIdx && curExp){
            sendTestResults();
        }
        processTestMsg(test_data_p, rssi, lqi);
        break;
    
    case PH_MSG_Angle:
        if(curExp) sendTestResults();
        if( flRestart ){        // Best time to resend the restart message after the angle change
            send_ctrl_msg(MSG_ACT_RESTART);
            flRestart = false;
        }
        break;

    case PH_MSG_Control:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, phaser_control_t, break);
        if(curExp) sendTestResults();

        act = ctrl_data_p->action;
        if(act == MSG_ACT_START ){
            flRestart = false;  // Clear restart command attempt
        }
        printAction(act);
        break;

    case PH_MSG_Text:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, msg_text_data_t, break );
        PRINTF(msg_text_p->text);
        PRINTF("\n");
        break;

    case PH_MSG_Config:
        MSG_CHECK_FOR_PAYLOAD(radioBuffer, test_config_t, break );
        PRINTF("Config received:\n");
        // TODO: parse the config and print
        print_test_config(test_config_p);
    }


    flRxProcessing=false;
}