示例#1
0
int	init_player_pos(char *map, char t_nbr, char m_size)
{
  int	i;
  int	check;

  i = 0;
  check = -1;
  while (i < m_size * m_size)
    {
      if (!map[i])
	check = 1;
      if (map[i] == t_nbr && get_free_pos(map, i, m_size) >= 0)
	return (get_free_pos(map, i, m_size));
      ++i;
    }
  if (check < 0)
    {
      fprintf(stderr, NO_PLACE_MSG);
      return (-1);
    }
  if ((check = starting_block_pos(map, m_size)) < 0)
    {
      check = random() % (m_size * m_size);
      while (map[check])
	check = random() % (m_size * m_size);
    }
  return (check);
}
示例#2
0
mytbf_t *mytbf_init(int cps, int burst)
{
	struct mytbf_st *me;
	int pos;

	pthread_once(&init_once, module_load);

	me = malloc(sizeof(*me));
	if (me == NULL) {
		return NULL;
	}

	me->cps = cps;
	me->burst = burst;
	me->token = 0;

	pthread_mutex_init(&me->mut, NULL);
	pthread_cond_init(&me->cond, NULL);

	pthread_mutex_lock(&mut_tbf);
	pos = get_free_pos();
	if (pos < 0) {
		pthread_mutex_unlock(&mut_tbf);
		free(me);
		pthread_cond_destroy(&me->cond);
		pthread_mutex_destroy(&me->mut);
		return NULL;
	}

	tbf[pos] = me;
	pthread_mutex_unlock(&mut_tbf);


	return me;
}
示例#3
0
文件: mytbf.c 项目: wcybxzj/shangguan
mytbf_t *mytbf_init(int cps, int burst){
	struct mytbf_st *me;
	int pos;
	if (inited) {
		module_load();
		inited = 0;
	}

	me = malloc(sizeof(*me));
	if (NULL == me) {
		return NULL;
	}

	me->cps = cps;
	me->burst = burst;
	me->token = 0;

	pos = get_free_pos();
	if (pos < 0) {
		free(me);
		return NULL;
	}
	me->pos = pos;
	job[pos] = me;
	return me;
}
示例#4
0
文件: map.c 项目: alexlevy0/LemIPC
void	update_res(t_data *data)
{
  unsigned int	cpt[NB_TEAM + 1];

  data->id = data->map->nb_gamer;
  printf("Update res ! (nb_gamer: %d)\n", data->id + 1);
  ++data->map->nb_gamer;
  map_stat(data, cpt);
  data->team_id = get_minor_team(cpt);
  data->pos = get_free_pos(data);
  data->map->tab[data->pos] = data->team_id;
}