Closed averbraeck closed 10 months ago
The following test has been taken from the documentation in the game:
The flood damage for all players in a group is calculated by the facilitator app for that group. When the facilitator enters the dice rolls and presses "ROLL DICE, SHOW DAMAGE", the calculation takes place. At the same time, the players can open the "SHOW DAMAGE" menu on their mobile phone to get a detailed assessment of the damage to their house in the current round.
HouseGroup.pluvialBaseProtection
and HouseGroup.fluvialBaseProtection
).HouseGroup.pluvialHouseProtection
and HouseGroup.fluvialHouseProtection
). Do not count measures whose valid_till_round
is filled with a round number, since they have already been consumed (e.g., sandbags).NewsEffects
, the pluvial and/or fluvial community protection can have been changed in a positive or negative way, from a certain round onward. This effect can be for a single or for multiple communities. This effect is the delta fluvial and pluvial protection.PlayerRound
record to be able to reproduce the game flow.[!WARNING]
We need to decide whetherNewsEffects
are calculated when the news is effective (changing the values in the database for the game play) or when the values are used (looping over theNewsEffects
till the current round, and applying the changes. Since most news effects do not have a field that can be updated in the database (e.g., tax discounts, living bonus, moving changes, etc.), the news effect calculation takes place where it is applied, and news effects are not changing any fields in the database.
GroupRound
record.pluvialHouseDamage
and fluvaialHouseDamage
in the subsequent items.pluvialCommunityDamage
and fluvaialCommunityDamage
in the subsequent items.(pluvialCommunityDamage > 0)
, the HouseGroup.lastRoundCommPluvial
field is set to the current round number.(fluvialCommunityDamage > 0)
, the HouseGroup.lastRoundCommFluvial
field is set to the current round number.(pluvialHouseDamage > 0)
, the HouseGroup.lastRoundHousePluvial
field is set to the current round number.(fluvialHouseDamage > 0)
, the HouseGroup.lastRoundHouseFluvial
field is set to the current round number.PlayerRound
table, since they can be recalculated (the protection levels for the current round and the current house are stored in the PlayerRound
table). validTillUsage
value being true in MeasureType
. (pluvialHouseDamage < 0)
(note: when == 0, all measures were needed), see if there were one or more measures that are valid till usage, and that can be left out to still have a damage <= 0. Watch for side-effects where the fluvial damage might become > 0.(fluvialHouseDamage < 0)
(note: when == 0, all measures were needed), see if there were one or more measures that are valid till usage, and that can be left out to still have a damage <= 0. Watch for side-effects where the pluvial damage might become > 0.consumedInRound
value to the current round number.ScenarioParameters
table has all the costs and penalties as either fixed or per point, and split between pluvial and fluvial damage and between house and community.PlayerRound
table has entries for costFluvialDamage
and costPluvialDamage
. The calculation has a fixed component (if damage > 0 add cost) and a dynamic component (add damage * cost). The costs need to be subtracted from the spendableIncome
.PlayerRound
table has entries for satisfactionFluvialPenalty
and satisfactionPluvialPenalty
. The calculation has a fixed component if the area is flooded (if communityDamage > 0 add penalty), a fixed component if the house is flooded (if houseDamage > 0, add penalty) and a dynamic component if the house if flooded (add penalty * house damage). The penalties need to be subtracted from the personalSatisfaction
. [!WARNING] Satisfaction penalties can lead to negative satisfaction. The
ScenarioParameters
indicate whether negative satisfaction for the player is allowed or not. This has to be taken into account in the calculation.[!NOTE] Flood damage impacts the personal satisfaction. It is not something that is bought or sold with the house, such as the positive psychological effect of having applied measures to the house.
NewsEffects
, the house can lose value if it has been flooded, also in subsequent rounds. The damageReduction
field has to be calculated for the house, based on news effects, independent of whether it was flooded in this round or in previous rounds.marketValue
of the house (lastSoldPrice - damageReduction)
or if lastSoldPrice
is null, (originalPrice - damageReduction)
.[!WARNING] Damage reductions also need to be calculated for houses that have not yet been sold. This is difficult for houses that are not yet on the market. We have to see how to proceed here...
The extra fields have been added to the database, see https://github.com/averbraeck/housinggame-common/issues/21
The dice roll has been implemented. processing is a tremendously long piece of code... The results of a dice roll 8, 8 for a test group (Table6) is as follows:
The results will be analyzed below.
Flood penalties and costs have also transferred to the players:
It looks like the flood table calculations are correct. The player table, however, does not show the correct flood penalty -- the numbers shown per player are not the sum of the damage numbers in the flood table. Let's check the costs:
Player t6p1 owns house D01. This house sustained 2 rain damage points, costing 4 k. Player t6p5 owns house U04. This house sustained 1 river damage point, costing 4 k.
The database has the following values for player t6p1, which is correct:
The database has the following values for player t6p5, which is correct:
One error was caused by not storing the pluvial and fluvial house protection with the HouseGroup
after buying measures. This has been corrected.
The calculation of the satisfaction points is actually correct:
There is a 1-point fixed fluvial satisfaction penalty if the area gets flooded plus a 1-point penalty per damage point if the house sustains fluvial damage. For the house above, this adds to 2 points.
The NewsEffects are taken into account in the community protection calculations. E.g., in round 3, the protection changes:
This leads in the flood table for round 3 and beyond to:
Calculations are complete, with the exception of depleting the resources for one-time measures, in case they had to be used.
The data entry is already there, but the damage calculation for players with a house has not yet been done.