Randomly sorting arrays
ramis2k
Member, PRO Posts: 17
Hey fellas,
This is my problem: imagine some kind of Tetris, where you have 5 different kind of blocks, and you only get 30 blocks per level.
In my case, I don´t want to just give out new blocks randomly, but I want to set the percentage of blocks you get for each level.
What I would do in any language is to populate an array with the number of each block (1 to 5) the N times I want that block according to the percentage I set up before.
It would look something like this:
myblocks[30] = [1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5,5,5,5]
Once I've got my array full with the blocks percentages, I would sort it randomly so I could get a random order of a preset percentage for each block.
Does it make sense?
What could I do to accomplish it with GameSalad as we don't have arrays?
Thanks guys!
This is my problem: imagine some kind of Tetris, where you have 5 different kind of blocks, and you only get 30 blocks per level.
In my case, I don´t want to just give out new blocks randomly, but I want to set the percentage of blocks you get for each level.
What I would do in any language is to populate an array with the number of each block (1 to 5) the N times I want that block according to the percentage I set up before.
It would look something like this:
myblocks[30] = [1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5,5,5,5]
Once I've got my array full with the blocks percentages, I would sort it randomly so I could get a random order of a preset percentage for each block.
Does it make sense?
What could I do to accomplish it with GameSalad as we don't have arrays?
Thanks guys!
Comments
not sure, even GS have game center, maybe it is for pro only!
You may want to look at corona for scripting.
Any ideas?
a=random(1,100)
if a<50 Block = 1 (50%)
if a>=50 and a<75 Block = 2 (25%)
..
if a=100 Block =5 (1%)
Random Without Repeats (experiment)
However, instead of having the blocks self-destruct when their number comes up, I would keep track of how many times a number appears. Only after it has appeared the number of times that you want would it self destruct. So, for instance (in your example), you would want the counter to record seven 1's before you eliminate this block.
Hope this makes sense. Have a good weekend!
just make some attribute,
game.blockA=5 (have total 5 block A)
game.blockB=3 (have total 3 block
..
..
then use
x=random(1,5)
if x=1 and game.blockA > 0
game.blockA=game.blockA - 1 ###you get the block
Block=A
otherwise
x=random(2,5) #### there is no block A
if x=2 ....
..
..
and we don't have dynamic arrays!
Problem is...the integer can only store 8 digits and it can't lead with a zero.
its a funky work around...but it works and I've used it to store level lock values (5 at a time instead of 1 at a time).
Store:
Change self.StoredColor to:
`(min(990000,self.Color.Red*1000000))+`
`(min(9900,self.Color.Green*10000))+`
`(min(99,self.Color.Blue*100))`
Load:
Change self.Color.Red to: `floor(self.StoredColor/10000)/100`
Change self.Color.Green to: `floor((self.StoredColor%10000)/100)/100`
Change self.Color.Blue to: `(self.StoredColor%100)/100`
The only sacrifice I can think of is that I can only store .00-.99 instead of the normal .00-1.00...
Perhaps its 7...I couldn't remember. At some point it begins to use exponential numbers.
@barkbark...
game.rgbStoredColor = 9002345
this value breaks down as the following:
the first 9 is merely a placeholder so you can have leading zeros for the actual values...it wont be used.
The next 2 numbers are the red value
The next 2 are the green value
The last 2 are the blue value
So to assign the red value:
self.Color.Red = (((floor( game.rgb /100000))%10*10)+((floor( game.rgb /10000))%10)))/100
[ this assigns digits 2 and 3 to a decimal value as the red value ... in this case 0.00 ]
self.Color.Green = (((floor( game.rgb /1000))%10*10)+((floor( game.rgb /100))%10)))/100
[ this assigns digits 4 and 5 to a decimal value as the green value... in this case 0.23 ]
self.Color.Blue = (((floor( game.rgb /10))%10*10)+( game.rgb %10))/100
[ this assigns digits 6 and 7 to a decimal value as the blue value ... in this case 0.45 ]
I think I have all the parenthesis in place...but the formulas appear to work.