Пример #1
0
static int	backtrack(char **grid, t_map *map)
{
	t_pair p;
	t_pair g;

	if (!map)
		return (0);
	ft_bzero(&g, sizeof(t_pair));
	ft_bzero(&p, sizeof(t_pair));
	g.i = -1;
	p.i = -1;
	find_beginning_piece(map->tab, &p);
	while (++g.i < (int)g_size && (g.j = -1))
	{
		while (++g.j < (int)g_size)
		{
			if (!insert_piece(&grid, map->tab, g, p))
			{
				if (!backtrack(grid, map->next))
					return (0);
				erase_try(&grid, map->tab, g, p);
			}
		}
	}
	return (1);
}
Пример #2
0
int			ai_turn_drunk(t_data *powf)
{
	ft_putstr(DRUNK);
	while (!insert_piece(rand() % powf->col, powf->current, powf))
		;
	display_board(powf);
	powf->current = powf->current == P1 ? AI : P1;
	powf->turn--;
	return (1);
}
Пример #3
0
int			player_turn(t_data *powf)
{
	int		read_size;
	char	buff[4096];

	ft_putstr(PROMPT);
	if ((read_size = xread(0, buff, 4096)) == -1)
		return (0);
	if (read_size == 1)
		return (1);
	buff[read_size - 1] = '\0';
	if (insert_piece(ft_atoi(buff) - 1, powf->current, powf) == 1)
	{
		display_board(powf);
		powf->current = powf->current == P1 ? AI : P1;
		powf->turn--;
	}
	return (1);
}