Remove food from side-view world initialization

This commit is contained in:
Jared Miller 2026-03-11 15:14:46 -04:00
parent 37d615e87a
commit cb43ebfe83
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 7 additions and 31 deletions

View file

@ -1,4 +1,4 @@
import { MAT_FOOD, MAT_HOME, MAT_SAND } from "./constants";
import { MAT_HOME, MAT_SAND } from "./constants";
export function generateSideViewWorld(worldSize: number): Float32Array {
const data = new Float32Array(worldSize * worldSize * 4);
@ -19,25 +19,5 @@ export function generateSideViewWorld(worldSize: number): Float32Array {
const homeIdx = (surfaceRow * worldSize + centerX) * 4;
data[homeIdx] = MAT_HOME;
// scatter food on surface — deterministic spots spread across the row
const foodPositions = [
Math.floor(worldSize * 0.15),
Math.floor(worldSize * 0.35),
Math.floor(worldSize * 0.65),
Math.floor(worldSize * 0.85),
];
for (const fx of foodPositions) {
// place a small cluster (3 cells wide) at each position
for (let dx = -1; dx <= 1; dx++) {
const x = fx + dx;
if (x >= 0 && x < worldSize) {
const idx = (surfaceRow * worldSize + x) * 4;
if (data[idx] !== MAT_HOME) {
data[idx] = MAT_FOOD;
}
}
}
}
return data;
}

View file

@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
import { MAT_AIR, MAT_FOOD, MAT_HOME, MAT_SAND } from "../constants";
import { MAT_AIR, MAT_HOME, MAT_SAND } from "../constants";
import { generateSideViewWorld } from "../WorldInit";
const SIZE = 64;
@ -17,9 +17,9 @@ describe("generateSideViewWorld", () => {
for (let x = 0; x < SIZE; x++) {
const idx = (y * SIZE + x) * 4;
const mat = data[idx];
// home and food are allowed on the surface row
// home is allowed on the surface row
if (y === sandHeight - 1) {
expect([MAT_SAND, MAT_HOME, MAT_FOOD]).toContain(mat);
expect([MAT_SAND, MAT_HOME]).toContain(mat);
} else {
expect(mat).toBe(MAT_SAND);
}
@ -74,18 +74,14 @@ describe("generateSideViewWorld", () => {
throw new Error("home not on surface row");
});
test("some cells have R = MAT_FOOD on the surface row", () => {
test("no food placed on the surface row", () => {
const data = generateSideViewWorld(SIZE);
const surfaceRow = Math.floor(SIZE * 0.6) - 1;
let foodCount = 0;
for (let x = 0; x < SIZE; x++) {
const idx = (surfaceRow * SIZE + x) * 4;
if (data[idx] === MAT_FOOD) {
foodCount++;
const mat = data[idx];
expect(mat === MAT_SAND || mat === MAT_HOME).toBe(true);
}
}
expect(foodCount).toBeGreaterThan(0);
});
});