Page 3 of 3

Re: My next game on ACT - 1st problem random number within a range of.

Posted: Tue Jan 21, 2020 1:02 pm
by vanpeebles
Image

Location 5 finished

Re: QL Ruins ACT - 1st problem random number within a range of.

Posted: Tue Jan 12, 2021 8:48 pm
by vanpeebles
I've started to work on my random number code. Basically it will do three different things. Give each treasure a random description name, then place it in a random location. And also place all the monsters at random too. So far, my initial attempt kind of works, (my first go had them moving about every time you moved!) Except it only seems to move them in blocks of 4 or 5 items to a different room. Once I get this part working, I'll do the names and monsters next using the same code.

900 NAME random_object_locs
910 LOAD_VAR 0,0:LOAD_VAR 1,2:BITTST_LOC 0,1,0:IF_NE 0:RETurn:Remark this part only checks if the initial startup game message has displayed as it only needs to run once per game.
920 LOAD_VAR 2,10:LOAD_VAR 3,10:REMark 10 item loop, 10 into var 2. Parameter 10 for each object holds the location value, 10 into var3
930 IF_EQ 2:RETurn:REMark check if the loop has reached 0 if so, return.
940 RANDOM 1:DIVIDE 1,3855:ADD 1,8:UPDATE_OBJ 2,3,1:SUBTRACT 2,1:GO TO 930

The random number is from -32768 to 32767. Divided by 3855 (65535 / 17 for range of 17 locations) Add 8 (middle of range) (As per Tobias' examples) By default I think ACT always rounds up, no matter the value.

Re: QL Ruins ACT - 1st problem random number within a range of.

Posted: Tue Jan 12, 2021 9:09 pm
by vanpeebles
Hmm, I put in a var print command for each turn of the loop and I got:

311114444111111 :lol:

Re: QL Ruins ACT - 1st problem random number within a range of.

Posted: Tue Jan 12, 2021 9:14 pm
by vanpeebles
2nd run was 917179999111, which is not ten runs through.

Re: QL Ruins ACT - 1st problem random number within a range of.

Posted: Tue Jan 12, 2021 10:02 pm
by vanpeebles
Oops, needed a space to my makeshift debugger, My last run had 10 values, 9 were 14 and 1 was 8. Ran it again, and they scattered all over. I kept running it and started to get 10 sets of 7, then ten sets of 3, then qemulator crashed!

Would the randoms be better on a normal QL?

Re: QL Ruins ACT - 1st problem random number within a range of.

Posted: Tue Jan 12, 2021 10:08 pm
by vanpeebles
I wonder if it's some kind of bug with qemulator? With gold card mode on, I can constantly get 10 values, that are all the same number.

Re: QL Ruins ACT - 1st problem random number within a range of.

Posted: Wed Jan 13, 2021 12:31 am
by M68008
vanpeebles wrote:qemulator crashed!
The emulated QL or the Q-emuLator application? In the latter case, maybe you can PM me more details, especially if it can be reproduced?

About the randomness, perhaps RANDOM's implementation is based on a timer?

Re: QL Ruins ACT - 1st problem random number within a range of.

Posted: Wed Jan 13, 2021 9:15 am
by stevepoole
Hi Van,

<< (65535 / 17 for range of 17 locations) >> Is this division done using DIV and/or MOD ? If so you may well have problems...

Steve.

Re: QL Ruins ACT - 1st problem random number within a range of.

Posted: Wed Jan 13, 2021 9:31 am
by vanpeebles
stevepoole wrote:Hi Van,

<< (65535 / 17 for range of 17 locations) >> Is this division done using DIV and/or MOD ? If so you may well have problems...

Steve.
It uses the ACT instruction divide :)

Re: QL Ruins ACT - 1st problem random number within a range of.

Posted: Wed Jan 13, 2021 10:16 am
by stevepoole
Hi Van,

Is this demo of any use to you ? (All you need is line 120).

100 DIM t(17):
110 FOR i=1 to 999:
120 n=INT(RND*17)+1: IF n=18: GOTO 120
130 t(n)=t(n+1): AT t(n): PRINT '.'
140 END FOR i

Steve.