Paul's 4k Adventure - coder's help needed (again)

Games for Spectrum, C64, Amstrad, Amiga, Apple ][ and the rest of the 8-bit and 16-bit platforms. Pleas for help, puzzles, bug reports etc.

Moderator: Alastair

Message
Author
Mark
Posts: 90
Joined: Sun Feb 27, 2005 7:04 pm
Location: Germany

Paul's 4k Adventure - coder's help needed (again)

#1 Post by Mark »

So, it seems that my affection for trashy games has led me to this game author...

The game in question (Paul's 4k Adventure, to be downloaded at the GB 64) features battles with a kind of random system. There is a battle against a knight, which is, to all my knowledge, impossible to win. And I suspect that is a bug. The reason why I suspect this: when the game tells me "you hit knight very hard" (or a related expression), it actually subtracts a fundamental amount of hit points from me instead of from the knight.

Maybe one of you guys with coding knowledge could have a look at the battle system and check if all's right there, or if I missed something vital (a specific combination of items or so). Thanks a lot!
Mr Creosote
Posts: 1121
Joined: Tue Sep 22, 2009 9:23 am
Contact:

Re: Paul's 4k Adventure - coder's help needed (again)

#2 Post by Mr Creosote »

There's also a C16 version of the game. Have you tried whether the same thing occurs there, too?
Mark
Posts: 90
Joined: Sun Feb 27, 2005 7:04 pm
Location: Germany

Re: Paul's 4k Adventure - coder's help needed (again)

#3 Post by Mark »

Mr Creosote wrote:There's also a C16 version of the game. Have you tried whether the same thing occurs there, too?
Not yet, and frankly, I don't think I want to. I have tried to play quite a few C16 adventures by now, and for some reason my VICE C16 emulator always shuts itself down when I try to save a snapshot image (practically the only real way to save a game). The whole C16 business is way too annoying for my level of patience :-).

Also, from what I know about Commodore basic, I reckon the code is identical between the C16 and C64.
dave
Posts: 606
Joined: Tue Aug 21, 2007 10:20 pm

Re: Paul's 4k Adventure - coder's help needed (again)

#4 Post by dave »

The code looks to be fine:

Code: Select all

211 MH=INT(RND(1)*350)+1:YY$="WITH A BONE-CRUSHING SOUND."
212 PRINT">":I=INT(RND(1)*25)+1:FORX=1TO500:NEXT:YS$="YOU SMASHED "
213 WD=1:FORX=1TO21:IFLO(X)=105THENPRINT"YOU ARE WIELDING ";NO$(X);"’.":WD=X:X=21
214 NEXT
215 PRINT"YOU ARE FIGHTING ";NO$(N);"."
216 PRINT">":IFI<=5THENPRINT"YOU MISSED."
217 IFI>=6ANDI<=10THENPRINT"YOU STRUCK A SOLID BLOW.":MH=MH-I
218 IFI>=11ANDI<=15THENPRINT"YOU HIT ";NO$(N):PRINT"VERY HARD.":MH=MH-WD:MH=MH-I
219 IFI>=16ANDI<=20THENPRINTYS$;NO$(N):PRINT YY$:MH=MH-(WD*2):MH=MH-I
220 IFI>=21THENPRINT"IT DODGED YOUR BLOW."
221 PRINT"YOUR HP’:";HP;"/";HM
222 PRINT"THEIRS ’:";MH
223 PRINT">":FORX=1TO300:NEXT
225 P=INT(RND(1)*25)+1:IFP<=5THENPRINT"THEY MISSED YOU."
226 IFP>=6ANDP<=10THENPRINT"YOU WERE HIT HARD.":HP=HP-P
227 IFP>=11ANDP<=15THENPRINT"YOU WERE SMASHED INTO FRAGMENTS.":HP=HP-P*8:HP=HP+AC
228 IFP>=16THENPRINT"YOU DODGED THE ATTACK."
229 PRINT">":FORX=1TO100:NEXT
230 IFMH<1THENPRINT"THE ";NO$(N);" DIED.":PRINT"YOU KILLED ";NO$(N);".":GOTO 240
231 IFHP<1THENPRINT"YOU DIED.":FORX=1TO1000:NEXT:PRINT:PRINT"GAME OVER’":CLR:END
232 GOTO212
The code is basically:
  • Choose a random amount of HP for the enemy (between 1 and 350)
  • Your strike - damage depends on whether you're wielding the sword
    • Choose a random number between 1 and 25
    • 1-5 = miss, no damage to enemy
    • 6-10 = normal hit, do between 6-10 points of damage
    • 11-15 = hit very hard, do 11-15 points of damage and add the damage of the sword or your hands (1 or 10)
    • 16-20 = smash, do 16-20 points of damage and add the damage of the sword or your hands * 2 (2 or 10)
    • 21-25 = dodged, no damage
  • Print your hp and the enemies
  • Enemies strike:
    • Choose a random number between 1 and 25
    • 1-5 = miss, no damage
    • 6-10 = hit hard, take 6-10 points of damage
    • 11-15 = smashed, take 11-15 * 8 points of damage reduce by your armour (which can be worn)
    • 16-25 = dodged, no damage
  • Check if any HP are below 1 - if so act accordingly
  • Repeat
The only confusing thing is that it will print out hit points after your strike, but before the enemy's so it will look like your hp are decreasing when you hit; not when they hit.

Your hit points (HM and HP) start at 294; so it seems combat is unfair and you may just have to save (in game, not as an image) and retry it a lot to shift the random numbers around. If you want I can try and edit the code so you always win the fight.

Edit: the C16 code from a quick look is exactly the same as the C64 code - so it may be an unofficial port as they shared the same flavour of BASIC.
Mark
Posts: 90
Joined: Sun Feb 27, 2005 7:04 pm
Location: Germany

Re: Paul's 4k Adventure - coder's help needed (again)

#5 Post by Mark »

Thanks a lot for looking into the code :-).
dave wrote:Choose a random amount of HP for the enemy (between 1 and 350)
Hmm... there's something that struck me as odd. I did try that battle like 25 times, and as far as I saw, the battles went in exactly identical ways, enemy hit points included. The knight always started with 294 or so. the damage the knight did was always exactly the same, in the exact same order. For shits and giggles, I attacked a villager in a nearby room. Course of battle: exactly the same as well. Could it be that the random number generator can't be properly emulated by VICE..?
dave wrote:11-15 = smashed, take 11-15 * 8 points of damage reduce by your armour (which can be worn)
Well, that's one ultra hard blow... If the battle were truly random, and perchance the knight would NOT always land one of those, it could just be possible to win.

Maybe the armor would help... I didn't find it in the places accessible before the bottleneck guarded by the knight. Could it be that I missed it? If yes, then the game is slightly richer than I thought. I never suspected any hidden items, from what I saw in Paul's games so far. Could it be that there is an actual puzzle in the game...? Any pointer there maybe..?
User avatar
Gunness
Site Admin
Posts: 1939
Joined: Tue Dec 07, 2004 7:04 pm
Location: Copenhagen, Denmark
Contact:

Re: Paul's 4k Adventure - coder's help needed (again)

#6 Post by Gunness »

Mark wrote:Maybe the armor would help... I didn't find it in the places accessible before the bottleneck guarded by the knight. Could it be that I missed it? If yes, then the game is slightly richer than I thought. I never suspected any hidden items, from what I saw in Paul's games so far. Could it be that there is an actual puzzle in the game...? Any pointer there maybe..?
Well, I hacked the game to turn the odds a bit in my favour after dying countless times ;) The armour doesn't show up until the very end, so I tried placing that and the helmet at the beginning instead. Even then, wearing the armour, helmet and shield and wielding the sword, I still managed to lose to the knight :?

So with some additional code tweaks, I won that battle as well as the final one with the evil guy himself. I haven't found any use for the ring, but otherwise there doesn't seem to be a lot of stones left to turn, and the game is very brief. Oddly, given the very strict memory restrictions there are quite a lot of empty locations. I think those bytes could have been filled up with something more useful :)
Mark
Posts: 90
Joined: Sun Feb 27, 2005 7:04 pm
Location: Germany

Re: Paul's 4k Adventure - coder's help needed (again)

#7 Post by Mark »

Well, yes... the game is trash. It downright sucks. But you know me, Jacob. I seldom hesitate to play even the dumbest games around, hehe.

Also, this specific author seems to have had a reputation as a sort of "Ed Wood of adventure games". Maybe it's sentimental, but I'd really like to play a few of his games (if only to pay heed to the memory of a slightly weird personality within the scene). Would it be very time-wasting to fix this particular game and put it up here, so I can solve it by fair means? It would be best to fix battles in a way that forces the player to at least find out that he has to "wear" stuff, and "wield" the sword to win.

P.S. is "classics" the appropriate place for this thread anyway? They were made for the C64, but they're quite recent.
dave
Posts: 606
Joined: Tue Aug 21, 2007 10:20 pm

Re: Paul's 4k Adventure - coder's help needed (again)

#8 Post by dave »

The odds of you winning a fight seem a bit poor: you have a 3 in 5 chance of scoring a hit, for either 6-11, 12-25 or 18-30 points of damage, which with 294 enemy hits will take a while. The enemy, on the other hand has a 2 in 5 chance of scoring a hit for either 6-11 or 88 - 120 points of damage, which'll kill you very quickly.

When you mention trying several times, did you restore from a save game, or use a save state? The way most random numbers are generated depends on most 8-bit machines depend on a mathematical formula to get a number from a sequence, usually the seed is stored in memory and will be the same when the machine boots, or is restored from a state; leading to the same random numbers. (this messed up another Spectrum game, which I fixed by manipulating the random number seed.)

[edit] Gunness, if you used my C64 detokeniser to decode this, I realised I got the tokens for ">" and "<" the wrong way around, so the program may look a bit strange.

[edit 2] I found this page on how the random number generator works on the C64; it looks like it wouldn't have been so bad if he'd just used RND(0) instead of RND(1).
Mark
Posts: 90
Joined: Sun Feb 27, 2005 7:04 pm
Location: Germany

Re: Paul's 4k Adventure - coder's help needed (again)

#9 Post by Mark »

dave wrote:The odds of you winning a fight seem a bit poor: you have a 3 in 5 chance of scoring a hit, for either 6-11, 12-25 or 18-30 points of damage, which with 294 enemy hits will take a while. The enemy, on the other hand has a 2 in 5 chance of scoring a hit for either 6-11 or 88 - 120 points of damage, which'll kill you very quickly.
88-120... Yes, that looks quite bleak for our poor hero... Would it be possible to manipulate the numbers in a way that the battle without a sword is almost impossible to win, but with the sword pretty easy? So at least the wield sword "puzzle" has some sense, AND the author's attempt at bringing in a rpg element is still there.
dave wrote:When you mention trying several times, did you restore from a save game, or use a save state?
Sounds like you put your finger on it. I save via the snapshot image function. Got used to doing that, since too many games either have no save command at all, or can only save one slot, or are buggy with saving games in the first place...
dave
Posts: 606
Joined: Tue Aug 21, 2007 10:20 pm

Re: Paul's 4k Adventure - coder's help needed (again)

#10 Post by dave »

The C64 random seed is stored in memory locations $8b - $ 8f; so you can probably edit it directly from the VICE monitor - though this looks to be a standard BASIC float variable, which is a sod to convert to.

I'll have a look at hacking the source code - I'll probably reduce the enemy's hit points and make the damages more sensible (and have the sword make more differences).
terri
Posts: 1250
Joined: Wed Dec 15, 2004 5:08 am
Location: Canada

Re: Paul's 4k Adventure - coder's help needed (again)

#11 Post by terri »

Not that I understand one whit what you folks are referring to, I recall playing some games, where the outcome was the same if you "saved" just previous to starting that sequence, but with others it truly was random.

Does it matter "when" the randomness is set to start?
dave
Posts: 606
Joined: Tue Aug 21, 2007 10:20 pm

Re: Paul's 4k Adventure - coder's help needed (again)

#12 Post by dave »

terri wrote:Not that I understand one whit what you folks are referring to, I recall playing some games, where the outcome was the same if you "saved" just previous to starting that sequence, but with others it truly was random.

Does it matter "when" the randomness is set to start?
It really does depend on the program. Most random numbers on old 8-bit computers were just generated by an algorithm, which took a starting number (the seed) and produced a "random" number, which meant that every time you reset the machine, you'd get the same random numbers afterwards.

Most versions of BASIC had a way to reset the seed. Depending on the programmer, this may have been done in a sensible place, following something more random (e.g. reading from the system clock or from hardware) or not at all.

So, in conclusion, it really does depend on the program. This one is evil as the odds of winning combat are skewed vastly away from the player!
terri
Posts: 1250
Joined: Wed Dec 15, 2004 5:08 am
Location: Canada

Re: Paul's 4k Adventure - coder's help needed (again)

#13 Post by terri »

Thanks, Dave. I learned something today. Some things are not truly "random". If random depends on something, then is it truly random?

One of those philosphical, rhetorical questions, that, as they be wont to be, will be laid to rest, without further ado, by me. Such imponderables are best done in college, or when one is young, and thinks it is important...
User avatar
pippa
Posts: 57
Joined: Sun Jan 16, 2005 3:28 am
Location: London

Re: Paul's 4k Adventure - coder's help needed (again)

#14 Post by pippa »

terri wrote:Thanks, Dave. I learned something today. Some things are not truly "random". If random depends on something, then is it truly random?
No, it's pseudo-random. Yes, really. That really is the technical term. Just about every old BASIC manual used to have a note in the section on random numbers, explaining that they were only pseudo-random not really random. (Of course, back then there was no difference in practice since you couldn't save and reload a snapshot of the whole machine's state. It's only modern emulators that have exposed the weakness in the system.)
[b]~~[i] Pippa [/i]~~[/b]
User avatar
Gunness
Site Admin
Posts: 1939
Joined: Tue Dec 07, 2004 7:04 pm
Location: Copenhagen, Denmark
Contact:

Re: Paul's 4k Adventure - coder's help needed (again)

#15 Post by Gunness »

@Dave: No, I didn't use the detokenizer, I just looked at the listing from within the game. I guess the other method would be easier :) (the LIST command in C64 BASIC is pretty sucky. As is the rest of the BASIC, actually!)
Mark wrote:Also, this specific author seems to have had a reputation as a sort of "Ed Wood of adventure games". Maybe it's sentimental, but I'd really like to play a few of his games (if only to pay heed to the memory of a slightly weird personality within the scene). Would it be very time-wasting to fix this particular game and put it up here, so I can solve it by fair means? It would be best to fix battles in a way that forces the player to at least find out that he has to "wear" stuff, and "wield" the sword to win.
Hehe, Paul Panks had quite a reputation in the IF community :) But I agree completely, and I've enjoyed (in a weird, masochistic way) playing this particular game. Somehow I don't think Paul ever anticipated that anyone would try to reverse engineer his program so enthusiastically ;)
Unless Dave does it, I can also "fix" the program a bit. You can't say that the player has to wear the armour of wield the sword to win, as it all comes down to semi-random numbers, but you can improve the odds a lot.
P.S. is "classics" the appropriate place for this thread anyway? They were made for the C64, but they're quite recent.
Could "Paul's 4K Adventure" ever have been considered a classic, no matter what decade it was written in?? :D The "classics" refers to the platforms, here meaning the various 8-bit and 16-bit computers as opposed to Inform and the other modern interpreters.
Post Reply