new element : t_list *map that keeps track of board avdancement, also blob is now a map of the actual blob, not just the size

This commit is contained in:
Jack Halford 2016-09-04 02:02:11 +02:00
parent b088c9bcba
commit bc678f6a35
2 changed files with 37 additions and 35 deletions

View file

@ -9,9 +9,8 @@ int ft_solved(char **board)
return (1);
}
int ft_solver(char **board, t_ttmn *ttmn)
int ft_solver(char **board, t_list *map, t_ttmn *ttmn)
{
int i;
int j;
int size;
@ -21,15 +20,17 @@ int ft_solver(char **board, t_ttmn *ttmn)
return (ft_solved(board));
/* ft_show_board(board); */
size = ft_strlen(*board);
i = -1;
while (++i < size * size)
while (map)
{
/* ft_show_board(board); */
if (ft_board_add(board, *ttmn, i))
if (ft_board_add(board, *ttmn, map->content))
continue ;
if (ft_validate_waste(board, ttmn + 1))
ft_map_remove(map, i, *ttmn);
if (ft_validate_waste(board, map, ttmn + 1))
return (1);
ft_board_remove(board, ttmn->id);
ft_map_add(map, i, *ttmn);
ft_board_remove_ttmn(&map, ttmn->id);
map = map->next;
}
return (0);
}

View file

@ -80,48 +80,49 @@ int ft_fit_any(char **board, t_ttmn *ttmn, int i, int blob)
return (0);
}
int ft_validate_waste(char **board, t_ttmn *ttmn)
int ft_validate_waste(char **board, t_list *map, t_ttmn *ttmn)
{
t_list *blob;
int waste;
int y;
int blob;
int size;
if (ttmn->id == '0')
return (ft_solver(board, ttmn + 1));
if (!ttmn->id)
return (ft_solved(board));
blob = NULL;
waste = 0;
size = ft_strlen(*board);
y = -1;
/* ft_show_board(board); */
while (++y < size * size)
while (map)
{
if (board[y / size][y % size] != '.')
ft_board_remove(board, '*');
if (board[map->content / size][map->content % size] != '.')
{
map = map->next;
continue ;
ft_board_replace(board, '*', '^');
blob = ft_waste_here(board, size, y);
/* printf("found blob=%i at %i\n", blob, y); */
/* fflush(stdout); */
/* ft_show_board(board); */
waste += blob % 4;
if (waste > size * size - 4 * g_ttmn)
{
ft_board_remove(board, '*');
ft_board_remove(board, '^');
return (0);
}
if (blob / 4 == 1 && ft_fit_any(board, ttmn, y, blob))
ft_lstadd(&blob, ft_waste_here(board, size, map->content));
waste += ft_lstsize(blob) % 4;;
ft_map_remove_blob(&map, blob);
if (waste > size * size - 4 * g_ttmn)
return (0);
map = map->next;
}
while (blob)
{
if (ft_lstsize(blob->content) / 4 == 1)
{
if (ft_fit_any(board, blob->content, ttmn, y, blob))
return (1);
waste += (blob / 4 == 1) ? 4 : 0;
if (waste > size * size - 4 * g_ttmn)
else
{
ft_board_remove(board, '*');
ft_board_remove(board, '^');
waste += (ft_lstsize(blob->content) / 4 == 1) ? 4 : 0;
if (waste > size * size - 4 * g_ttmn)
return (0);
}
}
ft_board_remove(board, '*');
ft_board_remove(board, '^');
blob = blob->next;
}
return (ft_solver(board, ttmn));
}