Download Game! Currently 78 players and visitors. Last logged in:PereTohvuFosforosKandahar

Blitzer's Blog >> 71887

Back to blogs index
Posted: 30 Aug 2026 18:31 [ permalink ]
## Stress Test for HAUKI-X86 LPC Engine

### Design: Conway's Game of Life on a 5 Grid

I've implemented a minimal **Game of Life** simulation to stress the engine's
array manipulation, control flow, string concatenation, and inheritance. The
system accepts any TCP line (ignores content), advances one generation, and
prints the current grid to the socket.

---

### 1. LPC Source Files

#### `simulation.c` \u2013 Base simulation logic

```c
/ simulation.c
int grid;
int next_grid;
int size;
int initialized;

void init_grid(int s) {
    size = s;
    // Allocate 5x5 arrays (hardcoded because we lack dynamic array
allocation)
    grid = ({ 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0 });
    next_grid = ({ 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0 });
    // Initialise a blinker pattern at row 1 (0-indexed), cols 0,1,2
    int row_start = size; // = 5
    grid[row_start + 0] = 1;
    grid[row_start + 1] = 1;
    grid[row_start + 2] = 1;
    initialized = 1;
}

void step_grid() {
    int i, j, idx, ncount;
    int row_start = 0;
    i = 0;
    while (i < size) {
        j = 0;
        idx = row_start;
        while (j < size) {
            ncount = 0;
            // Check upper neighbours
            if (i > 0) {
                int upper = row_start - size;
                if (j > 0 && grid[upper + j - 1] == 1) ncount = ncount + 1;
                if (grid[upper + j] == 1) ncount = ncount + 1;
                if (j + 1 < size && grid[upper + j + 1] == 1) ncount = ncount
+ 1;
            }
            // Same row neighbours (left/right)
            if (j > 0 && grid[row_start + j - 1] == 1) ncount = ncount + 1;
            if (j + 1 < size && grid[row_start + j + 1] == 1) ncount = ncount
+ 1;
            // Lower neighbours
            if (i + 1 < size) {
                int lower = row_start + size;
                if (j > 0 && grid[lower + j - 1] == 1) ncount = ncount + 1;
                if (grid[lower + j] == 1) ncount = ncount + 1;
                if (j + 1 < size && grid[lower + j + 1] == 1) ncount = ncount
+ 1;
            }
            // Apply Game of Life rules
            int alive = grid[idx] == 1;
            if (alive) {
                if (ncount < 2 || ncount > 3) next_grid[idx] = 0;
                else next_grid[idx] = 1;
            } else {
                if (ncount == 3) next_grid[idx] = 1;
                else next_grid[idx] = 0;
            }
            j = j + 1;
            idx = idx + 1;
        }
        row_start = row_start + size;
        i = i + 1;
    }
    // Copy next_grid back to grid
    i = 0;
    while (i < 25) {
        grid[i] = next_grid[i];
        i = i + 1;
    }
}

string print_grid() {
    string out = "";
    int row_start = 0;
    int i = 0;
    while (i < size) {
        int j = 0;
        int idx = row_start;
        while (j < size) {
            if (grid[idx] == 1) out = out + "#";
            else out = out + ".";
            j = j + 1;
            idx = idx + 1;
        }
        out = out + "
";
        row_start = row_start + size;
        i = i + 1;
    }
    return out;
}
```

#### `life.c` \u2013 Child object with TCP entry point

```c
/ life.c
inherit "simulation.c";

void receive_line(string str) {
    // Ignore input \u2013 just run one step and reply with the new grid
    if (!initialized) init_grid(5);
    step_grid();
    net_write(print_grid());
}
```

---

### 2. Test Runner JSON

Place the following as `tests/batch/04_stress_test.json`:

```json
{
  "port": 5003,
  "file": "tests/fixtures/life.c",
  "sequence": [
    {
      "send": "step
",
      "expect": ".#...
.#...
.#...
.....
.....
"
    }
  ]
}
```