From adba99e76784676491847cbbe827025560525113 Mon Sep 17 00:00:00 2001 From: Guido Knips Date: Mon, 28 Aug 2023 20:29:46 +0200 Subject: [PATCH] Add documentation for tourist trade bug in King - really bad pollution can get positive money from tourists - fix issue in python implementation, other implementations still lack it --- 53_King/README.md | 15 +++++++++++++++ 53_King/python/king.py | 6 ++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/53_King/README.md b/53_King/README.md index 14a66fe9a..83fb61c33 100644 --- a/53_King/README.md +++ b/53_King/README.md @@ -78,3 +78,18 @@ On basic line 1310 we see this: but it should probably be: 1310 IF J=0 THEN 1324 + +### Bug 5 + +On basic line 1390 the income from tourism is calculated: + +``` +1390 A=INT(A+Q) +1400 V1=INT(((B-P1)*22)+(RND(1)*500)) +1405 V2=INT((2000-D)*15) +1410 PRINT " YOU MADE";ABS(INT(V1-V2));"RALLODS FROM TOURIST TRADE." +``` + +It is very easily possible that `V2` is larger than `V1` e.g. if all of the land has been sold. In the original game this does not make a difference because of Bug 1 (see above). + +However, judging by how `V1` and `V2` are handled in the code, it looks like `V1` is the basic income from tourism and `V2` is a deduction for pollution. When `ABS(INT(V1-V2))` is used as earnings from tourism, the player actually _gets_ money for a large enough pollution. So a better solution would be to let `V1 - V2` cap out at 0, so once the pollution is large enough, there is no income from tourists anymore. diff --git a/53_King/python/king.py b/53_King/python/king.py index 9c8d075c0..a4d9b7696 100644 --- a/53_King/python/king.py +++ b/53_King/python/king.py @@ -61,7 +61,7 @@ def settled_people(self) -> int: return self.countrymen - self.population_change def sell_land(self, amount: int) -> None: - assert amount < self.farmland + assert amount <= self.farmland self.land -= amount self.rallods += self.land_buy_price * amount @@ -126,7 +126,9 @@ def handle_deaths( def handle_tourist_trade(self) -> None: V1 = int(self.settled_people * 22 + random() * 500) V2 = int((INITIAL_LAND - self.land) * 15) - tourist_trade_earnings = int(V1 - V2) + tourist_trade_earnings = 0 + if V1 > V2: + tourist_trade_earnings = V1 - V2 print(f" YOU MADE {tourist_trade_earnings} RALLODS FROM TOURIST TRADE.") if V2 != 0 and not (V1 - V2 >= self.tourism_earnings): print(" DECREASE BECAUSE ")