mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-03 11:01:03 +00:00
Add expand ratio to bot behavior class (#1376)
## Description: - Create a new expand ratio that allows AI players to expand with a much lower reserve ratio than the normal attack reserve ratio. - Unify the implementation of the first attack between bots and nations. - Bugfix: Multiple attacks per tick could cause nations to full-send. - Improve the chance of finding a place to boat to by allowing nations to target non-shore land tiles. ## Please complete the following: - [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
This commit is contained in:
@@ -18,14 +18,13 @@ export class BotBehavior {
|
||||
|
||||
private assistAcceptEmoji = flattenedEmojiTable.indexOf("👍");
|
||||
|
||||
private firstAttackSent = false;
|
||||
|
||||
constructor(
|
||||
private random: PseudoRandom,
|
||||
private game: Game,
|
||||
private player: Player,
|
||||
private triggerRatio: number,
|
||||
private reserveRatio: number,
|
||||
private expandRatio: number,
|
||||
) {}
|
||||
|
||||
handleAllianceRequests() {
|
||||
@@ -211,14 +210,12 @@ export class BotBehavior {
|
||||
if (target.isPlayer() && this.player.isOnSameTeam(target)) return;
|
||||
const maxPop = this.game.config().maxPopulation(this.player);
|
||||
const maxTroops = maxPop * this.player.targetTroopRatio();
|
||||
const targetTroops = maxTroops * this.reserveRatio;
|
||||
// Don't wait until it has sufficient reserves to send the first attack
|
||||
// to prevent the bot from waiting too long at the start of the game.
|
||||
const troops = this.firstAttackSent
|
||||
? this.player.troops() - targetTroops
|
||||
: this.player.troops() / 5;
|
||||
const reserveRatio = target.isPlayer()
|
||||
? this.reserveRatio
|
||||
: this.expandRatio;
|
||||
const targetTroops = maxTroops * reserveRatio;
|
||||
const troops = this.player.troops() - targetTroops;
|
||||
if (troops < 1) return;
|
||||
this.firstAttackSent = true;
|
||||
this.game.addExecution(
|
||||
new AttackExecution(
|
||||
troops,
|
||||
|
||||
Reference in New Issue
Block a user