Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DefaultAI

A heuristics based A.I

This is the default opponent for singleplayer.

It is built on heuristics and does not use any tree search based algorithm. As such, it runs quite fast but is prone to making short sighted moves.

Known Flaws

  • Doesn't currently consider the value of enchantments when empowering them (only their cost)
  • Doesn't currently take most global effects into play such as the effect of Death's Ascendence (which makes it pointless to play certain units as they will die instantly)
  • See documentation of attack and block methods for weaknesses in attack/blocking logic

Hierarchy

  • AI
    • DefaultAI

Index

Constructors

constructor

  • Creates an instance of DefaultAI.

    Parameters

    • playerNumber: number

      The number of the player the A.I will control

    • game: ClientGame

      The interface by which the A.I will take actions and observe state

    • deck: DeckList

      The DeckList of the deck the A.I will play

    Returns DefaultAI

Properties

Protected actionSequence

actionSequence: Array<function> = []

Protected aiPlayer

aiPlayer: Player

Protected Optional animator

animator: Animator

Protected deck

deck: DeckList

The DeckList of the deck the A.I will use

Protected enemyNumber

enemyNumber: number

Protected game

A ClientGame instance for the A.I to observe and take actions

Protected isImmediateMode

isImmediateMode: boolean = false

Protected playerNumber

playerNumber: number

The number of the player which the A.I will control

Protected thinking

thinking: boolean = false

Methods

Protected addActionToSequence

  • addActionToSequence(action: function, front?: boolean): void
  • Adds an action to be run at some point in the future depending on the A.Is timing mode

    Parameters

    • action: function

      The action to be added to the sequence

        • (): boolean
        • Returns boolean

    • Default value front: boolean = false

      If true the action will be added to the beginning of the sequence, otherwise it will go at the end.

    Returns void

Protected applyNextAction

  • applyNextAction(): void
  • Checks if we can take an action, if we can then takes the next one in the action sequence.

    Returns void

Protected attack

  • attack(): boolean
  • Chooses which, if any, units to attack with. The A.I will choose to attack with any units it would not block if it were the opponent. That is to say, any unit where the canFavorablyBlock function returns false for all enemy units.

    Known Flaws

    • The A.I should attack if it could guarantee lethal damage regardless of trades, but that is not implemented.
    • The A.I should consider potential multi-blocks from the enemy, but it dose not.
    • The A.I should consider whether it is best to leave a unit on defense, even if its a good attacker e.g if the enemy has much more life than us and attacking with that unit will give them good attacks.

    Returns boolean

Protected block

  • block(): void
  • Determines what units should block enemy attackers.

    If the enemy attack is potentially lethal, the A.I will focus on minimizing damage in the least disadvantageous way but it will be willing to sacrifice units to block without trading (chump blocks).

    Otherwise the A.I will only make blocks considered to be favorable by the canFavorablyBlock function.

    Known Flaws

    • The A.I should consider chump blocking if its health is more valuable than the unit it would sacrifice.
    • The A.I should consider multi-blocks, but it dose not.

    Returns void

Protected canFavorablyBlock

  • canFavorablyBlock(attacker: Unit, blocker: Unit): boolean
  • Analyzes whether a blocker can favorably block an attacker. A block is considered favorable under any of the following circumstances

    1. Only the attacker would die
    2. Neither the attacker nor the blocker would die
    3. Both the attacker and the blocker die, but the attacker is more valuable than the blocker.

    Notably, this function cannot handle blocking with multiple units (even though that is legal).

    Parameters

    • attacker: Unit

      The attacking unit to consider blocking

    • blocker: Unit

      The blocker to consider

    Returns boolean

Protected cardDrawHeuristic

  • cardDrawHeuristic(card: Card): number
  • A simple heuristic to determine which card is best to draw This heuristic assumes it is best to draw cards whose cost is close to the amount of resources we have.

    Parameters

    Returns number

Protected categorizeBlock

  • Categorizes a block by what its outcome will be (if the attacker, blocker or both will die)

    Parameters

    Returns BlockOutcome

Protected evaluateCard

  • Evaluates a card based on its value and the value of its target.

    Parameters

    • card: Card

      The card to be evaluated

    Returns EvaluatedAction

    • The EvaluatedAction with the score and any targets

Protected evaluateEnchantment

  • Creates an evaluated action from an enchantment.

    Currently the score is based on the ratio between the enchantments cost and its power.

    Parameters

    Returns EvaluatedAction

Protected evaluateToDiscard

  • evaluateToDiscard(choices: Card[], min: number, max: number): Card[]
  • Decides which cards of a set of choices to discard The heuristic is the inverse of the to draw heuristic.

    Parameters

    • choices: Card[]
    • min: number
    • max: number

    Returns Card[]

Protected evaluateToDraw

  • evaluateToDraw(choices: Card[], min: number, max: number): Card[]
  • Decides which cards of a set of choices to choose to draw.

    Parameters

    • choices: Card[]
    • min: number
    • max: number

    Returns Card[]

Protected evaluateToReplace

  • evaluateToReplace(choices: Card[], min: number, max: number): Card[]
  • Decides which cards of a set to replace. We replace a card if we think it is worse than the average card in our deck based on the card draw heuristic.

    Parameters

    • choices: Card[]
    • min: number
    • max: number

    Returns Card[]

Protected getBestHost

  • Gets the best host for an item. Currently it simply returns the unit with the highest value multiplier (ignoring the properties of the item).

    Parameters

    • item: Item

      The item to find a host for

    Returns Unit

Protected getBestTarget

  • Gets the best target for a card with a targeter. The best target is considered to be the one with the highest evaluateTarget value.

    Parameters

    Returns EvaluatedAction

Protected getCardToChoose

  • Returns the cards that should be chosen for a given choice based on its heuristic

    Parameters

    Returns Card[]

Protected getClosestUnmetRequirement

  • getClosestUnmetRequirement(cards: Card[]): undefined | Card
  • Returns the card whose resource pre reqs are not met, but are the closest to being met

    Parameters

    Returns undefined | Card

getDeckbuilder

  • Returns a deckbuilder to be used for limited tournaments

    Returns DeckBuilder

Protected getHeuristic

  • Get the appropriate heuristic for making a choice

    Parameters

    Returns function

      • (choices: Card[], min: number, max: number): Card[]
      • Parameters

        • choices: Card[]
        • min: number
        • max: number

        Returns Card[]

Protected getModifiableEnchantments

  • Returns the enchantments we have enough energy to empower or diminish

    Returns Enchantment[]

Protected getMostCommonResource

  • getMostCommonResource(cards: Card[]): string
  • Computes the most common resource among a set of cards (such as a deck or hand)

    Parameters

    Returns string

getPlayerNumber

  • getPlayerNumber(): number
  • Gets the number of the player this A.I controlls

    Returns number

Protected getReqDiff

  • Gets the difference in resources (not energy) between two values

    Parameters

    Returns object

    • resources: Map<string, number>
    • total: number

Protected getResourceToPlay

  • getResourceToPlay(): string
  • Decides what resource to play next based on the following heuristic.

    If the A.I has unplayable cards it in its hand, it looks at its hand and decides which card it is closest to being able to play but is not yet able to. It chooses a resource which gets it closer to playing that card.

    Otherwise it applies the same logic, but to its deck list.

    Finally, if it can play every card in its hand and deck, it simply plays the most common resource in its deck (based on average card cost).

    Returns string

    • The name of the resource to play

handleGameEvent

  • Parameters

    • event: GameSyncEvent

      A Game Synchronization Event sent by the server

    Returns void

Protected highestStatHeuristic

  • highestStatHeuristic(choices: Card[], min: number, max: number): Card[]
  • A heuristic that chooses the unit with the highest total stats (all choices must be Units)

    Parameters

    • choices: Card[]
    • min: number
    • max: number

    Returns Card[]

Protected makeBlockAction

  • makeBlockAction(params: object): (Anonymous function)
  • Declares a blocker as blocking a particular attacker

    Parameters

    • params: object

    Returns (Anonymous function)

Protected makeChoice

  • makeChoice(player: number, options: Array<Card>, min?: number, max?: number, callback?: function | null, message: string, heuristicType: ChoiceHeuristic): void
  • Makes a choice when requested to by the game engine (such as what cards to mulligan)

    Parameters

    • player: number
    • options: Array<Card>
    • Default value min: number = 1
    • Default value max: number = 1
    • Default value callback: function | null = null
    • message: string
    • heuristicType: ChoiceHeuristic

    Returns void

onGainPriority

  • onGainPriority(): void
  • Signals to the A.I that it has gained priority and may take actions

    Returns void

Protected playResource

  • playResource(): boolean
  • Returns boolean

Protected runCardPlayAction

  • Plays a card based on an action

    Parameters

    Returns boolean

Protected runEvaluatedAction

  • Runs an action (either playing a card or modifying an enchantment)

    Parameters

    Returns boolean

Protected selectActions

  • selectActions(): boolean
  • Selects a series of actions to take. Currently there are two actions, playing a card or modifying an enchantment.

    All actions have a energy cost thus to determine which ones to use we compute their heuristic values. Then we use a knapsack algorithm to get the highest total value of actions with our available energy.

    Returns boolean

Protected sequenceActions

  • sequenceActions(actions: Array<function>): void
  • Adds a list of actions to be run to end of the sequence.

    Parameters

    • actions: Array<function>

      The actions to add

    Returns void

startActingDelayMode

  • startActingDelayMode(delayTimeMs: number, animator: Animator): void
  • Tells the A.I to start taking actions, but to spread them out over time. It will also wait until the given animator has completed any animations. This is to keep the A.I from taking all its actions simultaneously when playing against a human.

    Parameters

    • delayTimeMs: number
    • animator: Animator

    Returns void

startActingImmediateMode

  • startActingImmediateMode(): void
  • Tells the A.I to start acting and to immediatly take any action it likes. This is to make the A.I faster for A.I vs A.I battles

    Returns void

stopActing

  • stopActing(): void
  • Tells the A.I to stop taking any moves when the game is over

    Returns void

Protected think

  • think(): void
  • Triggers the A.I to consider what its next action should be

    Returns void

Static getDeckbuilder

Generated using TypeDoc