Improve readability of alliance acceptation logic for bots and add tests (#1049)

## Description:
The method deciding whether bots should accept an alliance used to use
multiple variables with negated names (notTraitor, notMalice,
notTooManyAlliances). For readability, I have negated their value in
order to given them a positive name (isTraitor, hasMalice,
tooManyAlliances).

I have also added tests for the alliances acceptation/rejection behavior
of bots.

- [x] I have added screenshots for all UI updates
- [X] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [X] I have added relevant tests to the test directory
- [X] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [X] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

Discord: nephty
This commit is contained in:
Arnaud Moreau
2025-06-06 20:57:02 +02:00
committed by evanpelle
parent dd45f64953
commit 080cf8f3f8
2 changed files with 156 additions and 5 deletions
+6 -5
View File
@@ -202,11 +202,12 @@ export class BotBehavior {
}
function shouldAcceptAllianceRequest(player: Player, request: AllianceRequest) {
const notTraitor = !request.requestor().isTraitor();
const noMalice = player.relation(request.requestor()) >= Relation.Neutral;
const isTraitor = request.requestor().isTraitor();
const hasMalice = player.relation(request.requestor()) < Relation.Neutral;
const requestorIsMuchLarger =
request.requestor().numTilesOwned() > player.numTilesOwned() * 3;
const notTooManyAlliances =
requestorIsMuchLarger || request.requestor().alliances().length < 3;
return notTraitor && noMalice && notTooManyAlliances;
const tooManyAlliances = request.requestor().alliances().length >= 3;
return (
!isTraitor && !hasMalice && (requestorIsMuchLarger || !tooManyAlliances)
);
}