coding-horror / basic-computer-games

An updated version of the classic "Basic Computer Games" book, with well-written examples in a variety of common MEMORY SAFE, SCRIPTING programming languages. See https://coding-horror.github.io/basic-computer-games/
The Unlicense
10.84k stars 1.33k forks source link

12 BombsAway java version always asks for gunner hit rate #457

Closed havoclad closed 2 years ago

havoclad commented 2 years ago

To reproduce

  1. java BombsAwayGame
  2. What side - 1
  3. Target - 1
  4. Missions - 1
  5. What does the enemy have - 2

The response is "What's the percent rate of enemy gunners (10 to 50)?" This should only happen for choices 1 and 3, compare to the basic, javascript or perl versions.

Screen Shot 2022-01-07 at 9 47 01 PM

coding-horror commented 2 years ago

aha did we contact the person who submitted the pull request?

havoclad commented 2 years ago

git log --follow suggests that @journich might be the author of BombsAway.java

journich commented 2 years ago

Thanks for reporting this @havoclad - I have uploaded a fix for this and for some missing functionality from the original game. Please test and let me know if you have any other problems. @coding-horror FYI.

havoclad commented 2 years ago

This bug is fixed, thanks! Thanks for supporting code your wrote almost a year ago @journich

However, I think there is another inconsistency in the damage calculation. I noticed I wasn't getting shot down nearly often enough when selecting choice 3 (both) and looked at the code.

Lines 289 case GUNS: is commented that it's identical code to case BOTH. This is incorrect. Case BOTH should apply chanceToBeHit as well as percentageHitRateOfCunners while case GUNS should only apply the latter.

These are analogous to T and S in the original basic code.

Line 350 runs the percent hit rate code unless choice 2 is made while line 360 applies the extra 35 if the choice is greater than one.

journich commented 2 years ago

Thanks @havoclad - I totally missed that and the fix is in place now. Please take a look. In my testing I certainly get shot down a lot more when selecting BOTH, although it is still possible to succeed.

What BASIC interpreter are you using to test? I am using Chipmunk BASIC on a Mac with Apple Silicon and the very first time I play a game from scratch I always get a direct hit, but when I select Y to play again it seems to function normally.

havoclad commented 2 years ago

I'm using Vintage Basic

coding-horror commented 2 years ago

That's another open question, what's the "official" way to verify the original BASIC code behavor? 🤔

Would be nice if we had a web-based VM for this

havoclad commented 2 years ago

This book also has a bug in this program which bombsaway.bas in this repo does not. I wonder when it was addressed?

It wasn't fixed in the way I did back in '79 or so. I remember because it was the first time I found a bug in something published, lol.

https://annarchive.com/files/Basic_Computer_Games_Microcomputer_Edition.pdf has the version I remember.

207 IF F$="N" THEN S=0 : GOTO 358

There is no 358 :) It seems obvious to me that GOTO 357 was meant, after all. To get to line 207 the user just claimed that he or she was not on their first kamikaze mission. Setting S to 0 right before the GOTO clinches it, it should go to 357 with the great line, "YOU LIE, BUT YOU'LL PAY..."

journich commented 2 years ago

Thanks @havoclad I'll give Vintage Basic a go and see how it turns out.

I can't answer that question about the bug being fixed. It would be good to know for sure which original version of the code we are using to create our ports of the game.

Maybe the bugfixes got fixed in a reprint of the book?

journich commented 2 years ago

That's another open question, what's the "official" way to verify the original BASIC code behavor? 🤔

Would be nice if we had a web-based VM for this

@coding-horror I had a little hunt for a web-based VM but the ones I played around with had problems with multiple statements on the one line and the use of TAB to add spaces to output.

i.e.

PRINT "TRY AGAIN..." : GOTO 10

and

PRINT TAB(26);"ACEY DUCEY CARD GAME"

journich commented 2 years ago

Closing this one as I believe the bug is fixed. Let me know @havoclad if you have any other issues.

Thanks for your help in finding the bugs and testing.