Options
All
  • Public
  • Public/Protected
  • All
Menu

oath-odds

Index

Type aliases

CampaignResult

CampaignResult: AttackResult & DefenseResult

Type to hold a campaign result.

Variables

Const AttackDie

AttackDie: RandomDevice<AttackDieFace> = new RandomDevice<AttackDieFace>([[AttackDieFace.HOLLOW_SWORD, new Fraction(3, 6)],[AttackDieFace.SWORD, new Fraction(2, 6)],[AttackDieFace.TWO_SWORDS_AND_SKULL, new Fraction(1, 6)],])

The Oath attack (red) die.

Const DefenseDie

DefenseDie: RandomDevice<DefenseDieFace> = new RandomDevice<DefenseDieFace>([[DefenseDieFace.BLANK, new Fraction(2, 6)],[DefenseDieFace.SHIELD, new Fraction(2, 6)],[DefenseDieFace.TWO_SHIELDS, new Fraction(1, 6)],[DefenseDieFace.DOUBLE, new Fraction(1, 6)],])

The Oath defense (blue) die.

Functions

arrayEquals

  • arrayEquals<T>(a: T[], b: T[]): boolean
  • Compare 2 arrays using ===. No deep comparaison.

    Type parameters

    • T

      The type of the elements contained in the arrays.

    Parameters

    • a: T[]

      First array.

    • b: T[]

      Second array.

    Returns boolean

    True if a and b contains the same values in the same order.

campaignResultCompareFn

  • Compare 2 campaign results with following rules:

    • attack descending
    • then defense ascending
    • then kill ascending

    Parameters

    Returns number

    1 if a > b, 0 if a = B and -1 if a < b

cartesianProduct

  • cartesianProduct<T>(...sets: T[][]): T[][]
  • Computes the cartesian product of arrays of elements.

    cartesianProduct([1, 2], [3, 4]) // [[1, 3], [1, 4], [2, 3], [2, 4]]

    Type parameters

    • T

    Parameters

    • Rest ...sets: T[][]

      The sets to use for the cartesian product.

    Returns T[][]

    The cartesian product of all provided sets.

combineSetWithOdds

  • Combine two sets with odds into a single one. Sets are merged and odds are multiplied.

    Type parameters

    • O

      Type for the first set.

    • P

      Type for the second set.

    Parameters

    • first: WithOdds<O[]>

      The first set to be combined.

    • second: WithOdds<P[]>

      The second set to be combined.

    Returns WithOdds<(O | P)[]>

    The result of combining the two sets.

computeCampaignSuccess

  • computeCampaignSuccess(attackDice: number, attackingForceWarbands: number, defenseDice: number, defendingForceWarbands: number): CampaignSuccess[]
  • Parameters

    • attackDice: number
    • attackingForceWarbands: number
    • defenseDice: number
    • defendingForceWarbands: number

    Returns CampaignSuccess[]

flatten

  • flatten<T>(elems: T[][]): T[]
  • Flattens an array of arrays.

    Type parameters

    • T

      The type of the elements contained in the arrays.

    Parameters

    • elems: T[][]

      An array of arrays.

    Returns T[]

    A flattened array.

gcd

  • gcd(a: number, b: number): number
  • Computes the greatest common divider of 2 integers.

    Parameters

    • a: number

      First integer.

    • b: number

      Second integer.

    Returns number

    Greatest common divider of a and b.

merge

odds

  • Computes all possible sets from the provided list of random devices along with the odds of obtaining this particular set.

    Type parameters

    • T

    Parameters

    • devices: RandomDevice<T>[]

      The list of random devices from which to generate possible sets.

    Returns WithOdds<T[]>[]

    All possible sets that can be obtainded from this lsit of random devices along with the odds of obtaining this particular set.

remainingWarbandsAfterSacrifice

  • remainingWarbandsAfterSacrifice(result: CampaignResult, attackingForceWarbands: number, defendingForceWarbands: number): number | null
  • Computes the remaining warbands in attacking force by applying the kills from the dice roll and sacrificing the number of warbands needed to succeed. If the result is negative, it means by this campaign can't be a success (not enough warbands to sacrifice).

    Parameters

    • result: CampaignResult

      The campaign result.

    • attackingForceWarbands: number

      The number of warbands in attacking force.

    • defendingForceWarbands: number

      The number of warbands in defending force.

    Returns number | null

    The remaining warbands or null if the campaign is a loss.

replace

  • replace<T>(elems: T[], idx: number, elem: T): T[]
  • Returns a new array with element at index idx replaced with elem.

    Type parameters

    • T

      The type of the elements contained in the array.

    Parameters

    • elems: T[]

      The original array.

    • idx: number

      The index at which to replace.

    • elem: T

      The element to place at the specified index.

    Returns T[]

    A new array with the element replaced.

roll

  • roll<O, R>(device: RandomDevice<O>, numberOfDevices: number, resultTransformationFn: (outcomes: O[]) => R, resultEqualFn: (a: R, b: R) => boolean): WithOdds<R>[]
  • Type parameters

    • O

    • R

    Parameters

    • device: RandomDevice<O>
    • numberOfDevices: number
    • resultTransformationFn: (outcomes: O[]) => R
        • (outcomes: O[]): R
        • Parameters

          • outcomes: O[]

          Returns R

    • resultEqualFn: (a: R, b: R) => boolean
        • (a: R, b: R): boolean
        • Parameters

          • a: R
          • b: R

          Returns boolean

    Returns WithOdds<R>[]

rollAttack

  • Lists all possible results of an attack roll.

    Parameters

    • diceNumber: number

      Number of attack (red) dice to roll.

    Returns WithOdds<AttackResult>[]

    All possible results of rolling this number of attack dice.

rollCampaign

  • Lists all possible results of a campaign in Oath along with their odds.

    Parameters

    • attackDice: number

      Number of attack (red) dice to roll.

    • defenseDice: number

      Number of defense (blue) dice to roll.

    Returns WithOdds<CampaignResult>[]

    All possible results for this campaign along with their odds.

rollDefense

  • Lists all possible results of defense roll.

    Parameters

    • diceNumber: number

      Number of defense (blue) dice to roll.

    Returns WithOdds<DefenseResult>[]

    All possible results of rolling this number of defense dice.

toAttackResult

  • Sums up a set of attack die faces into an attack roll result.

    Parameters

    Returns AttackResult

    The attack roll result after adding all die faces.

toDefenseResult

  • Sums up a set of defense die faces into a defense roll result.

    Parameters

    Returns DefenseResult

    The defense roll result after adding all die faces.

Generated using TypeDoc