Card’s cost computing algorithm

Overview of a card’s cost

Each Age card can be discovered by paying their costs. Each card has between one and two costs. Each cost is covered either by paying the associated knowledge cost or, if a card name is indicated, having the card in the player’s active or research area.

Algorithm used in this adaptation

Instead of relying on cards name, the Age cards are all given a type Id (see PETAgeCard) which is used to check whether a card is present in any of the aforementioned locations.

The algorithm follows this workflow:

  1. Initialize the $cost array to the following structure:

    Knowledge type

    Value

    Science

    0

    Engineering

    0

    Culture

    0

    General knowledge

    0

  2. Get the cost(s) of the card

  3. For each cost:

    1. If a card can cover the cost:

      1. Check if a card of this type is present in the player’s active cards or research cards:

        • If a card is found, don’t change the $cost array

        • If not, add the cost the the corresponding knowledge type and to the General Knowledge type of the $cost array

      2. If no corresponding card is present, add the cost the the corresponding knowledge type and to the General Knowledge type of the $cost array

    2. If no card is present, add the cost the the corresponding knowledge type and to the General Knowledge type of the $cost array

Algorithm used to see if discarded cards and used tokens cover the costs of the card being discovered

The algorithm works through the following steps:

  1. Generate the $cost array of the card being discovered using the above algorithm.

  2. For each used token:

    • Reduce the value of the token’s Knowledge type in the $cost array.

    • Also reduce the value of the General Knowledge

  3. For each discarded card:

    • Reduce the value of the General Knowledge type in the $cost array.

  4. Check if the General Knowledge value in the $cost array is equal to 0:

    • If so, the costs have been covered, and the card can be discovered

    • If not, the costs haven’t been covered, add the resources to the player’s remaining resources in the DB.