the idea is field is 6x6 filled with 0,1,2,3,4. and user clicks on cells, when player clicks on cell > 0 its value increased by 1. if value becomes 5, cell is zeroed. and 4 bullets start flying up down left right, until they hits other nonzero cells. and when hit it works as player click - increase, initiate more bullets on 5 etc.

when field is all zeroes - game ends, this is the player goal.

so i want to write function, which gets level number, and generates initial state of field. so level 1 should be simple (less clicks, easier to clear field for player) and with every next level it will be more challenging - more clicks needed, not many values 4, not many 0 cells.

i hope you get an idea


something like this

 private initializeBoardOld(level: number): Tile[] {     ■ 'initializeBoardOld' is declared but its value is never read.                               │                                                                               
                                                                               │   20 │ │ let board: Tile[] = new Array(36);                                                                                                                  │                                                                               
                                                                               │   21 │ │                                                                                                                                                     │                                                                               
                                                                               │   22 │ │ // Return a function that generates a weighted probability for values 0 to 3                                                                        │                                                                               
                                                                               │   23 │ │ const probability = (level: number) => {                                                                                                            │                                                                               
                                                                               │   24 │ │ │ if (level <= 3) {                                                                                                                                 │                                                                               
                                                                               │   25 │ │ │ │ return [0.4, 0.4, 0.25, 0.05]; // 70% chance for 0, 20% for 1, 8% for 2, 2% for 3                                                               │                                                                               
                                                                               │   26 │ │ │ } else if (level <= 5) {                                                                                                                          │                                                                               
                                                                               │   27 │ │ │ │ return [0.5, 0.3, 0.15, 0.05]; // 50% for 0, 30% for 1, etc.                                                                                    │                                                                               
                                                                               │   28 │ │ │ } else {                                                                                                                                          │                                                                               
                                                                               │   29 │ │ │ │ return [0.7, 0.2, 0.05, 0.02]; // 30% for 0, 40% for 1, etc.                                                                                    │                                                                               
                                                                               │   30 │ │ │ }                                                                                                                                                 │                                                                               
                                                                               │   31 │ │ };                                                                                                                                                  │                                                                               
                                                                               │   32 │ │                                                                                                                                                     │                                                                               
                                                                               │   33 │ │ // Get the weights based on the level                                                                                                               │                                                                               
                                                                               │   34 │ │ const weights = probability(level);                                                                                                                 │                                                                               
                                                                               │   35 │ │                                                                                                                                                     │                                                                               
                                                                               │   36 │ │ // Calculate the size of the board (assuming it's a 6x6 grid)                                                                                       │                                                                               
                                                                               │   37 │ │ const size = 6 * 6; // 36 squares for a 6x6 grid                                                                                                    │                                                                               
                                                                               │   38 │ │                                                                                                                                                     │                                                                               
                                                                               │   39 │ │ // Generate the board with weighted probabilities                                                                                                   │                                                                               
                                                                               │   40 │ │ for (let i = 0; i < size; i++) {                                                                                                                    │                                                                               
                                                                               │   41 │ │ │ const rand = Math.random();                                                                                                                       │                                                                               
                                                                               │   42 │ │ │ let value = 0;                                                                                                                                    │                                                                               
                                                                               │   43 │ │ │                                                                                                                                                   │                                                                               
                                                                               │   44 │ │ │ // Determine the value based on random chance and the probability weights                                                                         │                                                                               
                                                                               │   45 │ │ │ if (rand < weights[0]) value = 0;                                                                                                                 │                                                                               
                                                                               │   46 │ │ │ else if (rand < weights[0] + weights[1]) value = 1;                                                                                               │                                                                               
                                                                               │   47 │ │ │ else if (rand < weights[0] + weights[1] + weights[2]) value = 2;                                                                                  │                                                                               
                                                                               │   48 │ │ │ else if (rand < weights[0] + weights[1] + weights[2] + weights[3]) value = 3;                                                                     │                                                                               
                                                                               │   49 │ │ │ else value = 4;                                                                                                                                   │                                                                               
                                                                               │   50 │ │ │                                                                                                                                                   │                                                                               
                                                                               │   51 │ │ │ // Add the generated value to the board array                                                                                                     │                                                                               
                                                                               │   52 │ │ │ const { x, y } = this.indexToXY(i);                                                                                                               │                                                                               
                                                                               │   53 │ │ │ board[i] = new Tile({                                                                                                                             │                                                                               
                                                                               │   54 │ │ │ │ index: i,                                                                                                                                       │                                                                               
                                                                               │   55 │ │ │ │ x: x,                                                                                                                                           │                                                                               
                                                                               │   56 │ │ │ │ y: y,                                                                                                                                           │                                                                               
                                                                               │   57 │ │ │ │ cellSize: this.cellSize,                                                                                                                        │                                                                               
                                                                               │   58 │ │ │ │ value: value                                                                                                                                    │                                                                               
                                                                               │   59 │ │ │ } as TileOptions);                                                                                                                                │                                                                               
                                                                               │   60 │ │ }                                                                                                                                                   │                                                                               
                                                                               │   61 │ │                                                                                                                                                     │                                                                               
                                                                               │   62 │ │ return board;                                                                                                                                       │                                                                               
                                                                               │   63 │ }