void mix_card_game_classic(Stack *card_game) {

  /** Mix the card game by taken an random card from the game and reinsert in the game at an random position. **/

  int c ;

  for (c=0 ; c < 32 ; c++) {


     int cc ;
     uint8_t get_cards ;


     ListElt *card_to_rm  = list_head(card_game) ;
     ListElt *card_to_add = list_head(card_game) ;

     /** Compute an random card taking position. **/

     get_cards=get_rand(32) ;

     while (get_cards == 0) {
         get_cards=get_rand(32) ;
     }

     for (cc=0 ; cc < get_cards ; cc++ ) {
        card_to_rm=list_next(card_to_rm) ;
     }

     /** Taken one card from the game. **/
     Card *card_datas = malloc(sizeof(Card)) ;
     if (list_remove_next((List *) card_game,card_to_rm,(void *) &card_datas) !=  0) {
       /** This should never append. **/
       continue ;
     }

     usleep(get_rand(25)) ;  /** For random utils. **/

     /** Compute an random insert position. **/

     get_cards=get_rand(32) ;

     while (get_cards == 0) {
         get_cards=get_rand(32) ;
     }

     for (cc=0 ; cc < get_cards ; cc++ ) {
        card_to_add=list_next(card_to_add) ;
     }

     if (list_insert_next((List *) card_game,card_to_add,card_datas) != 0) {
       /** This should never append. **/
       reinsert_card_in_game((List *) card_game, card_datas) ;
     }
 
     usleep(get_rand(25)) ; /** For random utils. **/

  }

  return ;
}
Example #2
0
void list_free_node(T node)
{
    assert(node);
#ifdef MEMPOOL
    list_insert_next(freelist, node);
#else
    free(node);
#endif
}
Example #3
0
int
parse_nf (char *string, List *list)
{
  newts_nfref *ref = nfref_alloc ();
  char *copy;

  if (string == NULL || list == NULL)
    return -1;

  copy = newts_strdup (string);

  if (!pattern_flag)
    sense = PARSE_ADD;

  if (*copy == ':')
    {
      return parse_file (copy + 1, list);
    }

  if (*copy == '!')
    {
      char *change = newts_strdup (copy + 1);
      newts_free (copy);
      copy = change;
      sense = PARSE_DELETE;
    }

  if (!pattern_flag &&
      (strchr (copy, '?') || strchr (copy, '[') || strchr (copy, '*') ||
       strchr (copy, ' ')))
    {
      /* Pattern matching. */

      int result;

      pattern_flag = TRUE;
      result = parse_pattern (copy, list);
      pattern_flag = FALSE;
      return result;
    }

  parse_single_nf (copy, ref);

  if (sense == PARSE_ADD)
    list_insert_next (list, list_tail (list), (void *) ref);
  else
    {
      list_remove_match (list, (void *) ref);
      nfref_free (ref);
    }

  newts_free (copy);

  return 0;
}
void gather_cards(Stack *throw_cards_stack, Card player[5], Card computer[5], uint8_t invert) {

  /** Internally function (not animation) to gather the cards wenn the round or the game is over.
   *  -) We throw all the cards from the player and the computer. *
   *  -) We pop every card from the trhow stack to insert it in the card game stack.
   * ********************************************************************************************/

  uint8_t c, cc, counter ;

  counter=0 ;

  for (c=invert, cc=0 ; c < (10+invert) ; c++) {
    /** We throw all the cards from theplayer and the computer. **/
 
    if (c % 2 == 0) {
      throw_a_card(throw_cards_stack, &player[cc]) ;
      remove_a_card_from_hand(game_control->player, player[cc].index,true) ;
    }
    else {
      throw_a_card(throw_cards_stack,&computer[cc]) ;
      remove_a_card_from_hand(game_control->computer, computer[cc].index,false) ;
    }
 
    if (counter % 2 == 1) {
      cc++ ;
    }
    counter++ ;
  }

  cc=stack_size(throw_cards_stack) ;

  for (c=0 ; c < cc ; c++) {
    /** We take all the cards from the throw stack to reinsert it in the game at the end of it. **/
 
    Card *card = malloc(sizeof(Card)) ;
 
    /** Pop a card from the throw stack. **/
    if (stack_pop(throw_cards_stack,(void *) &card) != 0) {
      /** This should not append. **/
      exit(EXIT_FAILURE) ;
    }
 
    /** Reinsert card in the game. **/
    if (list_insert_next((List *) game_control->card_game, list_tail(game_control->card_game),card) != 0) {
      /** This should not append. **/
      exit(EXIT_FAILURE) ;
    }
  }

}
int main(void) 
{
  link head, l;
  int i;

  head = list_init(0);
  for (i = 1, l = head; i < N; i++)
    {
      list_insert_next(l, i);
      l = l->next;
    }
  list_print(head);
  printf("\n");
  delete_last(head);
  list_print(head);
  printf("\n");
  return 0;
}
Example #6
0
int hashtbl_insert(HashTable *htbl, const void *data)
{
    void *temp;
    int bucket, retval;

    temp = (void*)data;
    if (hashtbl_lookup(htbl, &temp) == 0) {
        return 1;
    }

    bucket = htbl->h(data) % htbl->buckets;

    retval = list_insert_next(&htbl->table[bucket], NULL, data);
    if (retval == 0) {
        htbl->size++;
    }

    return retval;
}
Example #7
0
Region& Region::operator=(const Region& other)
{
	if (&other == this)
		return *this;

	// Create a copy of the list and its contents
	list_destroy(rect_list);
	list_init(rect_list, __kfree);

	ListElement* cur_node = list_head(other.rect_list);
	while (cur_node != NULL) {
		list_insert_next(rect_list, NULL,
			new Rect(*((Rect *)list_data(cur_node))));

		cur_node = cur_node->next;
	}

	return *this;
}
void reinsert_card_in_game(List *card_game, Card *card_datas) {

  int c = 0 ;

  ListElt *insert_after = list_head(card_game) ;

  while (list_insert_next(card_game, insert_after, card_datas) != 0) {

    c++ ;

    if (c == 31) {
      insert_after = list_head(card_game) ;
      c=0 ;
    }

    insert_after = list_next(insert_after) ;
 }

 return ;

}
Example #9
0
void
init_blacklist (void)
{
  struct blacklist_entry *entry;
  char *temp, *parsestr, *token, *subtoken, *subsubtoken;
  char *list, *item, *subitem;
  char *username = NULL;

  temp = getenv ("NFBLACKLIST");
  if (temp != NULL)
    parsestr = newts_strdup (temp);
  else
    parsestr = NULL;

  list_init (&blacklist,
             (void * (*) (void)) alloc_blacklist_entry,
             (void (*) (void *)) free_blacklist_entry,
             NULL);

  if (parsestr != NULL)
    {
      token = strtok_r (parsestr, " ", &list);

      while (token != NULL)
        {
          if (*token == ':')
            {
              /* ":nf,nf, ..." format */

              token++;
              subtoken = strtok_r (token, ",", &item);

              while (subtoken != NULL)
                {
                  entry = list_alloc_item (&blacklist);
                  entry->username = NULL;
                  entry->nf = newts_strdup (subtoken);

                  list_insert_next (&blacklist, list_tail (&blacklist),
                                    (void *) entry);

                  subtoken = strtok_r (NULL, ",", &item);
                }
            }
          else
            {
              subtoken = strtok_r (token, ":", &item);
              username = newts_strdup (subtoken);
              subtoken = strtok_r (NULL, ":", &item);

              if (subtoken == NULL)
                {
                  /* "user" format */

                  entry = list_alloc_item (&blacklist);
                  entry->username = newts_strdup (username);
                  entry->nf = NULL;
                  list_insert_next (&blacklist, list_tail (&blacklist),
                                    (void *) entry);
                }
              else
                {
                  /* "user:nf,nf, ..." format */

                  subsubtoken = strtok_r (subtoken, ",", &subitem);

                  while (subsubtoken != NULL)
                    {
                      entry = list_alloc_item (&blacklist);
                      entry->username = newts_strdup (username);
                      entry->nf = newts_strdup (subsubtoken);

                      list_insert_next (&blacklist, list_tail (&blacklist),
                                        (void *) entry);

                      subsubtoken = strtok_r (NULL, ",", &subitem);
                    }
                }

              newts_free (username);
            }

          token = strtok_r (NULL, " ", &list);
        }
    }

  newts_free (parsestr);

  temp = getenv ("NFWHITELIST");
  if (temp != NULL)
    parsestr = newts_strdup (temp);
  else
    parsestr = NULL;

  list_init (&whitelist,
             (void * (*) (void)) alloc_blacklist_entry,
             (void (*) (void *)) free_blacklist_entry,
             NULL);

  if (parsestr != NULL)
    {
      token = strtok_r (parsestr, " ", &list);

      while (token != NULL)
        {
          if (*token == ':')
            {
              /* ":nf,nf, ..." format */

              subtoken = strtok_r (token, ",", &item);

              while (subtoken != NULL)
                {
                  entry = list_alloc_item (&whitelist);
                  entry->username = NULL;
                  entry->nf = newts_strdup (subtoken);

                  list_insert_next (&whitelist, list_tail (&whitelist),
                                    (void *) entry);

                  subtoken = strtok_r (NULL, ",", &item);
                }
            }
          else
            {
              subtoken = strtok_r (token, ":", &item);
              username = newts_strdup (subtoken);
              subtoken = strtok_r (NULL, ":", &item);

              if (subtoken == NULL)
                {
                  /* "user" format */

                  entry = list_alloc_item (&whitelist);
                  entry->username = newts_strdup (username);
                  entry->nf = NULL;
                  list_insert_next (&whitelist, list_tail (&whitelist),
                                    (void *) entry);
                }
              else
                {
                  /* "user:nf,nf, ..." format */

                  subsubtoken = strtok_r (subtoken, ",", &subitem);

                  while (subsubtoken != NULL)
                    {
                      entry = list_alloc_item (&whitelist);
                      entry->username = newts_strdup (username);
                      entry->nf = newts_strdup (subsubtoken);

                      list_insert_next (&whitelist, list_tail (&whitelist),
                                        (void *) entry);

                      subsubtoken = strtok_r (NULL, ",", &subitem);
                    }
                }

              newts_free (username);
            }

          token = strtok_r (NULL, " ", &list);
        }
    }

  newts_free (parsestr);

  return;
}
Example #10
0
void Region::AddRect(Rect& rect)
{
	// Add the rect to the list
	Rect *data = new Rect(rect);
	list_insert_next(rect_list, NULL, (void *)data);
}
Example #11
0
int list_insert_head(list_t *lst, node_t *node)
{
	list_insert_next(lst, lst->head, node);
	return 0;
}
Example #12
0
int stack_push(Stack *stack, const void *data) {

  return list_insert_next((List *) stack,NULL,data) ;

}
Example #13
0
void UIComponent::AddComponent(UIComponent *component)
{
	list_insert_next(children, NULL, component);
}