Ejemplo n.º 1
0
int main(int argc, char ** argv) {
#ifdef _WIN32
	srand (time(NULL));
#endif
	bool quiet = false;
	int tomes = 0, grims = 0, bdice = 0, c;
	while ((c = getopt(argc, argv, "ht:g:b:q")) != -1) {
		switch (c) {
			case 'h':
				print_usage(argv[0]);
				exit(EXIT_SUCCESS);
				break;
			case 't':
				tomes = safe_atoi(optarg);
				break;
			case 'g':
				grims = safe_atoi(optarg);
				break;
			case 'b':
				bdice = safe_atoi(optarg);
				break;
			case 'q':
				quiet = true;
				break;
		}
	}
	check_inputs(tomes, grims, bdice);
	roll_dice(tomes, grims, bdice, quiet);
}
Ejemplo n.º 2
0
Archivo: sinap.c Proyecto: mkopta/sinap
void sinap(void)
{
	U score_limit = 1000U, accG, accL, dice_count, r_dice_count;
	UC dice[6];
	int c;
	Occurrences o;
	Player a = {0, "A", 0}, b = {1, "B", 0},
	       *p = random_number(0,1) == 0 ? &a : &b;

	while (a.score < score_limit && b.score < score_limit) {
		printf("\nScore: '%s'=%u '%s'=%u. Press enter to continue..",
				a.name, a.score, b.name, b.score);
		(void) fflush(stdout);
		while (getchar() != '\n');
		/* switch player */
		p = p->id == a.id ? &b : &a;
		accG = accL = 0;
		dice_count = r_dice_count = 6U;
		while (1) {
			printf("Player '%s' rolls: ", p->name);
			roll_dice(dice, dice_count);
			print_dice(dice, dice_count);
			o = calculate_occurrences(dice, dice_count);
			accL = calc_score(o);
			r_dice_count = remaining_dice(o, dice_count);
			printf(" ## s=%u ", accL);
			if (accL > 0) {
				printf("S=%u ", accL + accG);
				printf("t=%u ", p->score);
				printf("T=%u ", accL + accG + p->score);
				printf("r=%u", r_dice_count);
			}
			putchar('\n');
			if (accL == 0) {
				break;
			} else {
				dice_count = r_dice_count;
				accG += accL;
				if (accG + p->score > score_limit) {
					p->score += accG;
					break;
				}
			}
			if (!(p->score == 0 && accG < 35)) {
				printf("Continue? [Y/n]: ");
				(void) fflush(stdout);
				c = getchar();
				if (c != '\n')
					while (getchar() != '\n');
				if (c == 'n') {
					p->score += accG;
					break;
				}
			}
		}
	}

	printf("Player '%s' wins with score %u.\n", p->name, p->score);
}
bool play_game(void)
{
  int dice, point;
  switch (point = roll_dice()) {
    case 7: case 11: printf("You win!\n"); return true;
    case 2: case 3: case 12: printf("You lose!\n"); return false;
  }
  printf("Your point is %d\n", point);

  for (;;) {
    dice = roll_dice();
    if (dice == point) {
      printf("You win!\n");
      return true;
    } else if (dice == 7) {
      printf("You lose!\n");
      return false;
    }
  }
}
Ejemplo n.º 4
0
int roll_dice_ex(const std::string& die)
{
  int bonus = 0;
  auto dice_and_bonus = split_string(die, '+');
  if (dice_and_bonus.size() >= 2)
  {
    bonus = atoi(dice_and_bonus[1].c_str());
  }

  return roll_dice( dice_and_bonus[0] ) + bonus;
}
Ejemplo n.º 5
0
void
kaimen(Taku *taku)
{
    Yama *yama;
    unsigned me0, me1, me;
    unsigned wareme;

    yama = &taku->yama;
    me0 = roll_dice();
    me1 = roll_dice();
    me = me0 + me1 + 2;
    fput_dice(stdout, me0);
    fput_dice(stdout, me1);
    key_break();
    wareme = mod136_restrict(
            (oya(taku) + me - 1) * (N_PAI/N_PLAYER) - 2 * me);
    yama->wareme_idx = wareme;
    yama->tsumo_idx = wareme;
    yama->rinshan_idx = wareme;
}
Ejemplo n.º 6
0
void turn (int score[], int dice_values[], int size, int num_values[])
{
//Saw redundancy in the code, so instead of copy and pasting this 26 times, I made it into a function
printf("Roll 1\n");
roll_dice(dice_values, size);
show_dice(dice_values, size);
reroll(dice_values, size);
printf("Roll 2\n");
show_dice(dice_values, size);
reroll(dice_values, size);
printf("Roll 3\n");
show_dice(dice_values, size);
}
Ejemplo n.º 7
0
void creature_t::apply_poison_to()
{
  if (!(get_active_effects_for(this) & EF_POISON))
  {
    int poison_resistance = compute_resistance(ELEMENT_POISON);
    int poison_roll = roll_dice("1d100");

    if (poison_roll > poison_resistance)
    {
      create_effect(this, EF_POISON, 8, 1);
    }
  }
}
Ejemplo n.º 8
0
bool play_game(void){
	
/*	bool result = false;*/
	int point, roll;	
	
	roll = roll_dice();
	printf ("You rolled: %d\n", roll);
	
	switch (roll){
		case (7): case (11): return true;
		case (2): case (3): case (12): return false;
		default: point = roll; printf ("Your point is %d\n", point); break;
	}
	
	roll = roll_dice();
	printf ("You rolled: %d\n", roll);
	
	while ( roll != point){		
		roll= roll_dice();
		printf ("You rolled: %d\n", roll);
	}
	
	return true;
}
Ejemplo n.º 9
0
bool spell_mind_blade( char_data* ch, char_data* victim, void*,
  int level, int )
{
  int dam;

  if( ch == NULL ) {
    bug( "Mind_Blade: NULL caster." );
    return TRUE;
    }
 
  dam = ch->shdata->level > 20 ? 20 : ch->shdata->level;

  damage_mind( victim, ch, roll_dice( 2+level/2, dam ),
    "*The mind blade" );

  return TRUE;
}
Ejemplo n.º 10
0
void struggle_web( char_data* ch )
{
  affect_data* affect;

  for( int i = 0; ; i++ ) {
    if( i > ch->affected ) {
      bug( "Execute_Web: Entangled Character with no affect." );
      remove_bit( ch->affected_by, AFF_ENTANGLED );
      return;
      }
    if( ch->affected[i]->type == AFF_ENTANGLED ) {
      affect = ch->affected[i];
      break;
      }
    }

  if( roll_dice( 2,7 )+number_range( 0, affect->level ) < ch->Strength( ) )
    strip_affect( ch, AFF_ENTANGLED );
}
Ejemplo n.º 11
0
/*TRACE A RANDOM PATH AROUND THE SCREEN*/
void turtle_random_walk(turtle_t *t, pen_t *p, int steps){
	int i;
	color_t cc;
	for(i=0; i<steps; i++){
		int rndm = roll_dice(1, 4);
		if(rndm==1){
			turtle_walk(t, 10);
		}
		else if(rndm==2){
			turtle_turn(t, 90);
		}
		else if(rndm==3){
			turtle_turn(t, -90);
		}
		else{
			cc.r = (rand()%10)*0.1;
			cc.g = (rand()%10)*0.1;
			cc.b = (rand()%10)*0.1;
			pen_set_rgb(p, cc);
		}
	}
	return;
}/*END turtle_random_walk*/
Ejemplo n.º 12
0
size_t AmbushEvent::success() {
  srand(static_cast<unsigned int>(time(0)));
  // following consts may be tweaked to change game mechanics
  const size_t MORALE_BOOST = 15;
  const size_t MIN_SLAVES = 3;
  const size_t MAX_SLAVES = 5;
  const size_t ITEM_CHANCE = 30;
  const size_t OTHER_TROPHIES = 4;
  size_t slaves_count = rand() % (MAX_SLAVES - MIN_SLAVES) + MIN_SLAVES;
  for (size_t i = 0; i < slaves_count; ++i) {
    add_slave();
  }
  for (size_t i = 0; i < OTHER_TROPHIES; ++i) {
    size_t roll;
    roll_dice(roll);
    if (roll < ITEM_CHANCE) {
      add_random_item();
    } else {
      add_random_resource();
    }
  }
  return EO_SUCCESS;
}
Ejemplo n.º 13
0
int chaos_bs_dup_p(void)
{
    return roll_dice(config_chaos_p_bsamp_dup);
}
Ejemplo n.º 14
0
void creature_t::zombify(bool zombie)
{
  if (!(flag & CF_LEAVES_CORPSE))
    return;

  flag |= CF_UNDEAD;
  flag |= CF_MINDLESS;

  flag &= ~(CF_SPEAKS);
  flag &= ~(CF_LEAVES_CORPSE);
  flag &= ~(CF_INTELLIGENT);
  flag &= ~(CF_SPELLCASTER);

  band_leader = nullptr;
  spellbook.number_of_spells = 0;
  symbol.glyph = 'z';

  resistance[ELEMENT_FROST] = 100;
  resistance[ELEMENT_HOLY] = -50;
  resistance[ELEMENT_POISON] = 100;
  resistance[ELEMENT_EVIL] = 100;
  resistance[ELEMENT_ELECTRIC] = 50;

  for (item_t* item : inventory)
  {
    item_t::destroy_item(item);
  }
  inventory.clear();

  for (int i = 0; i < MAX_EQUIP; i++)
  {
    if (equipment[i])
    {
      item_t::destroy_item(equipment[i]);
      equipment[i] = nullptr;
    }
  }

  if (zombie)
  {
    strcat(name, " zombie");
    symbol.color = color_brown;
    speed += 25;

    hp.max += roll_dice("2d6");
    hp.cur = hp.max;

    base_ac += 5;
    base_ev -= 5;
    base_damage += 2;
    base_tohit -= 2;

    challenge_rating += 0.5;
  }
  else
  {
    strcat(name, " skeleton");
    symbol.color = color_white;
    speed += 15;

    hp.max -= roll_dice("1d6");

    if (hp.max < 0)
      hp.max = 1;

    hp.cur = hp.max;

    base_ac -= 2;
    base_damage -= 1;
    base_tohit -= 1;

    challenge_rating -= 0.5;
  }

  if (base_ac < 0) base_ac = 0;
  if (base_ev < 0) base_ev = 0;
  if (challenge_rating <= 0) challenge_rating = 0.1;

  if (speed > SPEED_SNAIL)
    speed = SPEED_SNAIL;
}
Ejemplo n.º 15
0
/*!
 * \brief        Roll dices and compute expressions
 * \param[node]  The root of the expression tree to compute
 * \param[print] Set to true to print the result of the expression
 * \return       The expression value
 */
int roll_expression ( struct ir_node * node, int print ) {

  int  high;
  int  i;
  int  limit;
  int  low;
  int  repetitions;
  int  return_value = 0;
  int  sides;
  int  tmp;
  int * results;

  struct ir_node * cur;

  cur = node;
  while (cur != NULL) {

    int sum = 0;

    switch (cur->op) {
    
    case OP_NUMBER:
      sum = cur->value;
      break;

    case OP_REP:

      for (i = 0; i < roll_expression(cur->left, FALSE); i++) {
        sum = checked_sum( sum, roll_expression(cur->right, FALSE) );
      }
      break;
      
    case OP_DICE:
      sum = roll_dice( roll_expression(cur->right, FALSE) );
      break;
      
    case OP_PLUS:
      sum = checked_sum( roll_expression( cur->left,  FALSE ),
                         roll_expression( cur->right, FALSE ) );
      break;
      
    case OP_MINUS:
      sum = checked_sum( roll_expression( cur->left,  FALSE ),
                         -roll_expression( cur->right, FALSE ) );
      break;
      
    case OP_TIMES:
      sum = checked_multiplication( roll_expression( cur->left,  FALSE ),
                                   roll_expression( cur->right, FALSE ) );
      break;
      
    case OP_DIV:
      sum = (int)
        ceil( (float)roll_expression( cur->left,  FALSE ) /
              roll_expression( cur->right, FALSE ) );
      break;
      
    case OP_HIGH:

      sides       = roll_expression(cur->right->right->right, FALSE);
      repetitions = roll_expression(cur->right->left,  FALSE);
      high        = roll_expression(cur->left, FALSE);      

      /* array to store the results to sort */
      if (!(results = malloc(sizeof(int)*repetitions))) {
        error("Out of memory");
      }
      
      for(i=0; i<repetitions; i++) {
        results[i] = roll_dice(sides);
      }
      qsort(results, repetitions, sizeof(int), &compare);

      for(i=(repetitions-high); i<repetitions; i++) {
        sum = checked_sum( sum, results[i] );
      }
      
      free(results);
      
      break;
      
    case OP_LOW:
      
      sides       = roll_expression(cur->right->right->right, FALSE);
      repetitions = roll_expression(cur->right->left,  FALSE);
      low         = roll_expression(cur->left, FALSE);
      
      if (cur->right->left != NULL) {
        repetitions = roll_expression(cur->right->left, FALSE);
      }
                  
      /* array to store the results to sort */
      if (!(results = malloc(sizeof(int)*repetitions))) {
        error("Out of memory");
      }
      
      for(i=0; i<repetitions; i++) {
        results[i] = roll_dice(sides);
      }
      qsort(results, repetitions, sizeof(int), &compare);
      for(i=0; i<low; i++) {
        sum = checked_sum( sum, results[i] );
      }
      
      free(results);
      
      break;

    case OP_GT:
      
      limit = roll_expression(cur->right, FALSE);      
      tmp   = roll_expression(cur->left,  FALSE);
      while (tmp <= limit) {
        tmp = roll_expression(cur->left, FALSE);
      }
      sum = checked_sum( sum, tmp );
      
      break;
      
    case OP_GE:
      
      limit = roll_expression(cur->right, FALSE);      
      tmp   = roll_expression(cur->left,  FALSE);
      while (tmp < limit) {
        tmp = roll_expression(cur->left, FALSE);
      }
      sum = checked_sum( sum, tmp );
      
      break;
      
    case OP_LT:
      
      limit = roll_expression(cur->right, FALSE);      
      tmp   = roll_expression(cur->left,  FALSE);
      while (tmp >= limit) {
        tmp = roll_expression(cur->left, FALSE);
      }
      sum = checked_sum( sum, tmp );
      
      break;
      
    case OP_LE:
      
      limit = roll_expression(cur->right, FALSE);      
      tmp   = roll_expression(cur->left,  FALSE);
      while (tmp > limit) {
        tmp = roll_expression(cur->left, FALSE);
      }
      sum = checked_sum( sum, tmp );
      
      break;
      
    case OP_NE:
      
      limit = roll_expression(cur->right, FALSE);      
      tmp   = roll_expression(cur->left,  FALSE);
      while (tmp == limit) {
        tmp = roll_expression(cur->left, FALSE);
      }
      sum = checked_sum( sum, tmp );
      
      break;
      
    default :
      
      fprintf(stderr, "Implementation error: unkown IR node with code %i\n", cur->op);
      exit(EXIT_FAILURE);
      
    }

    return_value = checked_sum( return_value, sum);
    if (print == TRUE) {
      printf("%i\n", sum);
    }
    
    cur = cur->next;
    
  }

  return return_value;
  
}