Vous n'êtes pas identifié(e). Pour pouvoir écrire ou répondre à un message, vous devez vous connecter ou vous créer un compte sur JAWA.
Pages : 1
Does anyone know a way / script to randomize an array?
I want to place cards in a puzzle game in a random order.
I have the numbers of the cards in an array.
Is there an easy way to randomize the array?
Hors ligne
Sorry I have no answer for that right now, shuffling an array is a complex thing to do !
A solution could be to create several preset distributions in a separate 2D arrays and assign one of them to your current distribution based on a random number :
for instance :
possible_shuffles =
1|2|3~
3|1|2~
3|2|1~
2|1|3~
...
(at variable initialization)
in a "draw cards" script :
variable:temp:[_rand:0:5] (5 = if there is 6 different shufflings presets)
variable:my_shuffling:{{possible_shuffling$*$TEMP}}
=> assign to my_shuffling array the randomized line number TEMP of the possible preset shuffles
(tell me if it works !)
Great idea, it works.
I implemented it as follows, to shuffle four cards.
variable:DRAW:[_rand:0:5]
updateobject:25827:x:[186*{{SHUFFLE$0$DRAW}}]:0
updateobject:25811:x:[186*{{SHUFFLE$1$DRAW}}]:0
updateobject:25826:x:[186*{{SHUFFLE$2$DRAW}}]:0
updateobject:25825:x:[186*{{SHUFFLE$3$DRAW}}]:0
Hors ligne
cool
Pages : 1