Skip to main content

simulate_battle

Function simulate_battle 

Source
pub fn simulate_battle(
    left: &[Fighter],
    right: &[Fighter],
    iterations: u32,
    is_arena_battle: bool,
) -> FightSimulationResult
Expand description

Simulates iterations many fights between both sides. The returned result will be from the perspective of the left side. A win ratio of 1.0 will mean, the left side win all fights.

Both sides are Fighter’s. These can be derived from UpgradeableFighter and Monster.

To obtain an UpgradeableFighter, we create a PlayerFighterSquad, which can then be turned into a fighter and be used in simulations.

use sf_api::{simulate::{Fighter, PlayerFighterSquad, UpgradeableFighter}, gamestate::GameState};
let gs: GameState = GameState::default();
let squad = PlayerFighterSquad::new(&gs);
let player: UpgradeableFighter = squad.character;
let fighter: Fighter = Fighter::from(&player);

We go through the PlayerFighterSquad, because calculating the stats for player + companion is pretty much as fast, as computing the stats for just the player. Similarely, we use Fighter, not UpgradeableFighter, because calculating the final stats of any fighter (attributes, rune values, etc) is work, that we would not want to do each time this function is invoked.

To obtain monsters, we use current_enemy() on Dungeons.

use sf_api::{simulate::{Fighter, UpgradeableFighter}, gamestate::{dungeons::LightDungeon, GameState}};
let gs: GameState = GameState::default();
let Some(monster) = gs.dungeons.current_enemy(LightDungeon::MinesOfGloria) else { return };
let fighter: Fighter = Fighter::from(monster);