radius(0))->toBe(0.0) ->and($frontier->radius(37346))->toEqualWithDelta(202.5, 0.1) ->and($frontier->radius(100))->toEqualWithDelta(sqrt(100 / (M_PI * 0.29)), 1e-9); }); it('starts the world at 0|0 and keeps new players inside the quarter they picked', function () { $frontier = new Frontier(gameConfig()); // No offset from the ring: the first village sits on 0|0; with 100 villages the ring is ~10.5 out. expect($frontier->pick(0, [], 'random', sequence(0.0, 0.5)))->toBe([0, 0]) ->and($frontier->pick(100, [], 'random', sequence(0.0, 0.5)))->toBe([10, 0]) ->and($frontier->pick(100, [], 'ne', sequence(0.0, 0.5)))->toBe([0, -10]) ->and($frontier->pick(100, [], 'sw', sequence(0.5, 0.5)))->toBe([-7, 7]); }); it('keeps clear of other players for as long as it can, but not of barbarians', function () { $frontier = new Frontier(gameConfig()); expect($frontier->pick(100, ['11|1' => false], 'random', sequence(0.0, 0.5)))->toBe([10, 0]) // Next to a player every try lands in the same spot, so the clear tries run out first. ->and($frontier->pick(100, ['11|1' => true], 'random', sequence(0.0, 0.5)))->toBe([10, 0]) ->and($frontier->pick(100, ['10|0' => false], 'random', sequence(0.0, 0.5)))->toBeNull(); }); it('places barbarians a few fields from the new village and brings 1.3 per join on average', function () { $frontier = new Frontier(gameConfig()); // Angle 0, distance 1.5 + 0.5 × 2.5 = 2.75: three fields east. expect($frontier->near(5, 5, [], sequence(0.0, 0.5)))->toBe([8, 5]) ->and($frontier->barbariansPerJoin(sequence(0.29)))->toBe(2) ->and($frontier->barbariansPerJoin(sequence(0.31)))->toBe(1); });