示例#1
0
static t_map	*generator0(t_map *map, int stack_size, int live, t_x_y direct)
{
  int	coord;
  int	count;
  int	i;
  int	*stack;

  if ((stack = malloc(sizeof(int) * stack_size + 1)) == NULL)
    exit(EXIT_FAILURE);
  i = 0;
  count = 1;
  coord = 0;
  while (count < stack_size)
    {
      move(map, &coord, &count, direct);
      if (check_dead_end(map, coord, direct) == 0)
	stack[i++] = coord;
      else if (check_dead_end(map, coord, direct) == 1)
	coord = back_in_stack(&i, stack, map, direct);
      if (live)
	display_live(map, coord, direct);
    }
  free(stack);
  return (map);
}
示例#2
0
void remove_dead_ends(int *allowed, int *new_allowed, int size, int offset)
{
    int i, x, y;
    int check_top, check_right, check_bot, check_left;
    int top, right, bot, left;
    for(i=0; i<size; i++)
    {
        check_top = check_right = check_bot = check_left = 1;
        x = get_x(i, offset);
        y = get_y(i, offset);
        // are we at any edges/corners?
        if(x == 0)       check_left = 0;
        if(y == 0)       check_bot = 0;
        if(x >= offset - 1 ) check_right = 0;
        if(y >= offset - 1) check_top = 0;

        // set values to be checked
        top = check_top ? allowed[i+1] : 0;
        right = check_right ? allowed[i+offset] : 0;
        bot = check_bot ? allowed[i-1] : 0;
        left = check_left ? allowed[i-offset] : 0;

        if(check_dead_end(top, right, bot, left))
        {
            new_allowed[i] = 0;
        }
        else
        {
            new_allowed[i] = allowed[i];
        }
    }
}
示例#3
0
int	back_in_stack(int *i, int *stack, t_map *map, t_x_y direct)
{
  (*i)--;
  while (check_dead_end(map, stack[*i], direct) == 1 && *i > 0)
    (*i)--;
  return (stack[*i]);
}