Exemplo n.º 1
0
static char *formatDosToAmiga_ShouldReturnFalseIfBatterNeedingOverflowHasPitchingStats_GivenAPlayersFile()
{
     fileplayer_s *players_file = buildFilePlayers();

     swapBatterStats( players_file );

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos != fpos_Pitcher )
          {
               acc_bat_stats_s *batting = &(players_file[i].acc_stats.action.batting);

               int2byte( batting->acc_rbi, STAT_CAP_AMOUNT + 1 );
               int2byte( batting->acc_so,  STAT_CAP_AMOUNT + 1 );

               acc_pch_stats_s *pitching = &(players_file[i].acc_stats.simulated.pitching);

               int2word( pitching->acc_innings, 1 );
               int2word( pitching->acc_hits,    1 );

               break;
          }
     }

     assertEquals( bl_False, formatDosToAmiga( players_file ) );

     return NULL;
}
Exemplo n.º 2
0
static char *formatDosToAmiga_ShouldMovePitcherActionGamesToSimulatedStarts_GivenAPlayersFile()
{
     fileplayer_s *players_file    = buildFilePlayers();
     int           expected_starts = 0;
     int           player_idx      = 0;

     swapBatterStats( players_file );

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos == fpos_Pitcher )
          {
               acc_pch_stats_s *sim = &(players_file[i].acc_stats.simulated.pitching);
               acc_bat_stats_s *act = &(players_file[i].acc_stats.action.batting);

               expected_starts = byte2int( sim->acc_starts );
               player_idx      = i;

               int2byte( sim->acc_starts, byte2int( act->acc_games ) );
               int2byte( act->acc_games,  expected_starts            );

               break;
          }
     }

     assertEquals( bl_True, formatDosToAmiga( players_file ) );

     acc_pch_stats_s *sim = &(players_file[player_idx].acc_stats.simulated.pitching);

     assertEquals( expected_starts, byte2int( sim->acc_starts ) );

     return NULL;
}
Exemplo n.º 3
0
static char *formatDosToAmiga_ShouldCapStrikeOutsAndMoveExcessFromActionToSimulated_GivenAPlayersFile()
{
     fileplayer_s *players_file = buildFilePlayers();
     int           player_idx   = 0;

     swapBatterStats( players_file );

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos != fpos_Pitcher )
          {
               int2byte( players_file[i].acc_stats.action.batting.acc_so,    229 );
               int2byte( players_file[i].acc_stats.simulated.batting.acc_so,   0 );

               player_idx = i;

               break;
          }
     }

     formatDosToAmiga( players_file );

     assertEquals( 225, byte2int( players_file[player_idx].acc_stats.simulated.batting.acc_so ) );
     assertEquals(   4, byte2int( players_file[player_idx].acc_stats.action.batting.acc_so    ) );

     return NULL;
}
Exemplo n.º 4
0
boolean_e genPlayerIds( fileplayer_s *players_file )
{
     clearErrorMessage();

     for ( int player_id = 1, idx = 0; idx < TOTAL_PLAYERS; ++idx )
     {
          if ( EMPTY( players_file[idx].last_name ) ) continue;

          acc_player_id_s *id_info = &(players_file[idx].acc_stats.action.id_info);

          if ( word2int( id_info->player_id ) != 0 )
          {
               sprintf( error_message, "Player ID field already contains a number!" );

               return bl_False;
          }

          if ( byte2int( id_info->checksum ) != 0 )
          {
               sprintf( error_message, "Checksum field already contains a number!" );

               return bl_False;
          }

          int2word( id_info->player_id,               player_id   );
          int2byte( id_info->checksum,  calcChecksum( player_id ) );

          player_id++;
     }

     return bl_True;
}
Exemplo n.º 5
0
size_t sn_cliet_ip_address(const char *ipaddress, SNAttribute *output) {
    in_addr_t ipaddr;
    u_char ip_bytes[4];
    
    ipaddr = ntohl(inet_addr(ipaddress));
    if (ipaddr == INADDR_NONE) {
        perror("ERROR:");
        return -1;
    }
    int2byte(ipaddr, ip_bytes);
    
    return generate_attribute(CLIENT_IPADDRESS_ID, ip_bytes, 4, output);
}
Exemplo n.º 6
0
static boolean_e generateFilePlayer( const player_s *player, const int season, const int player_idx, fileplayer_s *players_file )
{
     int2word( players_file[player_idx].acc_stats.action.id_info.player_id,               player->player_id   );
     int2byte( players_file[player_idx].acc_stats.action.id_info.checksum,  calcChecksum( player->player_id ) );

     memcpy( players_file[player_idx].first_name,  player->first_name,      sizeof(players_file[player_idx].first_name)  );
     memcpy( players_file[player_idx].last_name,   player->last_name,       sizeof(players_file[player_idx].last_name)   );
     memcpy( players_file[player_idx].first_phoen, player->first_phoenetic, sizeof(players_file[player_idx].first_phoen) );
     memcpy( players_file[player_idx].last_phoen,  player->last_phoenetic,  sizeof(players_file[player_idx].last_phoen)  );

     termName( players_file[player_idx].first_name,  sizeof(players_file[player_idx].first_name)  );
     termName( players_file[player_idx].last_name,   sizeof(players_file[player_idx].last_name)   );
     termName( players_file[player_idx].first_phoen, sizeof(players_file[player_idx].first_phoen) );
     termName( players_file[player_idx].last_phoen,  sizeof(players_file[player_idx].last_phoen)  );

     int2byte( players_file[player_idx].year, player->rookie_season + YEAR_SEASON_OFFSET );

     if   ( player->player_type == pt_Pitcher ) { generatePitcher( player, season, &(players_file[player_idx]) ); }
     else                                       { generateBatter(  player, season, &(players_file[player_idx]) ); }

     return bl_True;
}
Exemplo n.º 7
0
boolean_e copyPlayerIds( fileplayer_s *players_file1, fileplayer_s *players_file2 )
{
     fileplayer_s   *matchingPlayer;


     clearErrorMessage();

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          if ( EMPTY( players_file1[i].last_name ) ) continue;

          if ( (matchingPlayer = findMatchingPlayer( &players_file1[i], players_file2 )) == NULL )
          {
               sprintf( error_message, "Player <%.*s, %.*s> not found!",
                       sizeof(players_file1[i].last_name),  players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );

               return bl_False;
          }

          acc_player_id_s *id_info1 = &(players_file1[i].acc_stats.action.id_info);
          acc_player_id_s *id_info2 = &(matchingPlayer->acc_stats.action.id_info);

          if ( word2int( id_info1->player_id ) != 0 )
          {
               sprintf( error_message, "Player ID field for <%.*s, %.*s> already contains a number!",
                       sizeof(players_file1[i].last_name),  players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );

               return bl_False;
          }

          if ( byte2int( id_info1->checksum ) != 0 )
          {
               sprintf( error_message, "Checksum field for <%.*s, %.*s> already contains a number!",
                       sizeof(players_file1[i].last_name),  players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );

               return bl_False;
          }

          int2word( id_info1->player_id, word2int( id_info2->player_id ) );
          int2byte( id_info1->checksum,  byte2int( id_info2->checksum  ) );
     }

     return bl_True;
}
Exemplo n.º 8
0
char *calc_keepalive_data(time_t timestamp) {
    static char keepalive_data[64];
    u_char timebytes[4];
    u_char md5_result[16];
    mbedtls_md5_context md5;
    
    if (strlen(keepalive_data) == 0) {
        strcpy(keepalive_data, DEFAULT_KEEPALIVE_DATA);
    }
    
    int2byte((int)timestamp, timebytes);
    
    mbedtls_md5_init(&md5);
    mbedtls_md5_starts(&md5);
    mbedtls_md5_update(&md5, timebytes, 4);
    mbedtls_md5_update(&md5, (const u_char *)keepalive_data, strlen(keepalive_data));
    mbedtls_md5_finish(&md5, md5_result);
    
    byte2str(md5_result, 16, keepalive_data);
    return keepalive_data;
}
void Transfer::setBHAckUniqueID 	(int ackUniqueID 	) {
    m_bh_ackUniqueID 	= int2byte(ackUniqueID 	,8);
}
Exemplo n.º 10
0
void Transfer::setBHAckIdentifier	(int ackIdentifier	) {
    m_bh_ackIdentifier	= int2byte(ackIdentifier,8);
}
Exemplo n.º 11
0
void Transfer::setBHFlag 		(int flag 		) {
    m_bh_flag 	 	= int2byte(flag 	,8);
}
Exemplo n.º 12
0
static void generateClosingPitcher( const player_s *player, const int season, fileplayer_s *players_file )
{
     pitcher_s      *pitcher  = player->details.pitching;
     filepitching_s *pitching = &(players_file->filestats.filepitching);

     filehand_e hand = mapHandedness( player->handedness );

     int speed   = adjustRating(  pitcher->speed,   season, player );
     int control = adjustRating(  pitcher->control, season, player );
     int fatigue =                pitcher->fatigue;

     players_file->position[0] = (fpos_Pitcher << 4) + hand;

     pitching->ratings[0] = (speed   << 4) +         control;
     pitching->ratings[1] = (fatigue << 4) + player->longevity;

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

     int games = (rand() % 20) + 60;
     int era   = getValueForTwo( closer_earned_run_avg,   speed, control );
     int vsba  = getValueForTwo( closer_vs_batting_avg,   speed, control );
     int svpct = getValueForTwo( save_pct, speed, control );
     int innpg = (rand() % 30) + 100;
     int abpi  = getValueForTwo( at_bats_per_inn, speed, control );
     int sop9  = getValueForOne( so_per_9, speed );
     int bbp9  = getValueForOne( walks_per_9, control );
     int hrp9  = getValueForOne( hr_per_9, speed );

     int2word( players_file->real_avg, era );

     double dinn = (double)games * (double)innpg / 100.0;
     int    inn  = (int)floor( dinn ) * 10 + (rand() % 3);

     dinn  = (double)inn / 10.0;
     dinn += (((double)inn / 10.0) - dinn) / 3.0;

     int2byte( pitching->real_wins,   (rand() % 10) );
     int2byte( pitching->real_losses, (rand() % 10) );
     int2byte( pitching->real_games,  games         );
     int2byte( pitching->real_starts, 0             );
     int2byte( pitching->real_cg,     0             );
     int2byte( pitching->real_saves,  (int)round( (double)games * (double)svpct / 1000.0 ) );
     int2byte( pitching->real_fa,     1 );
     int2byte( pitching->real_er,     (int)round( dinn * (double)era / 900.0 ) ); // era is ERA * 100
     int2byte( pitching->vl_hr,       (int)round( dinn * (double)hrp9 / 900.0 ) ); // hrp9 is HR/9 * 100
     int2byte( pitching->vl_bb,       (int)round( dinn * (double)bbp9 / 90.0 ) ); // bbp9 is BB/9 * 10

     double dvsba = (double)vsba / 1000.0;
     int    ab    = (int)round( dinn * ((float)abpi / 100.0) );
     int    hits  = (int)round( dvsba * (float)ab );
     int    so    = (int)round( dinn * (double)sop9 / 90.0 ); // sop9 is SO/9 * 10

     int2word( pitching->real_inn,  inn  );
     int2word( pitching->vl_ab,     ab   );
     int2word( pitching->vl_hits,   hits );
     int2word( pitching->vl_so,     so   );
}
Exemplo n.º 13
0
void Transfer::setBHSessionID 	 	(int sessionID 		) {
    m_bh_sessionID	= int2byte(sessionID	,8);
}
Exemplo n.º 14
0
static void generateStartingPitcher( const player_s *player, const int season, fileplayer_s *players_file )
{
     pitcher_s      *pitcher  = player->details.pitching;
     filepitching_s *pitching = &(players_file->filestats.filepitching);

     filehand_e hand = mapHandedness( player->handedness );

     int speed   = adjustRating(  pitcher->speed,   season, player );
     int control = adjustRating(  pitcher->control, season, player );
     int fatigue = adjustFatigue( pitcher->fatigue, season, player );

     players_file->position[0] = (fpos_Pitcher << 4) + hand;

     pitching->ratings[0] = (speed   << 4) +         control;
     pitching->ratings[1] = (fatigue << 4) + player->longevity;

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

     int games = (rand() % 15) + 30;
     int era   = getValueForTwo( earned_run_avg,   speed, control );
     int vsba  = getValueForTwo( vs_batting_avg,   speed, control );
     int innpg = getValueForTwo( innings_per_game, speed, control );
     int wpct  = getValueForTwo( win_pct,          speed, control );
     int abpi  = getValueForTwo( at_bats_per_inn,  speed, control );
     int dpct  = innpg + 200;
     int maxcg = (int)round( (double)((games * innpg) - (games * (innpg - 200))) / (double)(1100 - innpg) );
     int cpct  = getValueForOne( cg_pct, fatigue );
     int sop9  = getValueForOne( so_per_9, speed );
     int bbp9  = getValueForOne( walks_per_9, control );
     int hrp9  = getValueForOne( hr_per_9, speed );
     int decisions = (int)round((float)games * ((float)dpct / 1000.0) );
     int fat_fact = getFatigueFactor( fatigue );

     if ( fat_fact < innpg ) innpg = fat_fact;

     int2word( players_file->real_avg, era );

     double dinn = (double)games * (double)innpg / 100.0;
     int    inn  = (int)floor( dinn ) * 10 + (rand() % 3);

     dinn  = (double)inn / 10.0;
     dinn += (((double)inn / 10.0) - dinn) / 3.0;

     int2byte( pitching->real_wins,   (int)ceil( (double)decisions * (double)wpct / 1000.0 ) );
     int2byte( pitching->real_losses, (int)ceil( (double)decisions * (1.0 - (double)wpct / 1000.0) ) );
     int2byte( pitching->real_games,  games );
     int2byte( pitching->real_starts, games );
     int2byte( pitching->real_cg,     (int)round( (double)maxcg * (double)cpct / 100.0 ) );

     int2byte( pitching->real_fa, 1 );
     int2byte( pitching->real_er, (int)round( dinn * (double)era / 900.0 ) ); // era is ERA * 100
     int2byte( pitching->vl_hr,   (int)round( dinn * (double)hrp9 / 900.0 ) ); // hrp9 is HR/9 * 100
     int2byte( pitching->vl_bb,   (int)round( dinn * (double)bbp9 / 90.0 ) ); // bbp9 is BB/9 * 10

     double dvsba = (double)vsba / 1000.0;
     int    ab    = (int)round( dinn * ((float)abpi / 100.0) );
     int    hits  = (int)round( dvsba * (float)ab );
     int    so    = (int)round( dinn * (double)sop9 / 90.0 ); // sop9 is SO/9 * 10

     int2word( pitching->real_inn,  inn  );
     int2word( pitching->vl_ab,     ab   );
     int2word( pitching->vl_hits,   hits );
     int2word( pitching->vl_so,     so   );
}
Exemplo n.º 15
0
void Transfer::setBHAckDataSize 	(int ackDataSize 	) {
    m_bh_ackDataSize 	= int2byte(ackDataSize 	,16);
}
Exemplo n.º 16
0
QByteArray Transfer::incAckIdentifier(int inc) {
    m_myAckIdentifier += inc;
    return int2byte(m_myAckIdentifier, 8);
}
Exemplo n.º 17
0
void Transfer::setBHIdentifier 	 	(int identifier 	) {
    m_bh_identifier 	= int2byte(identifier 	,8);
}
Exemplo n.º 18
0
void Transfer::setBHDataOffset 	 	(int dataOffset 	) {
    m_bh_dataOffset 	= int2byte(dataOffset 	,16);
}
Exemplo n.º 19
0
void Transfer::setBHTotalDataSize	(int totalDataSize 	) {
    m_bh_totalDataSize 	= int2byte(totalDataSize,16);
}
Exemplo n.º 20
0
size_t sn_keepalive_time(time_t timestamp, SNAttribute *output) {
    u_char timebytes[4];
    int2byte((int)timestamp, timebytes);
    
    return generate_attribute(KEEPALIVE_TIME_ID, timebytes, 4, output);
}
Exemplo n.º 21
0
void Transfer::setBHMessageLength	(int messageLength 	) {
    m_bh_messageLength	= int2byte(messageLength,8);
}
Exemplo n.º 22
0
//
//string Sdr::loadCdx() {
//	string cpath = this->cdxpath();
//	if (!fexist(cpath.c_str())) {
//		return "cdx file not exist";
//	}
//	fstream cfs(cpath.c_str(), ios::in);
//	if (!cfs.is_open()) {
//		cfs.close();
//		return "open cdx file error:" + cpath;
//	}
//	char cbuf[100];
//	cfs.read(cbuf, CDX_HSIZE);
//	int ccount = byte2int(cbuf);
//	int offs_len = byte2int(cbuf + 4);
//	int csize = byte2int(cbuf + 8);
//	while (!cfs.eof()) {
//		cfs.read(cbuf, ccount + 4);
//		int esize = byte2int(cbuf + ccount);
//		cout << cbuf << "," << esize << endl;
//		char ibuf[offs_len];
//		for (int i = 0; i < esize; i++) {
//			cfs.read(ibuf, offs_len);
//		}
//	}
//	cout << csize << endl;
//	return "";
//}
//
string Sdr::createEdx(int ecount, bool oft64) {
    this->loadDictInfo();
	string epath = this->edxpath();
	string ipath = this->idxpath();
	if (fexist(epath.c_str())) {
		return "edx file already exist";
	}
	fstream ifs(ipath.c_str(), ios::in);
	if (!ifs.is_open()) {
		ifs.close();
		return "open .idx file error:" + ipath;
	}
	fstream efs(epath.c_str(), ios::out);
	if (!efs.is_open()) {
		efs.close();
		return "open edx file error:" + epath;
	}
	string sbuf;
	int offs_len = oft64 ? 8 : 4;
	int cbuf_len = ecount + offs_len;
	int rofts = this->lessVersion("3.0.0") ? 4 : 8;
	char cbuf[cbuf_len];
	memset(cbuf, 0, cbuf_len);
	char tbuf[16];
	long offset = 0;
	int esize = 0;
	int ssize = 0;
	long loft = 0;
	//
	efs.seekp(12);
	//read the first line.
	getline(ifs, sbuf, '\0');
	memset(cbuf, 0, cbuf_len);
	ssize = sbuf.length();
	memcpy(cbuf, sbuf.c_str(), ssize < ecount ? ssize : ecount);
	ifs.read(tbuf, rofts + 4);
	while (1) {
		loft = ifs.tellg();
		sbuf.clear();
		getline(ifs, sbuf, '\0');
		ifs.read(tbuf, rofts + 4);
		if (ccmp_c(cbuf, sbuf.c_str(), ecount) == 0 && !ifs.eof()) {
			continue;
		}
		if (oft64) {
			long2byte(offset, cbuf + ecount);
		} else {
			int2byte(offset, cbuf + ecount);
		}
		efs.write(cbuf, cbuf_len);
//		cout << cbuf << endl;
		//
		memset(cbuf, 0, cbuf_len);
		ssize = sbuf.length();
		memcpy(cbuf, sbuf.c_str(), ssize < ecount ? ssize : ecount);
		offset = loft;
		esize++;
		if (ifs.eof()) {
			break;
		}
	}
	int2byte(ecount, tbuf);
	int2byte(offs_len, tbuf + 4);
	int2byte(esize, tbuf + 8);
	efs.seekp(0);
	efs.write(tbuf, 12);
	efs.close();
	ifs.close();
	return "";
}
Exemplo n.º 23
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 ) );
}