Video Game Design and Coding · PLECK lesson

PLECK lesson 127 · suggested week 26, day 2

Generate reproducible variation

Objective. Use a local RandomNumberGenerator and an explicit seed.

Godot Engine Standard desktop editor 4.7.2-stable, GDScript (Godot 4), Compatibility renderer. Headless Godot 4.7.2.stable.official.ed1daf0bf passed 106 assertions on the supplied scaffolds, including malformed JSON saves. Audio used the Dummy driver and a synthetic WAV, not a speaker. The visual editor, browser export, and signed-in submission were not tested. The desk still does not run a student's own upload.

About 55 minutes. The due date is chosen by a parent.

Seeded randomness, grids and guaranteed playable routes

Suggested pace: Recall and predict 5 min; Read instruction and scaffold 12 min; Build or design the assigned artifact 25 min; Run acceptance tests 8 min; Explain and checkpoint 5 min.

Materials: Godot Standard 4.7.2 desktop editor (GDScript, Compatibility renderer), Local course folder and prior checkpoint, No paid assets or public account required.

Comes after VGC-L126.

A seeded generator produces a repeatable sequence for the same engine version and calls. C-GRID creates a local RandomNumberGenerator, assigns seed 2468 and samples each eligible cell. A fixed seed helps reproduce a reported layout. Global random calls elsewhere should not accidentally change this generator’s sequence. Record the seed with every test case. Reproducibility is not a claim that all future engine versions guarantee identical random sequences; keep the pinned course version for comparisons.

Worked example

A four-cell corridor reserved before random walls guarantees a required path. Other open cells may still be isolated, so the guarantee must be stated narrowly. Scaffold C-GRID — A deterministic grid with a guaranteed clear route Setup: Attach to Node2D GridLab. This example draws, not physics, so the assignment adds matching wall collision only after validation. Grid is 8 columns by 6 rows at 40 pixels per cell. Row 0 and column 7 are a guaranteed clear route from (0,0) to (7,5). RNG seed is a nonpersonal integer. ```gdscript extends Node2D const COLS: int = 8 const ROWS: int = 6 const CELL: int = 40 var cells: Array = [] func _ready() -> void: var rng := RandomNumberGenerator.new() rng.seed = 2468 for y in range(ROWS): var row: Array[int] = [] for x in range(COLS): var blocked: bool = y != 0 and x != COLS - 1 and rng.randf() < 0.25 row.append(1 if blocked else 0) cells.append(row) queue_redraw() func _draw() -> void: for y in range(cells.size()): for x in range(cells[y].size()): var color := Color.DIM_GRAY if cells[y][x] == 1 else Color.BEIGE draw_rect(Rect2(x * CELL, y * CELL, CELL - 2, CELL - 2), color) ```

A deterministic grid with a guaranteed clear route

GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-GRID. Copy starts from this text. The desk does not run it.

Scene and node setup

Attach to Node2D GridLab. This example draws, not physics, so the assignment adds matching wall collision only after validation. Grid is 8 columns by 6 rows at 40 pixels per cell. Row 0 and column 7 are a guaranteed clear route from (0,0) to (7,5). RNG seed is a nonpersonal integer.

extends Node2D
const COLS: int = 8
const ROWS: int = 6
const CELL: int = 40
var cells: Array = []
func _ready() -> void:
    var rng := RandomNumberGenerator.new()
    rng.seed = 2468
    for y in range(ROWS):
        var row: Array[int] = []
        for x in range(COLS):
            var blocked: bool = y != 0 and x != COLS - 1 and rng.randf() < 0.25
            row.append(1 if blocked else 0)
        cells.append(row)
    queue_redraw()
func _draw() -> void:
    for y in range(cells.size()):
        for x in range(cells[y].size()):
            var color := Color.DIM_GRAY if cells[y][x] == 1 else Color.BEIGE
            draw_rect(Rect2(x * CELL, y * CELL, CELL - 2, CELL - 2), color)

Checks to run in the editor

Native Godot 4.7.2.stable.official.ed1daf0bf headless compile and representative node-tree/runtime tests passed; see native-qa-results.json. Visual UI, audible output, exports and website submission still need separate checks.

Generate reproducible variation — evidence task

  1. 1. Run C-GRID twice with seed 2468 and compare maps.
  2. 2. Change to 1357 and record the new map.

Deliverable. Grid project and two-seed comparison.

Acceptance checks

Understanding question. Why store the seed in a procedural bug report?

Include a downloadable project ZIP with project.godot, .tscn, .gd and original asset files when code changes. A private, teacher-accessible download link to that ZIP is equivalent. Screenshots or a playthrough do not replace editable source.

If this is still shaky. Use the fixed 8 by 6 grid in C-GRID. Keep the guaranteed top-row/right-column path empty before adding any random walls. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.

Optional extra. Compare three integer seeds while checking the same route invariant. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.

Name ____________________ Date ____________________