Ejemplo n.º 1
0
/*
** brief: main function for IA, it will check if she already won
** @lst: our list
** @more_one: used to check number of line with more 1 lucifer
** @pos: the pos choosed by AI
** @nbr: the number of lucifers
*/
void		ia_game(t_list *lst, int more_one, int pos, int nbr)
{
  t_list	*tmp;

  (void)sleep(1);
  tmp = lst->next;
  while (tmp != NULL)
    {
      more_one = (tmp->nbr_ele > 1) ? more_one + 1 : more_one;
      tmp = tmp->next;
    }
  if (lst->nbr_ele == 1)
    lst->next->nbr_ele = 1;
  else if (lst->nbr_ele == 2 && more_one <= 1)
    {
      if (lst->next->nbr_ele == 1)
	remove_ele(lst, 2);
      else
	remove_ele(lst, 1);
    }
  else if (more_one == 1)
    _one_big_size(lst, lst->nbr_ele - 1);
  else
    {
      pos = _find_position(lst, &nbr);
      _my_sub_nbr(lst, pos, nbr);
    }
}
Ejemplo n.º 2
0
int removeclient(struct client* c, struct queue_list *clientlist)
{
	struct node *temp = clientlist->front;
	while (temp)
	{
		if (temp->content == c)
		{
			break;
		}
		temp = temp->next;
	}
	
    return remove_ele(clientlist, temp);
}
Ejemplo n.º 3
0
static void	_one_big_size(t_list *lst, int par)
{
  t_list	*tmp;
  int		pos;

  pos = 0;
  tmp = lst->next;
  while (tmp != NULL && tmp->nbr_ele == 1)
    {
      ++pos;
      tmp = tmp->next;
    }
  if (par % 2 == 0)
    tmp->nbr_ele = 1;
  else
    remove_ele(lst, pos);
}
Ejemplo n.º 4
0
/*
** brief: it will substract the number of lucifers in line pos (if 0 remove)
** @lst: our list
** @pos: our line
** @nbr: number of lucifers
*/
static void	_my_sub_nbr(t_list *lst, const int pos, const int nbr)
{
  t_list	*tmp;
  int		i;

  tmp = lst;
  i = -1;
  while (tmp != NULL && ++i < pos)
    tmp = tmp->next;
  tmp->nbr_ele -= nbr;
  if (tmp->nbr_ele <= 0)
    remove_ele(lst, pos);
  else
    {
      free(tmp->bin);
      tmp->bin = int_to_bin(tmp->nbr_ele);
    }
  free(lst->bin);
  lst->bin = operation_xor(lst->next);
}
Ejemplo n.º 5
0
int main()
{
    int i, n, ret_value, choice = 1, flag;
    char string[eleSize];

    printf("Enter the max key: ");
    scanf("%d",&n);
    struct node * lList[n];

    for(i = 0; i < n; i++)
    {
        lList[i] = NULL;
    }

    do
    {
        printf("----------------------------------------------------------\n");
        printf("1. Insert || 2. Search || 3. Delete || 4. Print || 0. Exit\n");
        printf("----------------------------------------------------------\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch(choice)
        {
            case 1:
                printf("Element: ");
                scanf("%s", string);
                ret_value = hashFunc(string, n);
                printf("Inserting at key position: %d\n", ret_value);
                lList[ret_value] = insert(lList[ret_value], string);
                break;
            case 2:
                printf("Element: ");
                scanf("%s", string);
                ret_value = hashFunc(string, n);
                flag = search(lList[ret_value], string);
                if(flag == 1)
                    printf("Element found at key value: %d\n",ret_value);
                else
                    printf("Element not found!\n");
                break;
            case 3:
                printf("Element: ");
                scanf("%s", string);
                ret_value = hashFunc(string, n);
                flag = search(lList[ret_value], string);
                if(flag == 1)
                    lList[ret_value] = remove_ele(lList[ret_value], string);
                else
                    printf("That element is not present\n");
                break;
            case 4:
                printf("Elements present: \n");
                print(lList, n);
                break;
            case 0:
                break;
            default:
                printf("Wrong Choice\n");
                break;
        }
    }while(choice != 0);
    return 0;
}