KevKelley Posted May 26, 2020 Share Posted May 26, 2020 I understand the concept of data tables and have had limited use of then but I was wondering if there is a way to randomly seed a data table. Say I want to randomly generate a series of 12 values to draw 12 different sprites, and then recall them in that order every time needed, or until I reset it, would I simply randomly generate the first number in the data table and then add onto the subsequent values? Quote Link to comment Share on other sites More sharing options...
bogax Posted May 26, 2020 Share Posted May 26, 2020 rand is just a counter that counts in a funny sequence if you start from the same spot it will count through the same sequence Quote Link to comment Share on other sites More sharing options...
+Karl G Posted May 26, 2020 Share Posted May 26, 2020 Data tables normally reside in ROM, so you can't set their values to random values, nor can you change them at runtime. Technically you could have a data table in RAM, but you would have to give up 12 variables to do so, which is probably not what you want. Probably the best way to accomplish what you are wanting is to have a random function of your own that is separate from the built-in bB one, which would require one variable to hold the current seed value. If you set it to a certain seed number, then run the custom rand function 12 times, you will get the same values in the same order every time. If you need them again, then set the seed variable back to the starting value again. If you need a separate set of 12, pick a different initial seed value, etc. If you want to go this route, I could whip up a sample random function for demonstration purposes. Quote Link to comment Share on other sites More sharing options...
KevKelley Posted May 26, 2020 Author Share Posted May 26, 2020 I had just started playing around with an idea. The playfield consisted of 12 boxes. I wanted to flash a sprite in each of the 12 boxes and then disappear. Then one of the 12 sprites would randomly appear and you would have to place that sprite in the correct box. Essentially a game of memory... The only thing I was worried about is that a pattern would develop and it would be easy to guess. 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted May 26, 2020 Share Posted May 26, 2020 (edited) so you want a shuffle? that's a somewhat different problem (Wikipedia) Edited May 26, 2020 by bogax Quote Link to comment Share on other sites More sharing options...
KevKelley Posted May 26, 2020 Author Share Posted May 26, 2020 8 minutes ago, bogax said: so you want a shuffle? that's a somewhat different problem (Wikipedia) Yeah. I suppose that would be it. Once every box would be matched it would then reset, flash the new order of sprites, and then start over. Quote Link to comment Share on other sites More sharing options...
KevKelley Posted May 26, 2020 Author Share Posted May 26, 2020 So maybe a different direction would be assigning each sprite a value. Then a random number outside of the mainloop (r=Rand) and assign each box a value (y=r+1, y=r+2, etc), and then have y point to a data table for what the corresponding sprite would be. Once all boxes are filled then clear the boxes and go back to the random number and start over? Hopefully with enough sprites, positions, and randomizations, it could make a sequence difficult to remember? I'm just typing out loud playing with this idea to see if it works. Or if this is a rabbit hole I don't really want to go down or not. Quote Link to comment Share on other sites More sharing options...
bogax Posted June 4, 2020 Share Posted June 4, 2020 On 5/25/2020 at 7:24 PM, KevKelley said: Say I want to randomly generate a series of 12 values to draw 12 different sprites, and then recall them in that order every time needed, or until I reset it, would I simply randomly generate the first number in the data table and then add onto the subsequent values? How would you get 12 sprites? Quote Link to comment Share on other sites More sharing options...
KevKelley Posted June 4, 2020 Author Share Posted June 4, 2020 I didn't plan on showing them at the same time. Sorry. I should have clarified. Quote Link to comment Share on other sites More sharing options...
bogax Posted June 4, 2020 Share Posted June 4, 2020 (edited) I'm thinking something like this this rotates through three for each bit of rand you could probably find better choices for the three I tried swapping two but it didn't look very random (and neither does this really but it looks better than swapping) I didn't try to analyze it, I just picked some random looking stuff that is a notoriously bad idea the details would depend on exactly what you're doing there's like 500 million permutations of twelve, rand is only 8 bits and rand16 has a cycle length of 65535 dim rand16 = z rnd = rand for i = 0 to 14 step 2 p = (rnd & 1) | i on p goto rr_0 rr_1 rr_2 rr_3 rr_4 rr_5 rr_6 rr_7 rr_8 rr_9 rr10 rr11 rr12 rr13 rr14 rr15 nxt rnd = rnd/2 next rr_0 temp1 = sp0 : sp0 = sp3 : sp3 = sp10 : sp10 = temp1 : goto nxt rr_1 temp1 = sp0 : sp0 = sp6 : sp6 = sp11 : sp11 = temp1 : goto nxt rr_2 temp1 = sp1 : sp1 = sp9 : sp9 = sp10 : sp10 = temp1 : goto nxt rr_3 temp1 = sp1 : sp1 = sp4 : sp4 = sp11 : sp11 = temp1 : goto nxt rr_4 temp1 = sp2 : sp2 = sp7 : sp7 = sp10 : sp10 = temp1 : goto nxt rr_5 temp1 = sp2 : sp2 = sp10 : sp10 = sp11 : sp11 = temp1 : goto nxt rr_6 temp1 = sp3 : sp3 = sp5 : sp5 = sp10 : sp10 = temp1 : goto nxt rr_7 temp1 = sp3 : sp3 = sp6 : sp6 = sp11 : sp11 = temp1 : goto nxt rr_8 temp1 = sp4 : sp4 = sp10 : sp10 = sp10 : sp10 = temp1 : goto nxt rr_9 temp1 = sp4 : sp4 = sp6 : sp6 = sp11 : sp11 = temp1 : goto nxt rr10 temp1 = sp5 : sp5 = sp8 : sp8 = sp10 : sp10 = temp1 : goto nxt rr11 temp1 = sp5 : sp5 = sp9 : sp9 = sp11 : sp11 = temp1 : goto nxt rr12 temp1 = sp6 : sp6 = sp8 : sp8 = sp10 : sp10 = temp1 : goto nxt rr13 temp1 = sp6 : sp6 = sp9 : sp9 = sp11 : sp11 = temp1 : goto nxt rr14 temp1 = sp7 : sp7 = sp8 : sp8 = sp10 : sp10 = temp1 : goto nxt rr15 temp1 = sp7 : sp7 = sp10 : sp10 = sp11 : sp11 = temp1 : goto nxt Edited June 4, 2020 by bogax typos Quote Link to comment Share on other sites More sharing options...
KevKelley Posted June 4, 2020 Author Share Posted June 4, 2020 I never considered that. I have yet to use for and step commands but this could be interesting. Now I am a little confused briefly looking at this. Would the rr## be the assignment for the sprite location and the sp## the sprite? Quote Link to comment Share on other sites More sharing options...
bogax Posted June 4, 2020 Share Posted June 4, 2020 yes the rr##'s are the individual rotation routines they just rotate three sprites (you could think of a swap as a rotation of two sprites) and the sp##'s are the sprites they're sort of place holders, exactly what they'd end up being would depend on your code they could be plain bB variables, or you could pack them as nibbles. or you could make some of them nibbles and use the sprite x,y for some (assuming the x,y positions would be (different, unique) constants. it would be sort of inside out, the positions would get shuffled among the sprites instead of the sprites shuffled amongst the positions) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.