Exemplo n.º 1
0
static int	ft_resolve(t_tetriminos *shapes, t_gridinfo *info,
						int i, char *grid)
{
	int	pos;

	if (ft_place_shape(info, shapes, i, grid) == -1)
		return (-1);
	else
	{
		if ((*info).index < (*info).total)
		{
			if (ft_resolve(shapes, info, 0, grid) == -1)
			{
				(*info).index--;
				pos = ft_get_next_position(shapes[(*info).index].letter, grid);
				ft_clear_shape(grid, shapes[(*info).index].letter);
				if (ft_resolve(shapes, info, pos, grid) == -1)
					return (-1);
			}
		}
		else
		{
			(*info).index--;
			if (ft_place_shape(info, shapes, 0, grid) == -1)
				return (-1);
		}
	}
	return (1);
}
Exemplo n.º 2
0
int		main(int argc, char **argv)
{
	t_piece *tetriminos;
	int		s;
	char	**tab;
	int		i;

	i = 0;
	tab = (char **)malloc(sizeof(char **) * 24);
	if (!tab)
		ft_error();
	while (i < 24)
	{
		tab[i] = (char *)malloc(sizeof(char *) * 24);
		if (!tab[i++])
			ft_error();
	}
	if (argc != 2)
		ft_error();
	tetriminos = ft_read(argv[1], &s, 0);
	ft_dim(tetriminos, s);
	i = ft_resolve(tetriminos, tab, s, 0);
	ft_aff_tab(tab, i);
	return (0);
}
Exemplo n.º 3
0
int		main(int ac, char **av)
{
	char		**tab;
	t_magic		magic;

	if (ac != 2)
		printf("You must enter an equation\n");
	else
	{
		magic = ft_ini_magic();
		tab = ft_strsplit(av[1], ' ');
		if (tab != NULL)
		{
			ft_parse_entry(tab, &magic);
			if (magic.error == 0)
			{
				ft_clear_list(&magic);
				printf("Reduced form: ");
				ft_display_reduced(&magic);
				ft_resolve(&magic);
			}
			else
				ft_error(&magic);
			ft_delete(&magic);
		}
	}
	return (0);
}
Exemplo n.º 4
0
int		ft_resolve(t_coord *cd, t_etri *tetri)
{
	t_int *pmap;

	pmap = (t_int *)malloc(sizeof(t_int));
	pmap->k = 0;
	if (tetri == NULL)
		return (1);
	pmap->i = 0;
	while (pmap->i + LEN <= COTE)
	{
		pmap->j = 0;
		while (pmap->j + LAR <= COTE)
		{
			if (ft_check_tetri(cd, tetri, pmap) == 1)
			{
				if (ft_resolve(cd, NEXT) == 1)
					return (1);
				else
					ft_place(cd, tetri, '.', pmap);
			}
			pmap->j++;
		}
		pmap->i++;
	}
	free(pmap);
	return (0);
}
Exemplo n.º 5
0
int		main(int ac, char **av)
{
	int		nb_pieces;
	t_piece	pieces[MAX_PIECES + 1];
	t_map	*map;

	if (ac == 2)
	{
		nb_pieces = ft_check_file(av[1], pieces);
		if (nb_pieces > 0)
		{
			if (!(map = (t_map *)malloc(sizeof(t_map))))
				return (ERROR_MALLOC);
			if (ft_init_map(map, 3, 'A', nb_pieces) < 0)
			{
				free(map);
				return (ERROR_MALLOC);
			}
			ft_resolve(pieces, map, nb_pieces);
		}
		else
			ft_putstr("error");
	}
	else
		ft_putstr("error");
	return (0);
}
Exemplo n.º 6
0
static int	ft_resolve(t_tetri *tetri, char map[50][50], int letter, int size)
{
	int		i;

	if (!tetri)
		return (1);
	tetri->x = 0;
	while (tetri->x < size)
	{
		tetri->y = 0;
		while (tetri->y < size)
		{
			if (test_position(tetri, map, size))
			{
				ft_valid_pos(tetri, map, letter, size);
				if (ft_resolve(tetri->next, map, letter + 1, size))
					return (1);
				i = 0;
				ft_delete(map, letter, size);
			}
			tetri->y++;
		}
		tetri->x++;
	}
	return (0);
}
Exemplo n.º 7
0
int			ft_backtrack(t_inv *move, int posi, char (*tab)[SIZE],
						char (*end)[SIZE])
{
	t_point	co;

	++LTR;
	ft_posi(SIZE, &posi, &co);
	return (ft_resolve(co, move, tab, end));
}
Exemplo n.º 8
0
void	ft_prepare_algo(t_coord *cd, t_etri *tetri)
{
	COTE = ft_sqrt_int((NB_P) * 4);
	MAP = ft_map_creator(COTE);
	tetri = BEGIN;
	while (ft_resolve(cd, tetri) == 0)
	{
		COTE++;
		MAP = ft_map_creator(COTE);
	}
}
Exemplo n.º 9
0
int			ft_square(t_global *g)
{
	if (!(ft_size_square(g)))
		return (0);
	if (!(ft_create_square(g)))
		return (0);
	while (!ft_resolve(g, 0, 0))
	{
		g->size++;
		g->maxspace = g->maxspace + g->size * 2 - 1;
		if (!(ft_create_square(g)))
			return (0);
	}
	return (1);
}
Exemplo n.º 10
0
Arquivo: main.c Projeto: tirrorex/C
int		main(int argc, char **argv)
{
	int **sudoku;

	if (argc == 10)
	{
		if (!ft_check(argv))
			return (write(2, "Erreur\n", 8));
		sudoku = ft_chartoint(argv);
		ft_resolve(sudoku, 0, 1);
		ft_aff(sudoku);
	}
	else
		write(2, "Erreur\n", 8);
	return (0);
}
Exemplo n.º 11
0
Arquivo: main.c Projeto: Frayna/canyou
int		main(int ac, char **av)
{
	char	*file;
	t_bloc	*blocs;
	int		nbblocs;
	char	**square;

	if (ac != 2)
		ft_error();
	file = ft_readfile(av[1]);
	ft_veriffile(file, 0);
	nbblocs = ft_verifblocs(file);
	blocs = ft_stockblocs(file, nbblocs);
	*square = ft_resolve(blocs, nbblocs);
	ft_printsquare(*square);
	return (0);
}
Exemplo n.º 12
0
void		ft_solve(t_gridinfo *info, t_tetriminos *shapes, int i, char *grid)
{
	int	result;

	while ((*info).index < (*info).total)
	{
		result = ft_resolve(shapes, info, i, grid);
		if (result == -1)
		{
			free(grid);
			(*info).width += 1;
			grid = ft_make_grid(((*info).width - 1));
			(*info).index = 0;
			i = 0;
		}
	}
	ft_print_grid(grid);
}
Exemplo n.º 13
0
void		ft_start(t_tetri *tetri)
{
	int		size;
	int		i;
	char	map[50][50];
	int		j;

	size = 2;
	if (!ft_check_tetri(tetri))
	{
		ft_putendl_fd("Error.", 2);
		return ;
	}
	while (!ft_resolve(tetri, map, 'A', size) && size < 50)
	{
		i = 0;
		while (i < 50)
			ft_memset(map[i++], '.', 50);
		size++;
	}
	ft_write_map(map, size);
}
Exemplo n.º 14
0
int		control(int fd)
{
	char	*buffer;
	t_tetra	*tetralist;
	int		i;

	i = 0;
	tetralist = malloc(26 * sizeof(t_tetra));
	if (!(buffer = ft_buffing(fd)))
	{
		ft_putstr("error\n");
		return (1);
	}
	if (ft_checker(buffer) != 0)
	{
		ft_putstr("error\n");
		return (1);
	}
	tetralist = ft_crealist(buffer);
	ft_resolve(tetralist);
	return (0);
}
Exemplo n.º 15
0
int				main(int ac, char **av)
{
	int		fd;
	t_file	file;
	char	**tab;

	fd = 0;
	file = ft_init(file);
	tab = NULL;
	if (ac != 2)
		write(1, "usage: ./fillit input_file\n", 27);
	else
	{
		tab = ft_convert(ft_open(av[1], &fd, 0), &file.m, 0, 0);
		if (tab != NULL && ft_check(tab, file) != -1 && close(fd) != -1)
		{
			if (!(ft_resolve(tab, file, NULL)))
				write(1, "error\n", 6);
		}
		else
			write(1, "error\n", 6);
	}
	return (0);
}