62 lines
2.8 KiB
PHP
62 lines
2.8 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
use App\Game\Map\BarbarianGarrison;
|
|||
|
|
|
|||
|
|
it('picks a profile by village id', function () {
|
|||
|
|
$garrison = new BarbarianGarrison(gameConfig());
|
|||
|
|
|
|||
|
|
expect($garrison->profile(0))->toBe('spearmen')
|
|||
|
|
->and($garrison->profile(3))->toBe('riders')
|
|||
|
|
->and($garrison->profile(5))->toBe('swordsmen');
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it('grows full strength with the points above the free ones', function () {
|
|||
|
|
$garrison = new BarbarianGarrison(gameConfig());
|
|||
|
|
|
|||
|
|
// 0.1 × (40 − 30) = 1 head; 0.1 × (230 − 30) = 20 heads, 70/30 spears and swords.
|
|||
|
|
expect($garrison->full('spearmen', 30, 100))->toBe([])
|
|||
|
|
->and($garrison->full('spearmen', 40, 100))->toBe(['spear' => 1])
|
|||
|
|
->and($garrison->full('spearmen', 230, 100))->toBe(['spear' => 14, 'sword' => 6])
|
|||
|
|
->and($garrison->full(null, 230, 100))->toBe([]);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it('never eats more than its share of the food budget', function () {
|
|||
|
|
$garrison = new BarbarianGarrison(gameConfig());
|
|||
|
|
|
|||
|
|
// Riders eat (0.5 × 3 + 0.5 × 1) = 2 a head; half of 30 food/h feeds 7 heads.
|
|||
|
|
expect($garrison->full('riders', 230, 30))->toBe(['light_cavalry' => 4, 'spear' => 3]);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it('splits heads by largest remainder so they add up', function () {
|
|||
|
|
expect(BarbarianGarrison::split(5, ['spear' => 0.7, 'sword' => 0.3]))->toBe(['spear' => 4, 'sword' => 1])
|
|||
|
|
->and(BarbarianGarrison::split(1, ['archer' => 0.6, 'spear' => 0.4]))->toBe(['archer' => 1])
|
|||
|
|
->and(BarbarianGarrison::split(0, ['spear' => 1.0]))->toBe([]);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it('regroups a quarter of full strength per step, at least one, never above full', function () {
|
|||
|
|
$garrison = new BarbarianGarrison(gameConfig());
|
|||
|
|
$full = ['spear' => 14, 'sword' => 6];
|
|||
|
|
|
|||
|
|
expect($garrison->regroup([], $full))->toBe(['spear' => 4, 'sword' => 2])
|
|||
|
|
->and($garrison->regroup(['spear' => 12, 'sword' => 6], $full))->toBe(['spear' => 14, 'sword' => 6])
|
|||
|
|
->and($garrison->regroup([], ['spear' => 1]))->toBe(['spear' => 1])
|
|||
|
|
->and($garrison->isFull(['spear' => 14, 'sword' => 6], $full))->toBeTrue()
|
|||
|
|
->and($garrison->isFull(['spear' => 14], $full))->toBeFalse();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it('weighs strength by upkeep', function () {
|
|||
|
|
$garrison = new BarbarianGarrison(gameConfig());
|
|||
|
|
$full = ['light_cavalry' => 2, 'spear' => 2];
|
|||
|
|
|
|||
|
|
// 2 riders eat 6 of the 8 food.
|
|||
|
|
expect($garrison->strength(['light_cavalry' => 2], $full))->toBe(0.75)
|
|||
|
|
->and($garrison->strength([], $full))->toBe(0.0)
|
|||
|
|
->and($garrison->strength(['spear' => 9, 'light_cavalry' => 2], $full))->toBe(1.0)
|
|||
|
|
->and($garrison->strength([], []))->toBe(1.0);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it('regroups every few hours at world speed', function () {
|
|||
|
|
expect((new BarbarianGarrison(gameConfig()))->interval())->toBe(7200)
|
|||
|
|
->and((new BarbarianGarrison(gameConfig(['world' => ['speed' => 100]])))->interval())->toBe(72);
|
|||
|
|
});
|