// El flood fill de una cuadrícula pequeña, con un rastro de cada llamada que pinta.
#include <stdio.h>

#define ROWS 3
#define COLS 3

typedef struct {
    int calls;
    int painted;
} Tally;

void fill(char grid[][COLS + 1], int row, int col, int depth, Tally *tally) {
    tally->calls++;
    if (row < 0 || row >= ROWS || col < 0 || col >= COLS) {
        return;
    }
    if (grid[row][col] != '.') {
        return;
    }
    grid[row][col] = 'o';
    tally->painted++;
    printf("%*spinta (%d, %d)\n", depth * 2, "", row, col);
    fill(grid, row - 1, col, depth + 1, tally);
    fill(grid, row + 1, col, depth + 1, tally);
    fill(grid, row, col - 1, depth + 1, tally);
    fill(grid, row, col + 1, depth + 1, tally);
}

int main(void) {
    char grid[ROWS][COLS + 1] = {
        "..#",
        ".##",
        "..#",
    };
    Tally tally = {0, 0};

    fill(grid, 0, 1, 0, &tally);
    for (int row = 0; row < ROWS; row++) {
        printf("%s\n", grid[row]);
    }
    printf("%d celdas pintadas, %d llamadas\n", tally.painted, tally.calls);
    return 0;
}
