Beispiel #1
0
void
cw_gameiter_reset(CWGameIterator *gameiter)
{
  gameiter->event = gameiter->game->first_event;

  cw_gamestate_cleanup(gameiter->state);
  cw_gamestate_initialize(gameiter->state);
  cw_gameiter_lineup_setup(gameiter);

  if (cw_game_info_lookup(gameiter->game, "htbf") &&
      !strcmp(cw_game_info_lookup(gameiter->game, "htbf"), "true")) {
    gameiter->state->batting_team = 1;
  }
  else {
    gameiter->state->batting_team = 0;
  }

  if (gameiter->event) {
    if (strcmp(gameiter->event->event_text, "NP")) {
      gameiter->state->batter_hand = gameiter->event->batter_hand;
      gameiter->parse_ok = cw_parse_event(gameiter->event->event_text, 
					  gameiter->event_data);
    }
    else {
      /* There are some very rare instances with an NP as the first play */
      gameiter->parse_ok = 1;
    }
  }
}
Beispiel #2
0
void 
cw_game_replace_player(CWGame *game, char *key_old, char *key_new) 
{
  CWAppearance *sub;
  CWData *data;
  CWEvent *event;

  for (sub = game->first_starter; sub != NULL; sub = sub->next) {
    if (!strcmp(sub->player_id, key_old)) {
      free(sub->player_id);
      sub->player_id = (char *) malloc(sizeof(char) * (strlen(key_new)+1));
      strcpy(sub->player_id, key_new);
    }
  }

  for (event = game->first_event; event != NULL; event = event->next) {
    if (!strcmp(event->batter, key_old)) {
      free(event->batter);
      event->batter = (char *) malloc(sizeof(char) * (strlen(key_new)+1));
      strcpy(event->batter, key_new);
    }

    for (sub = event->first_sub; sub != NULL; sub = sub->next) {
      if (!strcmp(sub->player_id, key_old)) {
	free(sub->player_id);
	sub->player_id = (char *) malloc(sizeof(char) * (strlen(key_new)+1));
	strcpy(sub->player_id, key_new);
      }
    }
  }

  for (data = game->first_data; data != NULL; data = data->next) {
    if (data->num_data >= 3 && !strcmp(data->data[0], "er") &&
	!strcmp(data->data[1], key_old)) {
      free(data->data[1]);
      data->data[1] = (char *) malloc(sizeof(char) * (strlen(key_new)+1));
      strcpy(data->data[1], key_new);
    }
  }

  if (cw_game_info_lookup(game, "wp") != NULL &&
      !strcmp(cw_game_info_lookup(game, "wp"), key_old)) {
    cw_game_info_set(game, "wp", key_new);
  }
  if (cw_game_info_lookup(game, "lp") != NULL &&
      !strcmp(cw_game_info_lookup(game, "lp"), key_old)) {
    cw_game_info_set(game, "lp", key_new);
  }
  if (cw_game_info_lookup(game, "save") != NULL &&
      !strcmp(cw_game_info_lookup(game, "save"), key_old)) {
    cw_game_info_set(game, "save", key_new);
  }
}
Beispiel #3
0
int
cw_scorebook_insert_game(CWScorebook *scorebook, CWGame *game)
{
  if (game == NULL) {
    return 0;
  }

  if (scorebook->first_game == NULL) {
    scorebook->first_game = game;
    scorebook->last_game = game;
  }
  else {
    CWGame *g = scorebook->first_game;
    while (g != NULL &&
	   (strcmp(cw_game_info_lookup(g, "date"),
		   cw_game_info_lookup(game, "date")) < 0 ||
	    (strcmp(cw_game_info_lookup(g, "date"),
		    cw_game_info_lookup(game, "date")) == 0 &&
	     strcmp(cw_game_info_lookup(g, "number"),
		    cw_game_info_lookup(game, "number")) < 0))) {
      g = g->next;
    }

    if (g == NULL) {
      game->prev = scorebook->last_game;
      scorebook->last_game->next = game;
      scorebook->last_game = game;
    }
    else if (g->prev == NULL) {
      scorebook->first_game->prev = game;
      game->next = scorebook->first_game;
      scorebook->first_game = game;
    }
    else {
      game->prev = g->prev;
      game->prev->next = game;
      g->prev = game;
      game->next = g;
    }
  }
  return 1;
}
Beispiel #4
0
/*
 * Output one player's boxscore entry
 */
void
cwbox_xml_player(CWGame *game,
		 CWBoxPlayer *player, int slot, int seq, CWRoster *roster)
{
  int pos;

  CWPlayer *bio = cw_roster_player_find(roster, player->player_id);
  printf("    <player id=\"%s\" lname=\"%s\" fname=\"%s\" "
	 "slot=\"%d\" seq=\"%d\" ", 
	 player->player_id, 
	 (bio) ? bio->last_name : "", (bio) ? bio->first_name: "", slot, seq);
  
  printf("pos=\"");
  if (player->ph_inn > 0 && player->positions[0] != 11) {
    printf("h");
  }
  else if (player->pr_inn > 0 && player->positions[0] != 12) {
    printf("r");
  }
  for (pos = 0; pos < player->num_positions; pos++) {
    if (player->positions[pos] == 10) {
      printf("d");
    }
    else if (player->positions[pos] == 11) {
      printf("h");
    }
    else if (player->positions[pos] == 12) {
      printf("r");
    }
    else {
      printf("%d", player->positions[pos]);
    }
  }
  printf("\" ");

  if (player->ph_inn > 0) {
    printf("ph_inning=\"%d\" ", player->ph_inn);
  }
  else if (player->pr_inn > 0) {
    printf("pr_inning=\"%d\" ", player->pr_inn);
  }

  printf(">\n");

  if (slot > 0) {
    printf("      <batting ab=\"%d\" r=\"%d\" h=\"%d\" d=\"%d\" "
	   "t=\"%d\" hr=\"%d\" bi=\"%d\" bi2out=\"%d\" ",
	   player->batting->ab, player->batting->r,
	   player->batting->h, player->batting->b2,
	   player->batting->b3, player->batting->hr, 
	   player->batting->bi, player->batting->bi2out);
    printf("bb=\"%d\" ibb=\"%d\" so=\"%d\" gdp=\"%d\" "
	   "hp=\"%d\" sh=\"%d\" sf=\"%d\" ",
	   player->batting->bb, player->batting->ibb,
	   player->batting->so, player->batting->gdp,
	   player->batting->hp, player->batting->sh, player->batting->sf);
    printf("sb=\"%d\" cs=\"%d\" ",
	   player->batting->sb, player->batting->cs);
    if (cw_game_info_lookup(game, "gwrbi") &&
	!strcmp(player->player_id, cw_game_info_lookup(game, "gwrbi"))) {
      printf("gwrbi=\"1\" ");
    }
    printf("/>\n");
  }


  for (pos = 1; pos < 10; pos++) {
    if (player->fielding[pos] == NULL) {
      continue;
    }

    printf("      <fielding pos=\"%d\" ", pos);
    printf("outs=\"%d\" po=\"%d\" a=\"%d\" e=\"%d\" dp=\"%d\" tp=\"%d\" ",
	   player->fielding[pos]->outs, player->fielding[pos]->po,
	   player->fielding[pos]->a, player->fielding[pos]->e,
	   player->fielding[pos]->dp, player->fielding[pos]->tp);
    if (player->positions[pos] == 2) {
      printf("pb=\"%d\" ", player->fielding[pos]->pb);
    }
    printf("bip=\"%d\" bf=\"%d\" ",
	   player->fielding[pos]->bip, player->fielding[pos]->bf);
    printf("/>\n");
  }
  printf("    </player>\n");
}
Beispiel #5
0
/*
 * Outputs the boxscore in XML format
 */
void 
cwbox_print_xml(CWGame *game, CWBoxscore *boxscore, 
		CWRoster *visitors, CWRoster *home)
{
  printf("<boxscore game_id=\"%s\" date=\"%s\" site=\"%s\" "
	 "visitor=\"%s\" visitor_city=\"%s\" visitor_name=\"%s\" "
	 "home=\"%s\" home_city=\"%s\" home_name=\"%s\" ",
	 game->game_id, 
	 cw_game_info_lookup(game, "date"), cw_game_info_lookup(game, "site"),
	 visitors->team_id, visitors->city, visitors->nickname,
	 home->team_id, home->city, home->nickname);

  printf("start_time=\"%s\" day_night=\"%s\" "
	 "temperature=\"%s\" wind_direction=\"%s\" wind_speed=\"%s\" "
	 "field_condition=\"%s\" precip=\"%s\" sky=\"%s\" "
	 "time_of_game=\"%s\" attendance=\"%s\" ",
	 cw_game_info_lookup(game, "starttime"),
	 cw_game_info_lookup(game, "daynight"),
	 cw_game_info_lookup(game, "temp"),
	 cw_game_info_lookup(game, "winddir"),
	 cw_game_info_lookup(game, "windspeed"),
	 cw_game_info_lookup(game, "fieldcond"),
	 cw_game_info_lookup(game, "precip"),
	 cw_game_info_lookup(game, "sky"),
	 cw_game_info_lookup(game, "timeofgame"),
	 cw_game_info_lookup(game, "attendance"));

  if (cw_game_info_lookup(game, "umphome")) {
    printf("umpire_hp=\"%s\" ", cw_game_info_lookup(game, "umphome"));
  }
  if (cw_game_info_lookup(game, "ump1b")) {
    printf("umpire_1b=\"%s\" ", cw_game_info_lookup(game, "ump1b"));
  }
  if (cw_game_info_lookup(game, "ump2b")) {
    printf("umpire_2b=\"%s\" ", cw_game_info_lookup(game, "ump2b"));
  }
  if (cw_game_info_lookup(game, "ump3b")) {
    printf("umpire_3b=\"%s\" ", cw_game_info_lookup(game, "ump3b"));
  }
  if (cw_game_info_lookup(game, "umplf")) {
    printf("umpire_lf=\"%s\" ", cw_game_info_lookup(game, "umplf"));
  }
  if (cw_game_info_lookup(game, "umprf")) {
    printf("umpire_rf=\"%s\" ", cw_game_info_lookup(game, "umprf"));
  }

  if (boxscore->outs_at_end != 3) {
    printf("walk_off=\"%d\" outs_at_end=\"%d\" ",
	   boxscore->walk_off, boxscore->outs_at_end);
  }

  if (cw_game_info_lookup(game, "htbf") &&
      !strcmp(cw_game_info_lookup(game, "htbf"), "true")) {
    printf("htbf=\"1\" ");
  }

  printf(">\n");

  cwbox_xml_linescore(boxscore);

  cwbox_xml_batting(game, boxscore, 0, visitors);
  cwbox_xml_batting(game, boxscore, 1, home);
  cwbox_xml_pitching(game, boxscore, 0, visitors);
  cwbox_xml_pitching(game, boxscore, 1, home);

  cwbox_xml_batting_events(boxscore->b2_list, "doubles", "double");
  cwbox_xml_batting_events(boxscore->b3_list, "triples", "triple");
  cwbox_xml_homeruns(boxscore->hr_list);
  cwbox_xml_batting_events(boxscore->ibb_list, 
			   "intentionalwalks", "intentionalwalk");
  cwbox_xml_batting_events(boxscore->hp_list, "hitbypitches", "hitbypitch");
  cwbox_xml_batting_events(boxscore->sh_list, "sacbunts", "sacbunt");
  cwbox_xml_batting_events(boxscore->sf_list, "sacflies", "sacfly");

  cwbox_xml_steal_events(boxscore->sb_list, "stolenbases", "stolenbase");
  cwbox_xml_steal_events(boxscore->cs_list, "caughtstealings", 
			 "caughtstealing");
  cwbox_xml_pickoff_events(boxscore->po_list);

  cwbox_xml_wildpitch_events(boxscore->wp_list);
  cwbox_xml_passedball_events(boxscore->pb_list);
  cwbox_xml_multiplay_events(boxscore->dp_list, "doubleplays", "doubleplay");
  cwbox_xml_multiplay_events(boxscore->tp_list, "tripleplays", "tripleplay");
    
  printf("</boxscore>\n\n");
}
Beispiel #6
0
/*
 * Output the pitching lines for team 't'
 */
void
cwbox_xml_pitching(CWGame *game, CWBoxscore *boxscore, int t, CWRoster *roster)
{
  CWBoxPitcher *pitcher = cw_box_get_starting_pitcher(boxscore, t);
  int seq = 1;

  printf("  <pitching team=\"%s\">\n", roster->team_id);

  while (pitcher != NULL) {
    CWPlayer *bio = cw_roster_player_find(roster, pitcher->player_id);
    printf("    <pitcher id=\"%s\" lname=\"%s\" fname=\"%s\" ",
	   pitcher->player_id, (bio) ? bio->last_name : "", 
	   (bio) ? bio->first_name : "");
    /* FIXME: A pitcher gets a shutout if he records all outs for a team,
     * even if not the starting pitcher! */
    printf("gs=\"%d\" cg=\"%d\" sho=\"%d\" gf=\"%d\" ",
	   (pitcher->prev == NULL) ? 1 : 0,
	   (pitcher->prev == NULL && 
	    pitcher->next == NULL) ? 1 : 0,
	   (pitcher->prev == NULL && pitcher->next == NULL &&
	    pitcher->pitching->r == 0) ? 1 : 0,
	   (pitcher->prev != NULL && 
	    pitcher->next == NULL) ? 1 : 0);
    printf("outs=\"%d\" ab=\"%d\" bf=\"%d\" h=\"%d\" r=\"%d\" "
	   "er=\"%d\" hr=\"%d\" ",
	   pitcher->pitching->outs, pitcher->pitching->ab,
	   pitcher->pitching->bf,
	   pitcher->pitching->h, pitcher->pitching->r,
	   pitcher->pitching->er, pitcher->pitching->hr);
    printf("bb=\"%d\" ibb=\"%d\" so=\"%d\" wp=\"%d\" "
	   "bk=\"%d\" hb=\"%d\" ",
	   pitcher->pitching->bb, pitcher->pitching->ibb,
	   pitcher->pitching->so, pitcher->pitching->wp,
	   pitcher->pitching->bk, pitcher->pitching->hb);
    printf("gb=\"%d\" fb=\"%d\" ",
	   pitcher->pitching->gb, pitcher->pitching->fb);
    
    if (pitcher->pitching->xbinn > 0) {
      printf("xb=\"%d\" xbinn=\"%d\" ",
	     pitcher->pitching->xb, pitcher->pitching->xbinn);
    }

    if (cw_game_info_lookup(game, "pitches") &&
      !strcmp(cw_game_info_lookup(game, "pitches"), "pitches")) {
      printf("pitch=\"%d\" strike=\"%d\" ",
	     pitcher->pitching->pitches, pitcher->pitching->strikes);
    }

    if (cw_game_info_lookup(game, "wp") &&
	!strcmp(pitcher->player_id, cw_game_info_lookup(game, "wp"))) {
      printf("dec=\"W\" ");
    }
    else if (cw_game_info_lookup(game, "lp") &&
	     !strcmp(pitcher->player_id, cw_game_info_lookup(game, "lp"))) {
      printf("dec=\"L\" ");
    }
    else if (cw_game_info_lookup(game, "save") &&
	     !strcmp(pitcher->player_id, cw_game_info_lookup(game, "save"))) {
      printf("dec=\"S\" ");
    }


    printf("/>\n");
    seq++;
    pitcher = pitcher->next;
  }
  

  printf("  </pitching>\n");
}