示例#1
0
文件: yahtzee.c 项目: GNOME/tali
/* Test if we can use suggested score slot */
int
play_score (int player, int field)
{
  int i;

  /* Special case for yahtzee, allow multiple calls if 1st wasn't 0 */

  /* This, however, was broken: it didn't actually check to see if the
   * user had a yahtzee if this wasn't their first time clicking on it.
   * Bad. -- [email protected] */
  if (field == 11 && game_type == GAME_YAHTZEE) {
    if ((players[player].used[11] && (players[player].score[11] == 0)))
      return SLOT_USED;

    if ((players[player].used[11] && !find_yahtzee ()))
      return SLOT_USED;
  } else if (players[player].used[field])
    return SLOT_USED;

  players[player].used[field] = 1;
  players[player].score[field] = players[player].score[field] + field_score (field);
  PrependUndoList (player, field, players[player].score[field]);

  ShowPlayer (player, field);

  for (i = 0; i < NUM_FIELDS; ++i)
    if (!players[player].used[i])
      return SCORE_OK;

  players[player].finished = 1;

  return SCORE_OK;
}
示例#2
0
文件: yahtzee.c 项目: GNOME/tali
gint
player_field_score (gint player, gint field)
{
  /* A player can still score in H_YA even if it's used in the
   * regular game, but only if they have a non-zero value there */
  if (field == H_YA && game_type == GAME_YAHTZEE) {
    if (players[player].used[field]) {
      if (field_score (field) > 0 && players[player].score[field] > 0)
        return field_score (field);
      else
        return -1;
    }
  }
  else if (players[player].used[field])
    return -1;

  return field_score (field);
}
示例#3
0
static void
BuildTable (int player)
{
  int i;
  int d;

  for (i = 0; i < NUM_FIELDS; ++i) {
    bc_table[i] = 0;
    if (players[player].used[i]) {
      bc_table[i] = -99;
    }
  }

/*
**	HANDLING UPPER SLOTS
*/

  for (i = 0; i < NUM_UPPER; ++i) {
    if (players[player].used[i])
      continue;

/*
**	ok. now we set a base value on the roll based on its count and
**	how much it is worth to us.
*/
    bc_table[i] = (count (i + 1) - 2) * (i + 1) * 4 - (i + 1);
  }

/*
**	HANDLING LOWER SLOTS
*/

/*
**	now we look hard at what we got
*/

  /* Small straight */
  if (H_SS > 0 && !players[player].used[H_SS]) {
    d = field_score (H_SS);
    if (d) bc_table[H_SS] = d;
  }

  /* Large straight */
  if (!players[player].used[H_LS]) {
    bc_table[H_LS] = field_score (H_LS);
  }

  /* chance - sum of all dice */
  /* Lower this, because we'd rather score somewhere else when we can */
  if (!players[player].used[H_CH] && NumberOfRolls > 2) {
    bc_table[H_CH] = field_score (H_CH) / 2;
  }

  /* Full house */
  if (!players[player].used[H_FH]) {
    bc_table[H_FH]  = field_score (H_FH);
  }

  /* Two pair same color */
  if (H_2P > 0 && !players[player].used[H_2P]) {
    bc_table[H_2P] = field_score (H_2P);
  }

  /* Full house same color */
  if (H_FS > 0 && !players[player].used[H_FS]) {
    bc_table[H_FS]  = field_score (H_FS);
  }

  /* Flush - all same color */
  if (H_FL > 0 && !players[player].used[H_FL]) {
    bc_table[H_FL]  = field_score (H_FL);
  }

  /* 3 of a kind */
  if (!players[player].used[H_3]) {
    bc_table[H_3]  = field_score (H_3);
  }

  /* 4 of a kind */
  if (!players[player].used[H_4]) {
    /* Add one to break tie with 3 of a kind */
    bc_table[H_4] = field_score (H_4) + 1;
  }

  /* 5 of a kind */

  if (players[player].used[H_YA] && (players[player].score[H_YA] == 0 || game_type == GAME_KISMET)) {
      bc_table[H_YA] = -99;
  }
  else if (find_n_of_a_kind (5, 0)) {
      bc_table[H_YA] = 150;	/* so he will use it! */
  }

  if (DisplayComputerThoughts) {
    for (i = 0; i < NUM_FIELDS; ++i) {
      printf ("%s : SCORE = %d\n", _(FieldLabels[i]), bc_table[i]);
    }
  }
}