Logo Search packages:      
Sourcecode: mathwar version File versions  Download package

void begin_game ( game_engine *  game  ) 

Perform initialization required before each game.

A "game" is defined as a full set of "rounds". A "round" is two cards, and an operation. The number of rounds in a game is settable by the user.

This function should be called before the start of each game.

Parameters:
game A pointer to the game instance.
Returns:
Nothing.

Definition at line 537 of file game_engine.c.

References ADDITION, MULTIPLICATION, and SUBTRACTION.

{
   gint       i;
   gint       tmp_int;
   gint       cur_end;

   reset_player (game->player1);
   reset_player (game->player2);

   game->num_rounds = ini_get_int (PACKAGE, BASIC_PARMS,  
                                   NUM_ROUNDS, DEF_NUM_ROUNDS);

   game->cur_timer = -1;
   game->timer_is_active = FALSE;
   game->tick = 0;

   game->round_tick_len = ini_get_int (PACKAGE, BASIC_PARMS, 
                                       SECONDS, DEF_SECONDS) * TICKS_PER_SEC;
   game->comp_guess_tick = 0;

   tmp_int = ini_get_int (PACKAGE, COMP_PLAYER, GUESS_TIME, DEF_TIME);
   game->comp_avg_guess_tick = (gint) (game->round_tick_len * tmp_int / 100);

   tmp_int = ini_get_int (PACKAGE, COMP_PLAYER,
                          MAX_DEVIATION, DEF_MAX_DEV);
   game->comp_guess_tick_max_dev = 
      (gint) (game->round_tick_len * tmp_int / 100);

   /*
    * The game engine uses "bags of marbles" to determine events that
    * depend upon user defined probabilities.  Setup those bags of 
    * marbles.
    *
    * card arrays, random between 0 and user defined max 
    */
   tmp_int = ini_get_int (PACKAGE, OPERATORS, ADD_MAX, DEF_ADD_MAX);
   fill_int_array (game->add_cards, NUM_MARBLES, 0, tmp_int);

   tmp_int = ini_get_int (PACKAGE, OPERATORS, SUB_MAX, DEF_SUB_MAX);
   fill_int_array (game->sub_cards, NUM_MARBLES, 0, tmp_int);

   tmp_int = ini_get_int (PACKAGE, OPERATORS, MULT_MAX, DEF_MULT_MAX); 
   fill_int_array (game->mult_cards, NUM_MARBLES, 0, tmp_int);

   /* percent of rounds that are add, sub and mult */
   tmp_int = ini_get_int (PACKAGE, OPERATORS, SUB_PCT, DEF_SUB_PCT);
   for (i = 0; i < tmp_int; i++)
      {
      game->operator_pool[i] = (gint)SUBTRACTION;
      }
   cur_end = tmp_int;

   tmp_int = ini_get_int (PACKAGE, OPERATORS, MULT_PCT, DEF_MULT_PCT);
   for (i = cur_end; i < cur_end + tmp_int; i++)
      {
      game->operator_pool[i] = (gint)MULTIPLICATION;
      }
   cur_end += tmp_int;

   for (i = cur_end; i < NUM_MARBLES; i++)
      {
      game->operator_pool[i] = (gint)ADDITION;
      }

   /* Computer guess deviation (zero deviations are correct guesses). */
   tmp_int = ini_get_int (PACKAGE, COMP_PLAYER, RIGHT_PCT, DEF_RIGHT_PCT);
   cur_end = NUM_MARBLES - tmp_int;
   tmp_int = ini_get_int (PACKAGE, COMP_PLAYER, GUESS_DEV, DEF_GUESS_DEV);
   fill_int_array (game->guess_diff, cur_end, 1, tmp_int);
   for (i = cur_end; i < NUM_MARBLES; i++)
      {
      game->guess_diff[i] = 0;
      }

   /* Computer guess pct */
   tmp_int = ini_get_int (PACKAGE, COMP_PLAYER, GUESS_PCT, DEF_GUESS_PCT); 
   for (i = 0; i < tmp_int; i++)
      {
      game->computer_guess[i] = TRUE;
      }
   for (i = tmp_int; i < NUM_MARBLES; i++)
      {
      game->computer_guess[i] = FALSE;
      }
}


Generated by  Doxygen 1.6.0   Back to index