示例#1
0
static void generateBatter( const player_s *player, const int season, fileplayer_s *players_file )
{
     batter_s      *batter  = player->details.batting;
     filebatting_s *batting = &(players_file->filestats.filebatting);

     filehand_e     hand      = mapHandedness( player->handedness );
     fileposition_e primary   = mapPosition( batter->primary_position   );
     fileposition_e secondary = mapPosition( batter->secondary_position );

     int arm       = adjustRating( batter->arm,       season, player );
     int running   = adjustRating( batter->running,   season, player );
     int range     = adjustRating( batter->range,     season, player );
     int power     = adjustRating( batter->power,     season, player );
     int bunt      = adjustRating( batter->bunt,      season, player );
     int hit_n_run = adjustRating( batter->hit_n_run, season, player );

     players_file->position[0] = (primary << 4) + secondary;

     batting->ratings[0] = (hand    << 4) +         arm;
     batting->ratings[1] = (running << 4) +         range;
     batting->ratings[2] = (power   << 4) + player->longevity;
     batting->ratings[3] = (bunt    << 4) +         hit_n_run;

     if   ( player->skin_tone == st_Dark ) int2byte( batting->color, fc_Dark  );
     else                                  int2byte( batting->color, fc_Light );

     int games = (rand() % 25) + 120;
     int ab    = (int)round( (double)games * ab_per_game );
     int po    = (int)round( (double)games * ((double)getValueForTwo( put_outs, primary, range ) / 100.0) );
     int as    = (int)round( (double)games * ((double)getValueForTwo( assists, primary, arm ) / 100.0) );
     int ba    = getValueForTwo( batting_avg, power, hit_n_run );
     int soa   = getValueForOne( strikeout_avg, hit_n_run );
     int fa    = getValueForTwo( fielding_avg, range, arm ) + 9000;
     int fa2   = roll( 9500, fa - 9500 );
     int hits  = (int)round( (double)ab * (double)ba  / 1000.0 );
     int so    = (int)round( (double)ab * (double)soa / 1000.0 );
     int err   = (int)round( (double)(po + as) / (double)fa * 10000.0 ) - (po + as);

     if ( err < 0 ) err = 0;

     hits += getValueForOne( extra_hits, running );

     int2word( players_file->real_avg, ba );

     int2byte( batting->real_games, games );
     int2byte( batting->real_sb,    getValueForOne( steals, running ) );
     int2word( batting->vl_ab,      ab   );
     int2word( batting->vl_hits,    hits );
     int2byte( batting->vl_2b,      getValueForOne( doubles, power ) );
     int2byte( batting->vl_3b,      getValueForTwo( triples, power, running ) );
     int2byte( batting->vl_hr,      getValueForOne( home_runs, power ) );
     int2byte( batting->vl_bb,      getValueForOne( walks, hit_n_run ) );
     int2byte( batting->vl_so,      so );
     int2byte( batting->real_runs,  batting->vl_hr[0] + getValueForOne( runs, running ) );
     int2byte( batting->real_rbi,   batting->vl_hr[0] + getValueForOne( rbi, power ) );
     int2word( batting->real_po,    po   );
     int2word( batting->real_as,    as   );
     int2byte( batting->real_err,   err );
     int2byte( batting->real_fa2,   (int)round( (10000.0 - (double)fa2) / 10.0 ) );
}
示例#2
0
bool WorldHandler::worldCollideY(Math::Vector2D &position, Math::Vector2D &scene, float &v){
    float yCheck = yCheck = position.y + SPRITE_SIZE/2;;
    bool up = false, down = false;
    if(v > 0){
        //if it's going down
        down = true;
        yCheck = position.y + v + SPRITE_SIZE;
    }
    if (v < 0){
        //if it's going up
        up = true;
        yCheck = position.y + v;
    }
    Math::Vector2D gridPosition = Math::Vector2D((int)(position.x+SPRITE_SIZE/2)/SPRITE_SIZE, (int)yCheck/SPRITE_SIZE);
    Math::Vector2D mapPosition(gridPosition.x + scene.x*(windowWidth/SPRITE_SIZE), gridPosition.y + scene.y*(windowHeight/SPRITE_SIZE));
    
    //if it's going off the map
    if(mapPosition.x < 0 || mapPosition.y < 0 || mapPosition.x > xMapSize || mapPosition.y > xMapSize){
        return true;
    }
    if(map[mapPosition.x + mapPosition.y*xMapSize]->solid){
        if(up){
            position.y = (gridPosition.y+1)*SPRITE_SIZE;
        }
        if(down){
            position.y = (gridPosition.y-1)*SPRITE_SIZE;
        }
        return true;
    }
    return false;
}
示例#3
0
bool WorldHandler::worldCollideX(Math::Vector2D &position, Math::Vector2D &scene, float &v){
    float xCheck = position.x + SPRITE_SIZE/2;
    bool right = false, left = false;
    if(v > 0){
        right = true;
        xCheck = position.x + v + SPRITE_SIZE;
    }
    if(v < 0){
        //if it's going left
        left = true;
        xCheck = position.x + v;
    }
    Math::Vector2D gridPosition = Math::Vector2D((int)xCheck/SPRITE_SIZE, (int)(position.y+SPRITE_SIZE/2)/SPRITE_SIZE);
    Math::Vector2D mapPosition(gridPosition.x + scene.x*(windowWidth/SPRITE_SIZE), gridPosition.y + scene.y*(windowHeight/SPRITE_SIZE));
    //if it's going off the map
    if(mapPosition.x < 0 || mapPosition.y < 0 || mapPosition.x > xMapSize || mapPosition.y > xMapSize){
        return true;
    }
    
    if(map[mapPosition.x + mapPosition.y*xMapSize]->solid){
        if(right){
            //going right
            position.x = (gridPosition.x-1)*SPRITE_SIZE;
        }
        if(left){
            //going left
            position.x = (gridPosition.x+1)*SPRITE_SIZE;
        }
        return true;
    }
    return false;
}
示例#4
0
/**
 *  rysujemy siatke kwadratow okreslajaca ktore pola sa widoczne, i odpowiednio pokolorowana
 *
 */
void DebugScreen::drawMap(QuadTree &qt){
	const HexColor lodColors[] = {color::red, color::green, color::blue, color::yellow};
	float scale = mapSize.z / qt.size.x;
	float nodeSize (qt.chunkSize.x * scale);
	glm::vec4 mapPosition(Global::main.size.x - 5.f - mapSize.z*0.5f, mapSize.w*0.5f + 5.f, 0, 0);
	// glm::vec4 mapPosition(Global::main.size.x - 5.f - mapSize.z, 5.f, 0, 0);

}
示例#5
0
bool LRGramar::startGrammarAnalysis(const char codeBuffer[])
{
    int returnCode;         //每次识别字符串的code
    int startPosition = 0;  //每次读出字符的起始位置
    int charA;             //每次从输入串中读出的字符保存到a
    int statusTopStack;   //栈顶状态


    morphology.setPreIsOp(true);//初始化操作符信号
    double num = 0;    //记录scanner扫描到数字的数值
    ////////////////////////////////////////////////////////
    /*do{
    	returnCode = morphology.scaner(codeBuffer,startPosition,bufferToken);

    	if(returnCode == DIGIT)
    	{
    		Complier::strToNumber(bufferToken,num);
    		printf("(%d,%g)\n",returnCode,num);
    	}
    	else if(returnCode == ERROR)
    	{
    		printf("('%s')不能有该文法生成!\n",bufferToken);
    	}
    	else if(returnCode==NOTE)
    	{
    		//
    	}
    	else
    	{
    		printf("(%d,'%s')\n",returnCode,bufferToken);
    	}

    }while(returnCode!=END_JINGHAO);*/
    //初始化相关堆栈
    quadCount = 0; //记录四元式数组存放位置
    nextq = 1;     //记录下一个四元式标号
    trueChainHead = 0;//记录回填真链的链首
    variableBufferPtr = -1;//存放变量名或者标示符的栈的指针
    OpPtr = -1;//ptr to the stack of op
    tempCount = 0;
    startPosition = 0;  //每次读出字符的起始位置
    statusStackPtr = -1;
    charStackPtr = -1;
    doTruePtr = -1;
    falseChainPtr = -1;
    push(statusStack,statusStackPtr,0); //将0状态压入堆栈
    push(charStack,charStackPtr,END_JINGHAO);
    charA = morphology.scaner(codeBuffer,startPosition,bufferToken);  //将字符串读入a
    if(charA==DIGIT || charA == IDENTIFIER)//如果为数字或者标示符及时保存
    {
        strcpy(variableBuffer[++variableBufferPtr],bufferToken);
    }
    statusTopStack = statusStack[statusStackPtr];         //栈顶状态
    int actionStatus = ActionTable[statusTopStack][mapPosition(charA)] ;
    while(actionStatus != ACC)
    {
        //如果是转移状态
        if(isTransferStatus(actionStatus))
        {
            //将状态和a压入堆栈
            push(statusStack,statusStackPtr,actionStatus);
            push(charStack,charStackPtr,charA);
            //读取下一个字符a
            do {
                charA = morphology.scaner(codeBuffer,startPosition,bufferToken);  //将字符串读入a
                if(charA==DIGIT || charA == IDENTIFIER)//如果为数字或者标示符及时保存
                {
                    strcpy(variableBuffer[++variableBufferPtr],bufferToken);
                }
            } while(charA==NOTE);
        }
        //如果是规约状态
        else if(isGuiYueStatus(actionStatus))
        {
            //用actionStatus所对应的规则(A->a)规约,并将|a|个状态和|a|个输入符号退栈,
            //当前栈顶状态为S,将A和GOTO[S][A]=S`进栈
            if(!doGuiYue(actionStatus))  //如果规约失败返回错误
            {
                return false;
            }
        }
        //some status else
        else
        {
            //error
            return false;
        }
        statusTopStack = statusStack[statusStackPtr];         //栈顶状态
        actionStatus = ActionTable[statusTopStack][mapPosition(charA)] ;
    }
    printf("---------------------------------------------------\n");
    printQuad();
    return true;
}