示例#1
0
文件: main.c 项目: antonmazun/gogog
static void game_test1(void ** state)
{
    int size = 5;
    game_t * game[size];
    game[0] = game_new("Skyrim", 2011);
    game[1] = game_new("Witcher", 2007);
    game[2] = game_new("Most Wanted", 2005);
    game[3] = game_new("Underground", 2003);
    game[4] = game_new("Assasins Creed", 2007);
    assert_int_equal(2003, game_get_year(game_get_oldest(game, size)));
}
示例#2
0
void state_constructor() {
	switch (rpg.state.state) {
		case RPG_STATE_NEW_GAME:
			game_new();
			break;
		default:
			break;
	}

	return;
}
示例#3
0
文件: main.c 项目: impli/bomberman
int main(int argc, char *argv[]) {
	struct game* game = game_new();

	window_create(SIZE_BLOC * MAP_WIDTH,
			SIZE_BLOC * MAP_HEIGHT + BANNER_HEIGHT + LINE_HEIGHT);

	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

	// to obtain the DEFAULT_GAME_FPS, we have to reach a loop duration of (1000 / DEFAULT_GAME_FPS) ms
	int ideal_speed = 1000 / DEFAULT_GAME_FPS;
	int timer, execution_speed;

	// game loop
	// fixed time rate implementation
	int done = menu_display(game);

	while (!done) {
		timer = SDL_GetTicks();

		done = game_update(game);
		game_display(game);

		if ( player_get_dead(game_get_player(game))) {		// Reset the game if the player is dead
			game_free(game);
			game=game_new();
		}

		if(game_get_win(game) == 1)
			done=1;

		execution_speed = SDL_GetTicks() - timer;
		if (execution_speed < ideal_speed)
			SDL_Delay(ideal_speed - execution_speed); // we are ahead of ideal time. let's wait.

	}
	window_free();
	game_free(game);
	SDL_Quit();

	return EXIT_SUCCESS;
}
示例#4
0
文件: server.c 项目: jquick/pioneers
/** Try to start a new server.
 * @param params The parameters of the game
 * @param hostname The hostname that will be visible in the meta server
 * @param port The port to listen to
 * @param register_server Register at the meta server
 * @param meta_server_name The hostname of the meta server
 * @param random_order Randomize the player number
 * @return A pointer to the new game, or NULL
*/
Game *server_start(const GameParams * params, const gchar * hostname,
		   const gchar * port, gboolean register_server,
		   const gchar * meta_server_name, gboolean random_order)
{
	Game *game;
	guint32 randomseed = time(NULL);

	g_return_val_if_fail(params != NULL, NULL);
	g_return_val_if_fail(port != NULL, NULL);

#ifdef PRINT_INFO
	g_print("game type: %s\n", params->title);
	g_print("num players: %d\n", params->num_players);
	g_print("victory points: %d\n", params->victory_points);
	g_print("terrain type: %s\n",
		(params->random_terrain) ? "random" : "default");
	g_print("Tournament time: %d\n", params->tournament_time);
	g_print("Quit when done: %d\n", params->quit_when_done);
#endif

	g_rand_ctx = g_rand_new_with_seed(randomseed);
	log_message(MSG_INFO, "%s #%" G_GUINT32_FORMAT ".%s.%03d\n",
		    /* Server: preparing game #..... */
		    _("Preparing game"), randomseed, "G", get_rand(1000));

	game = game_new(params);
	g_assert(game->server_port == NULL);
	game->server_port = g_strdup(port);
	g_assert(game->hostname == NULL);
	if (hostname && strlen(hostname) > 0) {
		game->hostname = g_strdup(hostname);
	}
	game->random_order = random_order;
	if (!game_server_start(game, register_server, meta_server_name)) {
		game_free(game);
		game = NULL;
	}
	return game;
}
示例#5
0
文件: main.c 项目: NatTuck/teg
/* ends the game */
void game_end( PSPLAYER winner )
{
	char strout[PROT_MAX_LEN + PLAYERNAME_MAX_LEN * TEG_MAX_PLAYERS + 200];
	PLIST_ENTRY l = g_list_player.Flink;
	PSPLAYER pJ;

	/* add points to the winner */
	if( winner && g_game.round_number > 0 ) {
		int points = 350 / g_game.round_number;

		winner->player_stats.score += points;
	}

	/* update scores */
	player_map( player_insert_scores );

	if( aux_token_stasta(strout, sizeof(strout) -1 ) == TEG_STATUS_SUCCESS ) {

		/* send the last status to all the players */
		while( !IsListEmpty( &g_list_player ) && (l != &g_list_player) ) {
			pJ = (PSPLAYER) l;

			if( pJ->is_player && pJ->fd != 1)
				net_printf(pJ->fd,TOKEN_STATUS"=%s\n",strout);

			l = LIST_NEXT(l);
		}
	}

	/* delete disconn players */
	player_map( player_delete_discon );

	/* send who is the winner */
	if( winner )
		netall_printf( TOKEN_WINNER"=%d,%d\n",winner->numjug,winner->mission );

	game_new();
}
示例#6
0
文件: main.c 项目: NatTuck/teg
/* Initialize the server for the first game */
void game_init()
{
	player_init();
	color_init();
	pactos_init();
	scores_init();
	xmlscores_load();
	metaserver_init();

	g_game.connections = 0;
	g_game.players = 0;
	g_game.playing = 0;

	/* default values */
	g_game.fichas = 5;
	g_game.fichas2 = 3;
	g_game.mission = FALSE;
	g_game.cmission = TRUE;
	g_game.reglas = TEG_RULES_TEG;
	g_game.fog_of_war = FALSE;
	g_game.player_fow = NULL;

	game_new();
}
示例#7
0
/*
 * adjudicate
 *
 * Usage: adjudicate white_player black_player result
 *
 *   Adjudicates a saved (stored) game between white_player and black_player.
 *   The result is one of: abort, draw, white, black.  "Abort" cancels the game
 *   (no win, loss or draw), "white" gives white_player the win, "black" gives
 *   black_player the win, and "draw" gives a draw.
 */
int com_adjudicate(int p, param_list param)
{
  int wp, wconnected, bp, bconnected, g, inprogress, confused = 0;

  if (!FindPlayer(p, param[0].val.word, &wp, &wconnected))
    return COM_OK;
  if (!FindPlayer(p, param[1].val.word, &bp, &bconnected)) {
    if (!wconnected)
     player_remove(wp);
    return COM_OK;
  }

  inprogress = ((player_globals.parray[wp].game >=0) &&(player_globals.parray[wp].opponent == bp));

  if (inprogress) {
    g = player_globals.parray[wp].game;
  } else {
    g = game_new();
    if (game_read(g, wp, bp) < 0) {
      confused = 1;
      pprintf(p, "There is no stored game %s vs. %s\n", player_globals.parray[wp].name, player_globals.parray[bp].name);
    } else {
      game_globals.garray[g].white = wp;
      game_globals.garray[g].black = bp;
    }
  }
  if (!confused) {
    if (strstr("abort", param[2].val.word) != NULL) {
      game_ended(g, WHITE, END_ADJABORT);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been aborted.",
	       player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been aborted.",
	       player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);
    } else if (strstr("draw", param[2].val.word) != NULL) {
      game_ended(g, WHITE, END_ADJDRAW);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a draw", player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a draw", player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);
    } else if (strstr("white", param[2].val.word) != NULL) {
      game_ended(g, WHITE, END_ADJWIN);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a win", player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a loss", player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);
    } else if (strstr("black", param[2].val.word) != NULL) {
      game_ended(g, BLACK, END_ADJWIN);
      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a loss", player_globals.parray[wp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);

      pcommand(p, "message %s Your game \"%s vs. %s\" has been adjudicated "
	       "as a win", player_globals.parray[bp].name, player_globals.parray[wp].name, player_globals.parray[bp].name);
    } else {
      confused = 1;
      pprintf(p, "Result must be one of: abort draw white black\n");
    }
  }
  if (!confused) {
    pprintf(p, "Game adjudicated.\n");
    if (!inprogress) {
      game_delete(wp, bp);
    } else {
      return (COM_OK);
    }
  }
  game_remove(g);
  if (!wconnected)
    player_remove(wp);
  if (!bconnected)
    player_remove(bp);
  return COM_OK;
}
示例#8
0
int com_match(int p, param_list param)
{
  struct player *pp = &player_globals.parray[p];
  int adjourned;                /* adjourned game? */
  int g;                        /* more adjourned game junk */
  int p1;
  int bh = 0, partner = 0, pp1 = 0;
  struct pending* pendfrom;
  struct pending* pendto;
  struct pending* pend;
  int wt = -1;                  /* white start time */
  int winc = -1;                /* white increment */
  int bt = -1;                  /* black start time */
  int binc = -1;                /* black increment */
  int rated = -1;               /* 1 = rated, 0 = unrated */
  int white = -1;               /* 1 = want white, 0 = want black */
  char category[100], board[100];
  textlist *clauses = NULL;
  int type = 0;

  category[0] ='\0';
  board[0] ='\0';

  if ((pp->game >= 0) && ((game_globals.garray[pp->game].status == GAME_EXAMINE)
|| (game_globals.garray[pp->game].status == GAME_SETUP))) {

    pprintf(p, "You can't challenge while you are examining a game.\n");
    return COM_OK;
  }

  if (pp->game >= 0) {
    pprintf(p, "You can't challenge while you are playing a game.\n");
    return COM_OK;
  }

  /* Makes sure that the user has not been ratebanned - Added by johnthegreat*/
  if (in_list(p, L_RATEBAN, player_globals.parray[p].name))
  {
  	pprintf_prompt(p,"You are banned from playing rated games.");
   	return COM_OK;
  }

  stolower(param[0].val.word);
  p1 = player_find_part_login(param[0].val.word);
  if (p1 < 0) {
    pprintf(p, "No user named \"%s\" is logged in.\n", param[0].val.word);
    return COM_OK;
  }

  if (p1 == p) {                /* Allowing to match yourself to enter
                                   analysis mode */
    //ExamineScratch (p, param, 0);
    	pprintf(p, "Your can not match yourself.\n");
	return COM_OK;
  }

  if (!CheckPFlag(p1, PFLAG_OPEN)) {
    pprintf(p, "Player \"%s\" is not open to match requests.\n", player_globals.parray[p1].name);
    return COM_OK;
  }

  if (player_globals.parray[p1].game >= 0) {
    pprintf(p, "Player \"%s\" is playing a game.\n", player_globals.parray[p1].name);    return COM_OK;
  }

  if (CheckPFlag(p, PFLAG_TOURNEY) && !CheckPFlag(p1, PFLAG_TOURNEY)) {
    pprintf(p, "You may only match players with their tournament variable set.\n");
    return COM_OK;
  }

  if (!CheckPFlag(p, PFLAG_TOURNEY) && CheckPFlag(p1, PFLAG_TOURNEY)) {
    pprintf(p, "%s is in a tournament, and cannot accept other challenges.\n", player_globals.parray[p1].name);
    return COM_OK;
  }

	if (!net_globals.con[pp->socket]->timeseal)
	{
		return COM_OK;

	}
  if (!CheckPFlag(p, PFLAG_OPEN)) {
    PFlagON(p, PFLAG_OPEN);
    pprintf(p, "Setting you open for matches.\n");
  }


/* look for an adjourned game between p and p1 */
  g = game_new();
  adjourned = (game_read(g, p, p1) >= 0) || (game_read(g, p1, p) >= 0);
  if (adjourned) {
    type = game_globals.garray[g].type;
    wt = game_globals.garray[g].wInitTime / 60000;
    bt = game_globals.garray[g].bInitTime / 60000;
    winc = game_globals.garray[g].wIncrement / 1000;
    binc = game_globals.garray[g].bIncrement / 1000;
    rated = game_globals.garray[g].rated;
  }
  game_remove(g);

  pendto = find_pend(p, p1, PEND_MATCH);

  pendfrom = find_pend(p1, p, PEND_MATCH);

  if (!adjourned) {
      if (player_censored(p1, p))
        {
          pprintf(p, "Player \"%s\" is censoring you.\n",
              player_globals.parray[p1].name);
          return COM_OK;
        }
      if (player_censored(p, p1))
        {
          pprintf(p, "You are censoring \"%s\".\n",
              player_globals.parray[p1].name);
          return COM_OK;
        }
    if (in_list(p1, L_NOPLAY, pp->name)) {
      pprintf(p, "You are on %s's noplay list.\n", player_globals.parray[p1].name);
      return COM_OK;
    }
    if (in_list(p, L_NOPLAY, player_globals.parray[p1].name)) {
      pprintf(p, "You have %s on your noplay list.\n", player_globals.parray[p1].name);
      return COM_OK;
    }

    /* Makes sure that the opponent has not been ratebanned - Added by johnthegreat*/
    if (in_list(p1, L_RATEBAN, player_globals.parray[p1].name))
    {
    	pprintf(p,"%s has been banned from playing rated games.",player_globals.parray[p1].name);
    	return COM_OK;
    }

    if (CheckPFlag(p1, PFLAG_WHITELIST) && !player_isAllowedPlay(p1, p)) {
        struct player *pp2 = player_getStruct(p1);
        pprintf(p, "%s is not allowing requests from you.\n", pp2->name);
        return COM_OK;
    }

    if (param[1].type != TYPE_NULL) {
      if (!parse_match_string(p, &wt,&bt,&winc,&binc,&white,&rated,category,
                                                  board,param[1].val.string))

	  return COM_OK; /* couldn't parse */
    }

    if (rated == -1)
      rated = BoolCheckPFlag(p, PFLAG_RATED);
    if (!CheckPFlag(p, PFLAG_REG) || !CheckPFlag(p1, PFLAG_REG))
      rated = 0;

    if (winc == -1)
      winc = (wt == -1) ? pp->d_inc : 0;  /* match 5 == match 5 0 */

    if (wt == -1)
      wt = pp->d_time;

    if (bt == -1)
      bt = wt;

    if (binc == -1)
      binc = winc;

    if (category[0])
	{
			if (!board[0] && strcmp(category,"bughouse") && strcmp(category,"zh"))
			{
				pprintf(p, "You must specify a board and a category.\n");
				return COM_OK;
			} else if (board[0])
			{
				char fname[MAX_FILENAME_SIZE];

				if (!strcmp(board,"FR"))
					sprintf(fname, "%s/%s", BOARD_DIR, board);
				else
					sprintf(fname, "%s/%s/%s", BOARD_DIR, category, board);

				if (!file_exists(fname))
				{
					pprintf(p, "No such category/board: %s/%s\n", category, board);
					return COM_OK;
				}
			}
    }
    type = game_isblitz(category,board);

    if (type == TYPE_BUGHOUSE) {
      if (rated && pp->partner >= 0 && player_globals.parray[p1].partner >= 0) {
        if (!CheckPFlag(pp->partner, PFLAG_REG)
              || !CheckPFlag(player_globals.parray[p1].partner, PFLAG_REG))
          rated = 0;
      }
    }
    if (rated && (type == TYPE_NONSTANDARD)) {
      pprintf(p, "Game is non-standard - reverting to unrated\n");
      rated = 0;
    }
    if (rated && (type == TYPE_UNTIMED)) {
      pprintf(p, "Game is untimed - reverting to unrated\n");
      rated = 0;
    }
    if ((pendfrom == NULL) && !CheckPFlag(p1, PFLAG_ROPEN)
        && (rated != BoolCheckPFlag(p1, PFLAG_RATED))) {
      pprintf(p, "%s only wants to play %s games.\n", player_globals.parray[p1].name,
              rstr[!rated]);
      pprintf_highlight(p1, "Ignoring");
      pprintf(p1, " %srated match request from %s.\n",
              (rated ? "" : "un"), pp->name);
      return COM_OK;
    }

    /* Now check formula. */
    if (!adjourned
        && !GameMatchesFormula(p,p1, wt,winc,bt,binc, rated, type, &clauses)) {
      pprintf(p, "Match request does not fit formula for %s:\n",
              player_globals.parray[p1].name);
      pprintf(p, "%s's formula: %s\n", player_globals.parray[p1].name, player_globals.parray[p1].formula);
      ShowClauses (p, p1, clauses);
      ClearTextList(clauses);
      pprintf_highlight(p1, "Ignoring");
      pprintf_prompt(p1, " (formula): %s (%d) %s (%d) %s.\n",
                     pp->name,
                     GetRating(&player_globals.parray[p], type),
                     player_globals.parray[p1].name,
                     GetRating(&player_globals.parray[p1], type),
            game_str(rated, wt * 60, winc, bt * 60, binc, category, board));
      return COM_OK;
    }

    if (type == TYPE_BUGHOUSE) {
      bh = 1;
      partner = pp->partner;
      pp1 = player_globals.parray[p1].partner;

      if (pp < 0) {
        pprintf(p, "You have no partner for bughouse.\n");
        return COM_OK;
      }
      if (pp1 < 0) {
        pprintf(p, "Your opponent has no partner for bughouse.\n");
        return COM_OK;
      }
      if (partner == pp1) { /* should be an impossible case - DAV */
        pprintf(p, "You and your opponent both chose the same partner!\n");
        return COM_OK;
      }
      if (partner == p1 || pp1 == p) {
        pprintf(p, "You and your opponent can't choose each other as partners!\n");
        return COM_OK;
      }
      if (player_globals.parray[partner].partner != p) { /* another impossible case - DAV */
        pprintf(p, "Your partner hasn't chosen you as his partner!\n");
        return COM_OK;
      }
      if (player_globals.parray[pp1].partner != p1) { /* another impossible case - DAV */
        pprintf(p, "Your opponent's partner hasn't chosen your opponent as his partner!\n");
        return COM_OK;
      }
      if (!CheckPFlag(partner, PFLAG_OPEN) || player_globals.parray[partner].game >= 0) {
        pprintf(p, "Your partner isn't open to play right now.\n");
        return COM_OK;
      }
      if (!CheckPFlag(pp1, PFLAG_OPEN) || player_globals.parray[pp1].game >= 0) {
        pprintf(p, "Your opponent's partner isn't open to play right now.\n");
        return COM_OK;
      }

      /* Bypass NOPLAY lists, censored lists, ratedness, privacy, and formula for now */
      /*  Active challenger/ee will determine these. */
    }
    /* Ok match offer will be made */

  }                             /* adjourned games shouldn't have to worry
                                   about that junk? */
				/* keep incase of adjourned bughouse in future*/

  if (pendto != NULL) {
    pprintf(p, "Updating offer already made to \"%s\".\n", player_globals.parray[p1].name);
  }

  if (pendfrom != NULL) {
    if (pendto != NULL) {
      pprintf(p, "Pending list error!.\n");
      d_printf( "CHESSD: This shouldn't happen. You can't have a match pending from and to the same person.\n");
      return COM_OK;
    }

    if (adjourned || ((wt == pendfrom->btime) &&
                      (winc == pendfrom->binc) &&
                      (bt == pendfrom->wtime) &&
                      (binc == pendfrom->winc) &&
                      (rated == pendfrom->rated) &&
                      ((white == -1) || (white + pendfrom->seek_color == 1)) &&
               (!strcmp(category, pendfrom->category)) &&
                 (!strcmp(board, pendfrom->board_type)))) {
      /* Identical match, should accept! */
      accept_match(pendfrom,p, p1);
      return COM_OK;

    } else {
      delete_pending(pendfrom);
    }
  }

  if (pendto == NULL)
    pend = add_pending(p,p1,PEND_MATCH);
  else
    pend = pendto;

  pend->wtime = wt;
  pend->winc = winc;
  pend->btime = bt;
  pend->binc = binc;
  pend->rated = rated;
  pend->seek_color = white;
  pend->game_type = type;
  pend->category = strdup(category);
  pend->board_type = strdup (board);

  if (pendfrom != NULL) {
    pprintf(p, "Declining offer from %s and offering new match parameters.\n", player_globals.parray[p1].name);
    pprintf(p1, "\n%s declines your match offer a match with these parameters:", pp->name);
  }

  if (pendto != NULL) {
    pprintf(p, "Updating match request to: ");
    pprintf(p1, "\n%s updates the match request.\n", pp->name);
  } else {
    pprintf(p, "Issuing: ");
    pprintf(p1, "\n");
  }

  pprintf(p, "%s (%s) %s", pp->name,
          ratstrii(GetRating(&player_globals.parray[p], type), p),
          colorstr[white + 1]);
  pprintf_highlight(p, "%s", player_globals.parray[p1].name);
  pprintf(p, " (%s) %s%s.\n",
          ratstrii(GetRating(&player_globals.parray[p1], type), p1),
          game_str(rated, wt , winc, bt , binc, category, board),
          adjustr[adjourned]);
  pprintf(p1, "Challenge: ");
  pprintf_highlight(p1, "%s", pp->name);
  pprintf(p1, " (%s) %s",
          ratstrii(GetRating(&player_globals.parray[p], type), p),
          colorstr[white + 1]);
  pprintf(p1, "%s (%s) %s%s.\n", player_globals.parray[p1].name,
          ratstrii(GetRating(&player_globals.parray[p1], type), p1),
          game_str(rated, wt , winc, bt , binc, category, board),
          adjustr[adjourned]);
  Bell (p1);

  if (bh) {

    pprintf(partner, "\nYour bughouse partner issuing %s (%s) %s",
            pp->name, ratstrii(GetRating(&player_globals.parray[p], type), p),
            colorstr[white + 1]);
    pprintf_highlight(partner, "%s", player_globals.parray[p1].name);
    pprintf(partner, " (%s) %s.\n",
            ratstrii(GetRating(&player_globals.parray[p1], type), p1),
            game_str(rated, wt , winc, bt , binc, category, board));
    pprintf(partner, "Your game would be ");
    pprintf_highlight(partner, "%s", player_globals.parray[pp1].name);
    pprintf_prompt(partner, " (%s) %s%s (%s) %s.\n",
          ratstrii(GetRating(&player_globals.parray[pp1], type), pp1),
          colorstr[white + 1], player_globals.parray[partner].name,
          ratstrii(GetRating(&player_globals.parray[partner], type), partner),
          game_str(rated, wt , winc, bt , binc, category, board));
    Bell (partner);

    pprintf(pp1, "\nYour bughouse partner was challenged ");
    pprintf_highlight(pp1, "%s", pp->name);
    pprintf(pp1, " (%s) %s", ratstrii(GetRating(&player_globals.parray[p], type), p),
                             colorstr[white + 1]);
    pprintf(pp1, "%s (%s) %s.\n", player_globals.parray[p1].name,
            ratstrii(GetRating(&player_globals.parray[p1], type), p1),
            game_str(rated, wt , winc, bt , binc, category, board));
    pprintf(pp1, "Your game would be %s (%s) %s", player_globals.parray[pp1].name,
          ratstrii(GetRating(&player_globals.parray[pp1], type), pp1),
          colorstr[white + 1]);
    pprintf_highlight(pp1, "%s", player_globals.parray[partner].name);
    pprintf_prompt(pp1, " (%s) %s.\n",
          ratstrii(GetRating(&player_globals.parray[partner], type), partner),
          game_str(rated, wt , winc, bt , binc, category, board));
    Bell(pp1);
  }

  check_lists_match (p,p1);

  print_match_rating_info (p,p1,type,rated);

  pprintf_prompt(p1, "You can \"accept\" or \"decline\", or propose different parameters.\n");

  return COM_OK;
}
示例#9
0
int accept_match(struct pending *pend, int p, int p1)
{
	struct player *pp = &player_globals.parray[p];
	int wt, winc, bt, binc, rated, white;
	char category[50], board[50];
	char tmp[100];
	int bh = 0, partner = 0, pp1 = 0, g1;

	unobserveAll(p);              /* stop observing when match starts */
	unobserveAll(p1);
	wt = pend->wtime;
	winc = pend->winc;
	bt = pend->btime;
	binc = pend->binc;
	rated = pend->rated;
	strcpy (category, pend->category);
	strcpy (board, pend->board_type);
	white = (pend->seek_color == -1) ? -1 : 1 - pend->seek_color;

	pprintf(p, "You accept the challenge of %s.\n", player_globals.parray[p1].name);
	pprintf(p1, "\n%s accepts your challenge.\n", pp->name);


	if(!pend->status)
		delete_pending(pend);

	withdraw_seeks(p);
	withdraw_seeks(p1);

	pend_join_match (p,p1);




	player_globals.parray[p1].last_category = strdup(category);
	player_globals.parray[p1].last_board = strdup(board);
	player_globals.parray[p].last_category = strdup(category);
	player_globals.parray[p].last_board = strdup(board);

	if (game_isblitz(category,board) == TYPE_BUGHOUSE)
	{
		bh = 1;

		if ((partner = pp->partner) >= 0 &&
			(pp1 = player_globals.parray[p1].partner) >= 0)
		{
			unobserveAll(partner);         /* stop observing when match starts */
			unobserveAll(pp1);
			pprintf(partner, "\nYour partner accepts the challenge of %s.\n", player_globals.parray[p1].name);
			pprintf(pp1, "\n%s accepts your partner's challenge.\n", pp->name);
			pend_join_match (partner,pp1);
		} else
		{
			return COM_OK;
		}
	}

	g1 = game_new(); /* create a game structure */

	if (g1 < 0)
	{
		sprintf(tmp, "There was a problem creating the new match.\n");
		pprintf(p, tmp);
		pprintf_prompt(p1, tmp);
	}

	if (game_read(g1, p1, p) >= 0)
	{
		int swap;
		swap = p;
		p = p1;
		p1 = swap;
		pp = &player_globals.parray[p];
	} else if (game_read(g1, p, p1) < 0)
	{ /* so no adjourned game */

    // Alex Guo: this is creating the match too early. If we are doing bughouse,
    // we need to first create the other board, and THEN create the match
    //if (create_new_match(g1,p, p1, wt, winc, bt, binc, rated, category, board, white,0) == COM_FAILED) {
	//	return COM_OK;
    //}


	/* create first game */
	int g2=-1;

    int g1_white = white;

	if (bh)
	{ /* do bughouse creation */

		g2 = game_new();

        if (g2 < 0)
            return BugMatchErrorHandler(g1, pp1, partner);

		game_globals.garray[g1].link = g2; /* link the games */
		game_globals.garray[g2].link = g1;
		game_globals.garray[g1].databaseLink= g2;
		game_globals.garray[g2].databaseLink = g1;

        if (create_new_match(g1,p, p1, wt, winc, bt, binc, rated, category, board, g1_white,0)
            == COM_FAILED)
            return COM_OK;

		white = (pp->side == WHITE ? 0 : 1);

		player_globals.parray[partner].last_category = strdup(category);
		player_globals.parray[partner].last_board = strdup(board);
		player_globals.parray[pp1].last_category = strdup(category);
		player_globals.parray[pp1].last_board = strdup(board);

		if ((create_new_match(g2,partner, pp1, wt, winc, bt, binc, rated, category, board,white,0)
			== COM_FAILED))
            return BugMatchErrorHandler(g1, pp1, partner);

		sprintf(tmp, "\nYour partner is playing game %d (%s vs. %s).\n",
              g2 + 1, game_globals.garray[g2].white_name, game_globals.garray[g2].black_name);
		pprintf(p, tmp);
		pprintf(p1, tmp);

		sprintf(tmp, "\nYour partner is playing game %d (%s vs. %s).\n",
              g1 + 1, game_globals.garray[g1].white_name, game_globals.garray[g1].black_name);
		pprintf(partner, tmp);
		pprintf(pp1, tmp);

		pfollow_start(partner,  pp1);
		pfollow_start(p, p1);

	}
    else {
        if (create_new_match(g1,p, p1, wt, winc, bt, binc, rated, category, board, g1_white,0)
            == COM_FAILED)
            return COM_OK;
    }

    // Alex Guo: now here, send the information to the clients.
    //if (g1 >= 0) {
    //    gameinfo(p, g1);
    //    gameinfo(p1, g1);
    //    send_boards(g1);
    //}
    //if (g2 >= 0) {
    //    gameinfo(partner, g2);
    //    gameinfo(pp1, g2);
    //    send_boards(g2);
    //}

	return COM_OK;
  }

       /* resume adjourned game */

  game_delete(p, p1); /* remove the game from disk */

  sprintf(tmp, "{Game %d (%s vs. %s) Continuing %s %s match.}\n",
        g1+1, pp->name, player_globals.parray[p1].name,
        rstr[game_globals.garray[g1].rated], bstr[game_globals.garray[g1].type]);
  pprintf(p, tmp);
  pprintf(p1, tmp);
  output_match_messages(p, p1, g1, "Continuing");

  game_globals.garray[g1].white = p;
  game_globals.garray[g1].black = p1;
  game_globals.garray[g1].status = GAME_ACTIVE;
  game_globals.garray[g1].result = END_NOTENDED;
  game_globals.garray[g1].startTime = tenth_secs2();
  game_globals.garray[g1].lastMoveTime = game_globals.garray[g1].startTime;
  game_globals.garray[g1].lastDecTime = game_globals.garray[g1].startTime;
  pp->game = g1;
  pp->opponent = p1;
  pp->side = WHITE;
  player_globals.parray[p1].game = g1;
  player_globals.parray[p1].opponent = p;
  player_globals.parray[p1].side = BLACK;

  send_boards(g1);

  /* obey any 'follow' lists */
  //follow_start(p,p1);

  return COM_OK;
}