QL Ruins ACT - 1st problem random number within a range of.
- vanpeebles
- Commissario Pebbli
- Posts: 2821
- Joined: Sat Nov 20, 2010 7:13 pm
- Location: North East UK
- vanpeebles
- Commissario Pebbli
- Posts: 2821
- Joined: Sat Nov 20, 2010 7:13 pm
- Location: North East UK
Re: QL Ruins ACT - 1st problem random number within a range of.
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.
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.
- vanpeebles
- Commissario Pebbli
- Posts: 2821
- Joined: Sat Nov 20, 2010 7:13 pm
- Location: North East UK
Re: QL Ruins ACT - 1st problem random number within a range of.
Hmm, I put in a var print command for each turn of the loop and I got:
311114444111111
311114444111111
- vanpeebles
- Commissario Pebbli
- Posts: 2821
- Joined: Sat Nov 20, 2010 7:13 pm
- Location: North East UK
Re: QL Ruins ACT - 1st problem random number within a range of.
2nd run was 917179999111, which is not ten runs through.
- vanpeebles
- Commissario Pebbli
- Posts: 2821
- Joined: Sat Nov 20, 2010 7:13 pm
- Location: North East UK
Re: QL Ruins ACT - 1st problem random number within a range of.
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?
Would the randoms be better on a normal QL?
- vanpeebles
- Commissario Pebbli
- Posts: 2821
- Joined: Sat Nov 20, 2010 7:13 pm
- Location: North East UK
Re: QL Ruins ACT - 1st problem random number within a range of.
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.
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?vanpeebles wrote:qemulator crashed!
About the randomness, perhaps RANDOM's implementation is based on a timer?
-
- Super Gold Card
- Posts: 716
- Joined: Mon Nov 24, 2014 2:03 pm
Re: QL Ruins ACT - 1st problem random number within a range of.
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.
<< (65535 / 17 for range of 17 locations) >> Is this division done using DIV and/or MOD ? If so you may well have problems...
Steve.
- vanpeebles
- Commissario Pebbli
- Posts: 2821
- Joined: Sat Nov 20, 2010 7:13 pm
- Location: North East UK
Re: QL Ruins ACT - 1st problem random number within a range of.
It uses the ACT instruction dividestevepoole 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.
-
- Super Gold Card
- Posts: 716
- Joined: Mon Nov 24, 2014 2:03 pm
Re: QL Ruins ACT - 1st problem random number within a range of.
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.
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.