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:
Initialize the
$cost
array to the following structure:Knowledge type
Value
Science
0
Engineering
0
Culture
0
General knowledge
0
Get the cost(s) of the card
For each cost:
If a card can cover the cost:
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
arrayIf not, add the cost the the corresponding knowledge type and to the General Knowledge type of the
$cost
array
If no corresponding card is present, add the cost the the corresponding knowledge type and to the General Knowledge type of the
$cost
array
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:
Generate the
$cost
array of the card being discovered using the above algorithm.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
For each discarded card:
Reduce the value of the General Knowledge type in the
$cost
array.
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.