# ArkUtils Source Reference

The Breeding Line Builder's mutation probability engine is adapted from the open-source ArkUtils **How many females?** calculator.

Repository:
- https://github.com/arkutils/arkutils-website

Relevant source paths:
- `src/routes/(pages)/tools/howmanyfemales/+page.svelte`
- `src/routes/(pages)/tools/howmanyfemales/traits.ts`
- `src/routes/(pages)/tools/howmanyfemales/TraitGroup.svelte`
- `src/routes/(pages)/tools/howmanyfemales/TraitSelect.svelte`

License:
- Apache License 2.0
- Full copy included as `LICENSE-ARKUTILS.txt`.

## Baseline constants preserved by the reference implementation

- Base mutation rolls: `3`
- Base mutation roll chance: `0.025` (2.5%)
- Base higher-stat pick chance: `0.55` (55%)
- Base stat weight: `1`
- One mutation-capped parent multiplier: `0.55`
- Male-only acceptance multiplier: `0.5`

## Probability model

For non-guaranteed mutation mode:

- `fullRollChance = rollChance * cappedChance * higherPickChance * statPickChance`
- `anyMutChance = 1 - (1 - fullRollChance) ^ numRolls`
- `successChance = anyMutChance * genderChance`
- `failChance = 1 - successChance`
- females required for a desired confidence:
  `ceil(log(1 - targetConfidence) / log(failChance))`

The bundled reference build includes these calculations and should be treated as the functional regression reference when porting into the target site's framework.

## ASA trait effects preserved

- Mutable (target): +roll chance and +target stat weight; tiers 1–3.
- Robust: +higher-stat pick chance; tiers 1–3.
- Mutable (off-stat): +roll chance but adds competing off-stat weight; tiers 1–3.
- Five trait slots per parent with the ArkUtils stacking constraints preserved.

Do not silently change the math while restyling or refactoring it.
