//Display information about the current state of the game
void display(int cycle,Agent agents[],Graph g){
    int i = 0;
    printf("Hour %d\n",cycle);
    // function to print the current location of each agent
    printf ("  T  D1  D2  D3  D4\n");
    for (i = 0; i <= NUM_DETECTIVES; i++) {    
	 printf ("%3d", getCurrentLocation(agents[i]));
	 if ( checkInformant ( g, getCurrentLocation(agents[i]) ) ) {
	     printf("*");
	 }
         printf(" ");
    }
    printf ("\n\n");
}
Exemple #2
0
char    *getUsersOfLivedoorClip( const char *url )
{
    Thread  static char users[32];
    Thread  static char saveURL[MAX_URLLENGTH * 8];
    char    apiURL[MAX_URLLENGTH];
    char    *response;
    size_t  sz = MAX_CONTENT_SIZE;

    if ( users[0] && (strcmp( users, "(?)" ) != 0 ) )
        if ( !strncmp( url, saveURL, MAX_URLLENGTH - 1 ) )
            return ( users );
    strcpy( users, "(?)" );

    /* livedoorクリップのブックマーク登録者数を取得 */
    response = (char *)malloc( sz );
    if ( !response )
        return ( users );

    sprintf( apiURL, "http://image.clip.livedoor.com/counter/small/%s",
             encodeURLforHatena( url ) );
    setUpReceiveBuffer( response, sz );
    http_get( apiURL, response );

    if ( *response ) {
        char    *p;
        char    pngURL[MAX_URLLENGTH];

        pngURL[0] = NUL;
        getCurrentLocation( pngURL );
        if ( pngURL[0] ) {
            // pngURL は 登録者数に対応する PNG 画像の URL になる
            //   例: http://image.clip.livedoor.com/img/users/small/00005.png
            p = strrchr( pngURL, '/' );
            if ( p ) {
                p++;
                while ( *p == '0' )
                    p++;
                if ( (*p >= '1') && (*p <= '9') )
                    sprintf( users, "(%d)", atol(p) );
                else if ( *p == '.' )
                    strcpy( users, "(0)" );

                strncpy( saveURL, url, MAX_URLLENGTH - 1 );
                saveURL[MAX_URLLENGTH - 1] = NUL;
            }
        }
    }

    free( response );

    return ( users );
}
Exemple #3
0
char    *getUsersOfECnaviClip( const char *url )
{
    Thread  static char users[32];
    Thread  static char saveURL[MAX_URLLENGTH * 8];
    char    apiURL[MAX_URLLENGTH];
    char    *response;
    size_t  sz = MAX_CONTENT_SIZE;

    if ( users[0] && (strcmp( users, "(?)" ) != 0 ) )
        if ( !strncmp( url, saveURL, MAX_URLLENGTH - 1 ) )
            return ( users );
    strcpy( users, "(?)" );

    /* Buzzurl のブックマーク登録者数を取得 */
    response = (char *)malloc( sz );
    if ( !response )
        return ( users );

    sprintf( apiURL, "http://buzzurl.jp/api/counter/%s",
             encodeURLforHatena( url ) );
    setUpReceiveBuffer( response, sz );
    http_get( apiURL, response );

    if ( *response ) {
        char    *p;
        char    gifURL[MAX_URLLENGTH];

        gifURL[0] = NUL;
        getCurrentLocation( gifURL );
        if ( gifURL[0] ) {
            // gifURL は 登録者数に対応する GIF 画像の URL になる
            //   例: http://buzzurl.jp/static/image/api/number/017.gif
            p = strrchr( gifURL, '/' );
            if ( p ) {
                p++;
                while ( *p == '0' )
                    p++;
                if ( (*p >= '1') && (*p <= '9') )
                    sprintf( users, "(%d)", atol(p) );
                else if ( *p == '.' )
                    strcpy( users, "(0)" );

                strncpy( saveURL, url, MAX_URLLENGTH - 1 );
                saveURL[MAX_URLLENGTH - 1] = NUL;
            }
        }
    }

    free( response );

    return ( users );
}
//check whether the game is over
int checkGameState(Agent agents[],Graph g,int cycle,int maxCycles){
  if(cycle >= maxCycles) {
    printf("GAME OVER: YOU LOSE - TIME IS UP\n");
    return OVER;
  } else {
    Vertex currThiefLoc = getCurrentLocation (agents[THIEF]);
    int i = 1;
    while (i <= NUM_DETECTIVES) {
      if (currThiefLoc == getCurrentLocation (agents[i])) {
	printf("D%d caught the thief in %s (%d)\n", i, getCityName(g, currThiefLoc), currThiefLoc);
	printf("YOU WIN - THIEF CAUGHT!\n");
	return WIN;
      }
      i++;
    }
    if ( currThiefLoc == getGoal (agents[THIEF]) ) {
      printf("T got away to  %s (%d)\n", getCityName(g, currThiefLoc), currThiefLoc);      
      printf("GAME OVER: YOU LOSE - THIEF GOT TO GETAWAY\n");
      return LOSE;
    }
    return CONTINUE;
  }
}
// Smoothly move the observer to the given location
void StelCore::moveObserverTo(const StelLocation& target, double duration, double durationIfPlanetChange)
{
	emit(locationChanged(target));
	double d = (getCurrentLocation().planetName==target.planetName) ? duration : durationIfPlanetChange;
	if (d>0.)
	{
		StelLocation curLoc = getCurrentLocation();
		if (position->isTraveling())
		{
			// Avoid using a temporary location name to create another temporary one (otherwise it looks like loc1 -> loc2 -> loc3 etc..)
			curLoc.name = ".";
		}
		SpaceShipObserver* newObs = new SpaceShipObserver(curLoc, target, d);
		delete position;
		position = newObs;
		newObs->update(0);
	}
	else
	{
		delete position;
		position = new StelObserver(target);
	}
}
void dvmSystemUpdateLocation(){
	getCurrentLocation(gCurOperatingpoint.curLocation.latitude, gCurOperatingpoint.curLocation.longitude);
	//ALOGD("Current Reported Location %f, %f", gCurOperatingpoint.curLocation.latitude, gCurOperatingpoint.curLocation.longitude);
	double curlatitude = gCurOperatingpoint.curLocation.latitude;
	double curlongitude = gCurOperatingpoint.curLocation.longitude;
	// initialize the current location to anywhere
	gCurOperatingpoint.curLocation.locationMask = LOCATION_MASK_ANYWHERE;


	for(DvmConfigLocationMapIter it = dvmConfigFileGetMapLocationAddress()->begin(); it!=dvmConfigFileGetMapLocationAddress()->end(); ++it){
		//ALOGD("ClassID:%d MethodID:%d ==> tag:%d, priority:%d, powerindex:%d, tempindex:%d, voltindex:%d ",it->first.first, it->first.second, it->second.tag, it->second.priority, it->second.ids.first, it->second.ids.second, it->second.ids.third);
		if(locationEquals(curlatitude, it->second.first) && locationEquals(curlongitude, it->second.second)){
			gCurOperatingpoint.curLocation.locationMask = it->first;
		}
	}
}
void StelCore::moveObserverToSelected()
{
	StelObjectMgr* objmgr = GETSTELMODULE(StelObjectMgr);
	Q_ASSERT(objmgr);
	if (objmgr->getWasSelected())
	{
		Planet* pl = dynamic_cast<Planet*>(objmgr->getSelectedObject()[0].data());
		if (pl)
		{
			// We need to move to the selected planet. Try to generate a location from the current one
			StelLocation loc = getCurrentLocation();
			if (loc.planetName != pl->getEnglishName())
			{
				loc.planetName = pl->getEnglishName();
				loc.name = "-";
				loc.state = "";
				moveObserverTo(loc);

				LandscapeMgr* landscapeMgr = GETSTELMODULE(LandscapeMgr);
				if (pl->getEnglishName() == "Solar System Observer")
				{
					landscapeMgr->setFlagAtmosphere(false);
					landscapeMgr->setFlagFog(false);
					landscapeMgr->setFlagLandscape(false);
				}
				else
				{
					landscapeMgr->setFlagAtmosphere(pl->hasAtmosphere());
					landscapeMgr->setFlagFog(pl->hasAtmosphere());
					landscapeMgr->setFlagLandscape(true);
				}
			}
		}
	}
	StelMovementMgr* mmgr = GETSTELMODULE(StelMovementMgr);
	Q_ASSERT(mmgr);
	mmgr->setFlagTracking(false);
}
//step through one cycle of the game
int step(int cycle,Agent agents[],Graph g,int maxCycles){
    
    int i;
    cycle++;
    
    for(i=0;i<=NUM_DETECTIVES;i++){
      if(i == THIEF) {
        //location of thief stored in graph
        setThiefLocation(g, getCurrentLocation(agents[i]));
      }

       Edge  nextMove = getNextMove(agents[i],g);  
       makeNextMove(g, agents[i], nextMove);
     
    }
    display(cycle,agents,g);
    int gameState = checkGameState(agents,g,cycle,maxCycles);
    if(gameState == CONTINUE){
        return cycle;
    } else {
        return gameState;
    }
}
Exemple #9
0
Token DefaultLexer::readToken() {
  char c = lookChar();

  while (true) {
    // skip whitespace
    while (isWhiteSpace(c)) {
      skipChar();
      c = lookChar();
    }

    // newlines
    if (isNewline(c)) {
      readNewline(c);
      if (interactive_ && getCurrentBraceNesting() == 0)
        return Token(TK_Newline);
      c = lookChar();
      continue;
    }

    // treat line comments as newlines
    if (c == '/' && lookChar(1) == '/') {
      readLineComment();
      c = lookChar();
      continue;
    }
    break;
  }

  SourceLocation sloc = getCurrentLocation();

  // punctuation
  if (c == '(') {
    skipChar();
    signalOpenBrace(TK_LParen);
    return Token(TK_LParen, "(", sloc);
  }
  if (c == ')') {
    skipChar();
    signalCloseBrace(TK_LParen);
    return Token(TK_RParen, ")", sloc);
  }
  if (c == '{') {
    skipChar();
    signalOpenBrace(TK_LCurlyBrace);
    return Token(TK_LCurlyBrace, "{", sloc);
  }
  if (c == '}') {
    skipChar();
    signalCloseBrace(TK_LCurlyBrace);
    return Token(TK_RCurlyBrace, "}", sloc);
  }
  if (c == '[') {
    skipChar();
    signalOpenBrace(TK_LSquareBrace);
    return Token(TK_LSquareBrace, "[", sloc);
  }
  if (c == ']') {
    skipChar();
    signalCloseBrace(TK_LSquareBrace);
    return Token(TK_RSquareBrace, "]", sloc);
  }
  if (c == ',') {
    skipChar();
    return Token(TK_Comma, ",", sloc);
  }
  if (c == ';') {
    skipChar();
    return Token(TK_Semicolon, ";", sloc);
  }
  if (c == ':' && !isOperatorChar(lookChar(1))) {
    skipChar();
    return Token(TK_Colon, ":", sloc);
  }
  if (c == '.') {
    skipChar();
    return Token(TK_Period, ".", sloc);
  }

  // identifiers
  if (isLetter(c)) {
    readIdentifier(c);
    StringRef str = copyStr(finishToken());

    unsigned keyid = lookupKeyword(str.c_str());
    if (keyid) {
      return Token(keyid, str, sloc);
    }
    return Token(TK_Identifier, str, sloc);
  }

  // generic operators
  if (isOperatorChar(c)) {
    readOperator(c);
    StringRef str = copyStr(finishToken());

    unsigned keyid = lookupKeyword(str.c_str());
    if (keyid) {
      return Token(keyid, str, sloc);
    }
    return Token(TK_Operator, str, sloc);
  }

  // numbers
  if (isDigit(c)) {
    readInteger(c);
    StringRef str = copyStr(finishToken());
    return Token(TK_LitInteger, str, sloc);
  }

  // characters
  if (c == '\'') {
    if (!readCharacter())
      return Token(TK_Error);

    StringRef str = copyStr(finishToken());
    return Token(TK_LitCharacter, str, sloc);
  }

  // strings
  if (c == '\"') {
    if (!readString())
      return Token(TK_Error);

    StringRef str = copyStr(finishToken());
    return Token(TK_LitString, str, sloc);
  }

  // if we're out of buffer, put in an EOF token.
  if (c == 0 || stream_eof()) {
    return Token(TK_EOF, "", sloc);
  }

  // Can't get the next token -- signal an error and bail.
  signalLexicalError();
  return Token(TK_Error, "", sloc);
}
Exemple #10
0
void read_data_bluetooth(float* _x, float* _y)
{
	t_location pos=getCurrentLocation();
    *_x = pos.x;
	*_y = pos.y;
}
Exemple #11
0
int
loginCocologFiles( const char *username,    // (I) ユーザ名
                   const char *password,    // (I) パスワード
                   char       *cookie )     // (O) クッキー
{
    int     ret = 0;
    char    *p;
    char    *request;
    char    *response;
    char    url[MAX_URLLENGTH_MAX];
    char    realm[MAX_KEYLENGTH * 2];
    char    digest[BUFSIZ];
    size_t  sz = MAX_CONTENT_SIZE;

    if ( !cookie )
         return ( ret );

    if ( !username )
        username = xmlrpc_p->userName;
    if ( !password )
        password = xmlrpc_p->password;

    request  = (char *)malloc( MAX_CONTENT_SIZE );
    if ( !request ) 
        return ( ret );
    response = (char *)malloc( sz );
    if ( !response ) {
        free( request );
        return ( ret );
    }
    memset( request, 0x00, MAX_CONTENT_SIZE );

    strcpy( url, 
            xmlrpc_p->blogKind == BLOGKIND_COCOLOGFREE
                ? COCOLOGFREE_APP
                : COCOLOG_APP );
    setUpReceiveBuffer( response, sz );
    http_getEx( url, response, cookie );
    if ( *response )
        getCurrentLocation( url );

    realm[0] = NUL;
    getRealm( request, response, sz, cookie, realm );
    if ( realm[0] ) {
        sprintf( digest, "%s:%s:%s", username, realm, password );
        p = MD5( digest );
        if ( p ) {
            strcpy( digest, p );
            sprintf( request,
                     "username=%s&"
                     "digest=%s&"
                     "remember=1&"
                     "submit=%s",
                     username,
                     digest,
                     encodeURL(sjis2utf("ログイン")) );
            setUpReceiveBuffer( response, sz );
            http_postEx( url,
                         "application/x-www-form-urlencoded",
                         request, response, cookie );
            if ( *cookie && strstr( cookie, "SSOID=" ) )
                ret = 1;    /* ログイン成功 */
            else {
                ret = 0;    /* ログイン失敗 */
                if ( xmlrpc_p->verbose )
                    dputs( "loginCocologFiles: login失敗\n" );
            }
        }
    }

    encodeURL( NULL );
    free( response );
    free( request  );

    return ( ret );
}