/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   score.c                                            :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: qmennen <qmennen@student.codam.nl>         +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2025/05/25 20:54:23 by whaffman          #+#    #+#             */
/*   Updated: 2025/06/03 21:42:54 by qmennen          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "cub3d.h"

int	count_tiles(t_map *map, t_tile tile_type)
{
	int		count;
	int		x;
	int		y;

	count = 0;
	y = 0;
	while (y < map->height)
	{
		x = 0;
		while (x < map->width)
		{
			if (map->grid[y][x] == tile_type)
				count++;
			x++;
		}
		y++;
	}
	return (count);
}

int	count_collected(t_game *game)
{
	int		collected;
	int		i;

	i = 0;
	collected = 0;
	while (i < game->map->n_sprites)
	{
		if (game->map->sprites[i].type == SPRITE_TYPE_COLLECTED)
			collected++;
		i++;
	}
	return (collected);
}

void	print_scores(t_game *game)
{
	int	empty;
	int	visited;
	int	collected;

	empty = count_tiles(game->map, TILE_EMPTY);
	visited = count_tiles(game->map, TILE_VISITED);
	collected = count_collected(game);
	printf("Score:\n");
	printf("Seen %d of %d tiles\n", visited, visited + empty);
	printf("Collected items: %d\n", collected);
}

void	count_scores(t_game *game)
{
	t_scoreboard	*scoreboard;
	
	scoreboard = game->scoreboard;
	scoreboard->tiles_visited = count_tiles(game->map, TILE_VISITED);
	scoreboard->total_tiles = count_tiles(game->map, TILE_EMPTY) + scoreboard->tiles_visited;
	scoreboard->collectibles = count_collected(game);
}
