Skip to content

Commit

Permalink
Merge pull request #892 from GKnirps/king_tourist_bug
Browse files Browse the repository at this point in the history
Add documentation for tourist trade bug in King
  • Loading branch information
coding-horror authored Aug 28, 2023
2 parents 0b7b162 + adba99e commit c0ce909
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions 53_King/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 4 additions & 2 deletions 53_King/python/king.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ")
Expand Down

0 comments on commit c0ce909

Please sign in to comment.