game-village-politics-backend/tests/Unit/Game/RaidsTest.php

57 lines
2.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use App\Game\Combat\Raids;
it('sizes a band by the village points in its camp profile', function () {
$raids = new Raids(gameConfig());
// 50 + 1.5 × 300 = 500 attack; a spearmen head hits 0.7 × 10 + 0.3 × 25 = 14.5, so 35 heads.
expect($raids->attack(300))->toBe(500.0)
->and($raids->band('spearmen', 300, 0))->toBe(['spear' => 25, 'sword' => 10])
// Riders: 0.5 × 130 + 0.5 × 10 = 70 a head, 155 / 70 → 3 heads.
->and($raids->band('riders', 70, 0))->toBe(['light_cavalry' => 2, 'spear' => 1])
->and($raids->band(null, 300, 0))->toBe([]);
});
it('brings rams against the wall of a big enough village', function () {
$raids = new Raids(gameConfig());
expect($raids->band('swordsmen', 300, 5))->toHaveKey('ram', 5)
->and($raids->band('swordsmen', 299, 5))->not->toHaveKey('ram')
->and($raids->band('swordsmen', 300, 0))->not->toHaveKey('ram');
});
it('shrinks the band with its camp and scatters it below a quarter', function () {
$raids = new Raids(gameConfig());
$band = ['spear' => 25, 'sword' => 10];
expect($raids->muster($band, 1.0))->toBe($band)
->and($raids->muster($band, 0.5))->toBe(['spear' => 13, 'sword' => 5])
->and($raids->muster($band, 0.25))->toBe(['spear' => 6, 'sword' => 3])
->and($raids->muster($band, 0.24))->toBe([]);
});
it('leaves half its attack strength as bounty when beaten', function () {
// 25 × 10 + 10 × 25 = 500 attack → 250, a third each.
expect((new Raids(gameConfig()))->bounty(['spear' => 25, 'sword' => 10]))->toBe(['wood' => 83, 'clay' => 83, 'iron' => 83]);
});
it('comes every 18 to 30 hours at world speed, after a few hours of warning', function () {
$raids = new Raids(gameConfig());
$fast = new Raids(gameConfig(['world' => ['speed' => 100]]));
expect($raids->interval(0.0))->toBe(18 * 3600)
->and($raids->interval(0.5))->toBe(24 * 3600)
->and($fast->interval(0.5))->toBe(864)
->and($raids->gatherSeconds())->toBe(3 * 3600)
->and($fast->gatherSeconds())->toBe(108);
});
it('picks the nearest camp in range', function () {
$raids = new Raids(gameConfig());
$camps = [['id' => 7, 'x' => 10, 'y' => 0], ['id' => 3, 'x' => 0, 'y' => 4], ['id' => 2, 'x' => 4, 'y' => 0], ['id' => 9, 'x' => 16, 'y' => 0]];
expect($raids->nearest($camps, 0, 0))->toBe(2)
->and($raids->nearest([['id' => 9, 'x' => 16, 'y' => 0]], 0, 0))->toBeNull();
});