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

Anything QL Software or Programming Related.
User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

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

Post by vanpeebles »

Image

Location 5 finished


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

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

Post 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.


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

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

Post by vanpeebles »

Hmm, I put in a var print command for each turn of the loop and I got:

311114444111111 :lol:


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

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

Post by vanpeebles »

2nd run was 917179999111, which is not ten runs through.


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

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

Post 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?


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

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

Post 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.


User avatar
M68008
Trump Card
Posts: 223
Joined: Sat Jan 29, 2011 1:55 am
Contact:

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

Post 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?


stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

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

Post 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.


User avatar
vanpeebles
Commissario Pebbli
Posts: 2816
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

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

Post 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 :)


stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

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

Post 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.


Post Reply