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 ) ); }
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; }
static void generateBatter( fileplayer_s *player, const names_s *name, const position2_e position ) { batter_attr_s attributes = { 0 }; rollBatterAttributes( &attributes ); strcpy( attributes.last_name, name->last_name ); strcpy( attributes.first_name, name->first_name ); int games = (rand() % 25) + 120; int ab = (int)round( (double)games * ab_per_game ); int po = (int)round( (double)games * ((double)getValueForTwo( put_outs, position, attributes.range ) / 100.0) ); int as = (int)round( (double)games * ((double)getValueForTwo( assists, position, attributes.arm ) / 100.0) ); int ba = getValueForTwo( batting_avg, attributes.power, attributes.hit_n_run ); int soa = getValueForOne( strikeout_avg, attributes.hit_n_run ); int fa = getValueForTwo( fielding_avg, attributes.range, attributes.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, attributes.speed ); memset( player, '\0', sizeof(fileplayer_s) ); strncpy( player->last_name, attributes.last_name, sizeof(player->last_name) ); strncpy( player->first_name, attributes.first_name, sizeof(player->first_name) ); termName( player->last_name, sizeof(player->last_name) ); termName( player->first_name, sizeof(player->first_name) ); int2word( player->real_avg, ba ); player->year[0] = 0x9D; player->position[0] = (position * 0x10) + getSecondaryPosition( position ); struct batting_s *batting = &(player->filestats.filebatting); setBatterRatings( batting->ratings, &attributes ); batting->real_games[0] = games; batting->real_sb[0] = getValueForOne( steals, attributes.speed ); batting->vl_2b[0] = getValueForOne( doubles, attributes.power ); batting->vl_3b[0] = getValueForTwo( triples, attributes.power, attributes.speed ); batting->vl_hr[0] = getValueForOne( home_runs, attributes.power ); batting->vl_bb[0] = getValueForOne( walks, attributes.hit_n_run ); batting->vl_so[0] = so; batting->real_runs[0] = batting->vl_hr[0] + getValueForOne( runs, attributes.speed ); batting->real_rbi[0] = batting->vl_hr[0] + getValueForOne( rbi, attributes.power ); batting->real_err[0] = err; batting->real_fa2[0] = (int)round( (10000.0 - (double)fa2) / 10.0 ); batting->color[0] = attributes.color; int2word( batting->vl_ab, ab ); int2word( batting->vl_hits, hits ); int2word( batting->real_po, po ); int2word( batting->real_as, as ); }
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 ); }
static int subtract(struct proc *p, int addr) { char temp[4]; int i,j; if (addr < 0 || addr > 99) { fprintf(stderr, "subtract: invalid address\n"); return -1; } if (load(addr, temp) == -1) { fprintf(stderr, "subtract: load failed\n"); return -1; } i = word2int(p->r); j = word2int(temp); if (i == -1) { fprintf(stderr, "subtract: non-numeric word in register\n"); return -1; } if (j == -1) { fprintf(stderr, "subtract: non-numeric word in memory\n"); return -1; } if (i < j) { fprintf(stderr, "subtract: negative result\n"); return -1; } i -= j; int2word(i, p->r); return 0; }
static int multiply(struct proc *p, int addr) { char temp[4]; int i,j; if (addr < 0 || addr > 99) { fprintf(stderr, "multiply: invalid address\n"); return -1; } if (load(addr, temp) == -1) { fprintf(stderr, "multiply: load failed\n"); return -1; } i = word2int(p->r); j = word2int(temp); if (i == -1) { fprintf(stderr, "multiply: non-numeric word in register\n"); return -1; } if (j == -1) { fprintf(stderr, "multiply: non-numeric word in memory\n"); return -1; } i *= j; int2word(i, p->r); return 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; }
static int divide(struct proc *p, int addr) { char temp[4]; int i,j; if (addr < 0 || addr > 99) { fprintf(stderr, "divide: invalid address\n"); return -1; } if (load(addr, temp) == -1) { fprintf(stderr, "divide: load failed\n"); return -1; } i = word2int(p->r); j = word2int(temp); if (i == -1) { fprintf(stderr, "divide: non-numeric word in register\n"); return -1; } if (j == -1) { fprintf(stderr, "divide: non-numeric word in memory\n"); return -1; } if (j == 0) { fprintf(stderr, "divide: division by zero\n"); return -1; } i /= j; int2word(i, p->r); return 0; }
void test_function_md5(param_test_thread* p) { /**********************/ /** Define variables **/ /**********************/ long count = 0; mpz_t nb; char word[100]; int i = 0; unsigned char hash[16]; char tmp[2]; char test[] = "05b28d17a7b6e7024b6e5d8cc43a8bf7"; /**************************/ /** Initialize variables **/ /**************************/ mpz_init_set_ui(nb, 540504354034); int2word(nb, "abcdefghijklmnopqrstuvwxyz", 26, word); /** Transfor hash (to externalize **/ for(i = 0; i < 16; i++) { tmp[0] = test[i*2]; tmp[1] = test[i*2+1]; sscanf(tmp, "%02x", (unsigned int *)&hash[i]); } /** Calculate while time is not over **/ while(*p->time_over == 0) { count++; nextword("abcdefghijklmnopqrstuvwxyz", 26, word); // comp(hash, (unsigned char*)md5(word)); module_md5_comp(hash, word); } /** When finish, block to avoid conflict on idp and mutex_running**/ test_finish_thread(p, count); /*pthread_mutex_lock(p->mutex_idp); *p->mutex_running -= 1; *p->idp += count; If mutex_runing reach 0, all thread are terminated. End program if(*p->mutex_running <= 0) { pthread_mutex_unlock(p->mutex_finish_test); } pthread_mutex_unlock(p->mutex_idp); */ }
static int divide_stack(struct proc *p, int addr) { char word1[4]; char word2[4]; int i,j; addr = word2int(p->sp); if (addr < 0 || addr > 99) { fprintf(stderr, "divide_stack: invalid stack pointer\n"); return -1; } if (load(addr--, word1) == -1) { fprintf(stderr, "divide_stack: load failed\n"); return -1; } if (load(addr, word2) == -1) { fprintf(stderr, "divide_stack: load failed\n"); return -1; } i = word2int(word1); j = word2int(word2); if (i==-1 || j==-1) { fprintf(stderr, "divide_stack: non-numeric word on stack\n"); return -1; } if (i == 0) { fprintf(stderr, "divide_stack: division by zero\n"); return -1; } j /= i; int2word(j, word2); int2word(addr, p->sp); if (store(word2, addr) == -1) { fprintf(stderr, "divide_stack: store failed\n"); return -1; } return 0; }
static int jmp(struct proc *p, int addr) { char temp[4]; if (addr < 0 || addr > 99) { fprintf(stderr, "jmp: invalid address\n"); return -1; } int2word(addr, temp); memcpy(p->ic, temp+2, 2); return 0; }
static int add_stack(struct proc *p, int addr) { char word1[4]; char word2[4]; int i,j; addr = word2int(p->sp); if (addr < 0 || addr > 99) { fprintf(stderr, "add_stack: invalid stack pointer\n"); return -1; } if (addr < p->stack_base+1) { fprintf(stderr, "add_stack: stack contains less than 2 elements\n"); return -1; } if (load(addr--, word1) == -1) { fprintf(stderr, "add_stack: load failed\n"); return -1; } if (load(addr, word2) == -1) { fprintf(stderr, "add_stack: load failed\n"); return -1; } i = word2int(word1); j = word2int(word2); if (i == -1 || j == -1) { fprintf(stderr, "add_stack: non-numeric word on stack\n"); return -1; } j += i; int2word(j, word2); /* store new stack value */ int2word(addr, p->sp); /* store stack pointer */ if (store(word2, addr) == -1) { fprintf(stderr, "add_stack: store failed\n"); return -1; } return 0; }
static int subtract_stack(struct proc *p, int addr) { char word1[4]; char word2[4]; int i,j; addr = word2int(p->sp); if (addr < 0 || addr > 99) { fprintf(stderr, "subtract_stack: invalid stack pointer\n"); return -1; } if (load(addr--, word1) == -1) { fprintf(stderr, "subtract_stack: load failed\n"); return -1; } if (load(addr, word2) == -1) { fprintf(stderr, "subtract_stack: load_failed\n"); return -1; } i = word2int(word1); j = word2int(word2); if (i==-1 || j==-1) { fprintf(stderr, "subtract_stack: non-numeric word on stack\n"); return -1; } if (i > j) { fprintf(stderr, "subtract_stack: negative result\n"); return -1; } j -= i; int2word(j, word2); int2word(addr, p->sp); if (store(word2, addr) == -1) { fprintf(stderr, "subtract_stack: store failed\n"); return -1; } return 0; }
static int jmp_if(struct proc *p, int addr) { char temp[4]; if (addr < 0 || addr > 99) return -1; int2word(addr, temp); if (p->c == 'T') { memcpy(p->ic, temp+2, 2); } return 0; }
int main() { struct proc *p; int procs,i; set_mem('0'); procs = load_progs(); if (procs < 0) return 1; if (sched_init() != 0) { fprintf(stderr, "Scheduler init failed\n"); return 1; } msg_init(); for (i=0; i<procs; i++) { p = &proc_table[i]; /* set up the process */ memset(p, '0', sizeof(struct proc)); p->c = 'F'; p->stack_base = 0; p->pid = i; int2word(i*100, p->br); int2word(99, p->lr); /* schedule process */ sched_reset(i); sched_resume(i); } /* print_mem(); */ sched_run(); /* print_mem(); */ return 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; }
int tick(struct proc *p) { char word[4]; char temp[4]; enum OP op; int addr, ic, i; if (p == NULL) { fprintf(stderr, "tick: NULL process\n"); return -1; } if (p->runnable == 0) return 0; /* load the word at p->ic */ memset(temp, '0', 4); memcpy(temp+2, p->ic, 2); ic = word2int(temp); if (ic == -1) { fprintf(stderr, "tick: invalid IC\n"); return -1; } if (load(ic, word) == -1) { fprintf(stderr, "tick: load failed\n"); return -1; } /* increment p->ic */ ic++; int2word(ic, temp); memcpy(p->ic, temp+2, 2); /* execute the instruction */ op = OPCODE(word[0], word[1]); memset(temp, '0', 4); memcpy(temp+2, word+2, 2); addr = word2int(temp); for (i=0; i<LEN(op_table); i++) { if (op_table[i].opcode == op) return op_table[i].run(p, addr); } fprintf(stderr, "tick: Illegal operation %c%c\n", word[0], word[1]); return -1; }
static int do_register_op(struct proc *p, int addr, char op, char *opname) { char *temp; int res; temp = get_wordref(p, addr); if (temp == NULL) { fprintf(stderr, "%s: failed to get memory ref\n", opname); return -1; } res = do_binop(p->r, temp, op); if (res < 0) { fprintf(stderr, "%s: do_binop failed\n", opname); return -1; } release_wordref(p, addr); int2word(res, p->r); return 0; }
static int push(struct proc *p, int addr) { addr = word2int(p->sp); if (addr == -1) { fprintf(stderr, "push: Non-numeric stack pointer\n"); return -1; } addr++; int2word(addr, p->sp); if (addr > 99) { fprintf(stderr, "push: Out of memory\n"); return -1; } if (store(p->r, addr) == -1) { fprintf(stderr, "push: store failed\n"); return -1; } return 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; }
static int pop(struct proc *p, int addr) { addr = word2int(p->sp); if (addr == -1) { fprintf(stderr, "pop: non-numeric stack pointer\n"); return -1; } if (addr > 99) { fprintf(stderr, "pop: Invalid stack pointer\n"); return -1; } if (addr <= p->stack_base) { fprintf(stderr, "pop: pop on empty stack\n"); return -1; } if (load(addr, p->r) == -1) { fprintf(stderr, "pop: load failed\n"); return -1; } addr--; int2word(addr, p->sp); return 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 ); }
static void generateCloser( fileplayer_s *player, const names_s *name ) { pitcher_attr_s attributes = { 0 }; rollCloserAttributes( &attributes ); strcpy( attributes.last_name, name->last_name ); strcpy( attributes.first_name, name->first_name ); int games = (rand() % 20) + 60; int era = getValueForTwo( closer_earned_run_avg, attributes.speed, attributes.control ); int vsba = getValueForTwo( closer_vs_batting_avg, attributes.speed, attributes.control ); int svpct = getValueForTwo( save_pct, attributes.speed, attributes.control ); int innpg = (rand() % 30) + 100; int abpi = getValueForTwo( at_bats_per_inn, attributes.speed, attributes.control ); int sop9 = getValueForOne( so_per_9, attributes.speed ); int bbp9 = getValueForOne( walks_per_9, attributes.control ); int hrp9 = getValueForOne( hr_per_9, attributes.speed ); memset( player, '\0', sizeof(fileplayer_s) ); strncpy( player->last_name, attributes.last_name, sizeof(player->last_name) ); strncpy( player->first_name, attributes.first_name, sizeof(player->first_name) ); termName( player->last_name, sizeof(player->last_name) ); termName( player->first_name, sizeof(player->first_name) ); int2word( player->real_avg, era ); player->year[0] = 0x9D; player->position[0] = attributes.hand; struct pitching_s *pitching = &(player->filestats.filepitching); setPitcherRatings( pitching->ratings, &attributes ); 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; pitching->real_wins[0] = (rand() % 10); pitching->real_losses[0] = (rand() % 10); pitching->real_games[0] = games; pitching->real_starts[0] = 0; pitching->real_cg[0] = 0; pitching->real_saves[0] = (int)round( (double)games * (double)svpct / 1000.0 ); pitching->color[0] = attributes.color; pitching->real_fa[0] = 1; pitching->real_er[0] = (int)round( dinn * (double)era / 900.0 ); // era is ERA * 100 pitching->vl_hr[0] = (int)round( dinn * (double)hrp9 / 900.0 ); // hrp9 is HR/9 * 100 pitching->vl_bb[0] = (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 ); }
ToddCoxeter::Graph* view(int c12, int c13, int c14, int c23, int c24, int c34, int g1, int g2, int g3, int edges, int faces, int weights) { /* logger.debug() << "viewing <" << c12 << ", " //4 << c13 << ", " //2 << c14 << ", " //2 << c23 << ", " //3 << c24 << ", " //2 << c34 << "> modulo {" //3 << g1 << ", " //2 << g2 << ", " //3 << g3 << "}" |0; //4 logger.debug() << "edges = " << edges << ", faces = " << faces |0; */ int arg_coxeter[6]; arg_coxeter[0] = c12; arg_coxeter[1] = c13; arg_coxeter[2] = c14; arg_coxeter[3] = c23; arg_coxeter[4] = c24; arg_coxeter[5] = c34; int e[5] = { 0, 0, 0, 0, 0 }; //so zero index does nothing Assert(0 <= g1 and g1 < 5, "generator #1 out of range"); e[g1] = true; Assert(0 <= g2 and g2 < 5, "generator #2 out of range"); e[g2] = true; Assert(0 <= g3 and g3 < 5, "generator #3 out of range"); e[g3] = true; //define symmetry subgroup std::vector<Word> gens; for (int i = 0; i < 4; ++i) { //LATER: this does nothing yet gens.push_back(Word(1, i)); } //define vertex stabiliizer subgroup generators std::vector<Word> v_cogens; for (int i = 0; i < 4; ++i) { if (e[i + 1]) v_cogens.push_back(int2word(i + 1)); } //define edges generators std::vector<Word> e_gens; for (int i = 0; i < 4; ++i) { if ((not e[i + 1]) and(edges % 10)) { e_gens.push_back(int2word(i + 1)); } edges /= 10; } //define face generators std::vector<Word> f_gens; for (int i = 0; i < 4; ++i) { for (int j = i + 1; j < 4; ++j) { if (faces % 10) { Word word; word.push_back(i); word.push_back(j); f_gens.push_back(word); } faces /= 10; } } //define weights Vect weight_vect = int2Vect(weights); return view(arg_coxeter, gens, v_cogens, e_gens, f_gens, weight_vect); }
static void generatePitcher( fileplayer_s *player, const names_s *name ) { pitcher_attr_s attributes = { 0 }; rollPitcherAttributes( &attributes ); strcpy( attributes.last_name, name->last_name ); strcpy( attributes.first_name, name->first_name ); int games = (rand() % 15) + 30; int era = getValueForTwo( earned_run_avg, attributes.speed, attributes.control ); int vsba = getValueForTwo( vs_batting_avg, attributes.speed, attributes.control ); int innpg = getValueForTwo( innings_per_game, attributes.speed, attributes.control ); int wpct = getValueForTwo( win_pct, attributes.speed, attributes.control ); int abpi = getValueForTwo( at_bats_per_inn, attributes.speed, attributes.control ); int dpct = innpg + 200; int maxcg = (int)round( (double)((games * innpg) - (games * (innpg - 200))) / (double)(1100 - innpg) ); int cpct = getValueForOne( cg_pct, attributes.fatigue ); int sop9 = getValueForOne( so_per_9, attributes.speed ); int bbp9 = getValueForOne( walks_per_9, attributes.control ); int hrp9 = getValueForOne( hr_per_9, attributes.speed ); int decisions = (int)round((float)games * ((float)dpct / 1000.0) ); int fat_fact = getFatigueFactor( attributes.fatigue ); if ( fat_fact < innpg ) innpg = fat_fact; memset( player, '\0', sizeof(fileplayer_s) ); strncpy( player->last_name, attributes.last_name, sizeof(player->last_name) ); strncpy( player->first_name, attributes.first_name, sizeof(player->first_name) ); termName( player->last_name, sizeof(player->last_name) ); termName( player->first_name, sizeof(player->first_name) ); int2word( player->real_avg, era ); player->year[0] = 0x9D; player->position[0] = attributes.hand; struct pitching_s *pitching = &(player->filestats.filepitching); setPitcherRatings( pitching->ratings, &attributes ); 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; pitching->real_wins[0] = (int)ceil( (double)decisions * (double)wpct / 1000.0 ); pitching->real_losses[0] = (int)ceil( (double)decisions * (1.0 - (double)wpct / 1000.0) ); pitching->real_games[0] = games; pitching->real_starts[0] = games; pitching->real_cg[0] = (int)round( (double)maxcg * (double)cpct / 100.0 ); pitching->color[0] = attributes.color; pitching->real_fa[0] = 1; pitching->real_er[0] = (int)round( dinn * (double)era / 900.0 ); // era is ERA * 100 pitching->vl_hr[0] = (int)round( dinn * (double)hrp9 / 900.0 ); // hrp9 is HR/9 * 100 pitching->vl_bb[0] = (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 ); }