implement 4 items on belt tile

This commit is contained in:
2026-05-01 21:19:07 +02:00
parent 0ce7cd7ae8
commit b30addab3d
3 changed files with 204 additions and 243 deletions

View File

@@ -66,17 +66,19 @@ TEST_CASE("BeltSystem: tryPutItem fails after removeTile", "[belt]")
// Capacity
// ---------------------------------------------------------------------------
TEST_CASE("BeltSystem: two items fit in one tile", "[belt]")
TEST_CASE("BeltSystem: four items fit in one tile", "[belt]")
{
BeltSystem bs(kFastBeltSpeed);
const QPoint tile(0, 0);
bs.placeBelt(tile, Rotation::East);
REQUIRE(bs.tryPutItem(tile, makeItem("iron_ore")));
REQUIRE(bs.tryPutItem(tile, makeItem("copper_ore")));
REQUIRE(bs.tryPutItem(tile, makeItem("a")));
REQUIRE(bs.tryPutItem(tile, makeItem("b")));
REQUIRE(bs.tryPutItem(tile, makeItem("c")));
REQUIRE(bs.tryPutItem(tile, makeItem("d")));
}
TEST_CASE("BeltSystem: third tryPutItem on full tile returns false", "[belt]")
TEST_CASE("BeltSystem: fifth tryPutItem on full tile returns false", "[belt]")
{
BeltSystem bs(kFastBeltSpeed);
const QPoint tile(0, 0);
@@ -84,8 +86,10 @@ TEST_CASE("BeltSystem: third tryPutItem on full tile returns false", "[belt]")
bs.tryPutItem(tile, makeItem("a"));
bs.tryPutItem(tile, makeItem("b"));
bs.tryPutItem(tile, makeItem("c"));
bs.tryPutItem(tile, makeItem("d"));
REQUIRE_FALSE(bs.tryPutItem(tile, makeItem("c")));
REQUIRE_FALSE(bs.tryPutItem(tile, makeItem("e")));
}
// ---------------------------------------------------------------------------
@@ -217,6 +221,8 @@ TEST_CASE("BeltSystem: item stays blocked when next tile is full", "[belt]")
// Fill tileB to capacity.
bs.tryPutItem(tileB, makeItem("b1"));
bs.tryPutItem(tileB, makeItem("b2"));
bs.tryPutItem(tileB, makeItem("b3"));
bs.tryPutItem(tileB, makeItem("b4"));
// Place item in tileA — should be blocked.
bs.tryPutItem(tileA, makeItem("a1"));
@@ -226,11 +232,11 @@ TEST_CASE("BeltSystem: item stays blocked when next tile is full", "[belt]")
REQUIRE(bs.tryTakeItem(eastPort(tileA)).has_value());
}
TEST_CASE("BeltSystem: belt back slot is capped at progress 0.5", "[belt]")
TEST_CASE("BeltSystem: belt second slot is capped at progress 0.75", "[belt]")
{
// Use progress/tick = 0.4 so the cap is observable: without it, back would
// advance to 0.8 while front is stuck at 1.0, and then need only 1 more tick
// after being promoted. With the cap it stays at 0.5 and needs 2 more ticks.
// Use progress/tick = 0.4 so the cap is observable: without it, slot[1] would
// advance to 0.8 while slot[0] is stuck at 1.0. With the 0.75 cap it stays
// at 0.75 and needs exactly 1 more tick after promotion.
const double medBeltSpeed = 0.4 * static_cast<double>(kTickRateHz);
BeltSystem bs(medBeltSpeed);
@@ -239,21 +245,18 @@ TEST_CASE("BeltSystem: belt back slot is capped at progress 0.5", "[belt]")
// Advance front item to the output edge; it stays there (no next tile).
bs.tryPutItem(tile, makeItem("front_item"));
bs.tick(); // front: 0.4
bs.tick(); // front: 0.8
bs.tick(); // front: 1.0 (capped, stuck)
bs.tick(); // slot[0]: 0.4
bs.tick(); // slot[0]: 0.8
bs.tick(); // slot[0]: 1.0 (capped, stuck)
// Place back item; front is at 1.0 and not blocking (back < 1.0).
// Place second item; slot[0] is at 1.0.
bs.tryPutItem(tile, makeItem("back_item"));
bs.tick(); // back: 0.4
bs.tick(); // back would reach 0.8 — must be capped at 0.5
bs.tick(); // slot[1]: 0.4
bs.tick(); // slot[1] would reach 0.8 — capped at 0.75
// Remove front; back (now promoted to front) must be at 0.5, not 0.8.
// Remove front; slot[1] (now promoted to slot[0]) must be at 0.75.
REQUIRE(bs.tryTakeItem(eastPort(tile)).has_value());
// At 0.4/tick, 0.5 → 0.9 after one tick — not at 1.0 yet.
bs.tick();
REQUIRE_FALSE(bs.tryTakeItem(eastPort(tile)).has_value());
// 0.9 → 1.0 after a second tick — now available.
// At 0.4/tick, 0.75 → 1.0 (capped) after one tick — available.
bs.tick();
REQUIRE(bs.tryTakeItem(eastPort(tile)).has_value());
}