xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
178
Reaction score
38
I'm testing the fisher yates shuffle on this online editor
JavaScript:
var t0 = [0,0,0,0,0,0,0,0,0,0,0,0,0];
var t1 = [1,1,1,1,1,1,1,1,1,1,1,1,1];
var t2 = [2,2,2,2,2,2,2,2,2,2,2,2,2];
var t3 = [3,3,3,3,3,3,3,3,3,3,3,3,3];
var t4 = t0.concat(t1,t2,t3);

console.log(t4);

var pp = t4; // array cards
for (var i = pp.length - 1; i > 0; i--) {
    const swapIndex = Math.floor(Math.random() * (i + 1))
    const currentCard = pp[i]
    const cardToSwap = pp[swapIndex]
    pp[i] = cardToSwap
    pp[swapIndex] = currentCard
  }
console.log(pp);
console.log(pp[0]);console.log(pp[4]);console.log(pp[8]);console.log(pp[12]);

this is the output.. as you can see the array is shuffled correctly..
1620271308288.png
however in RMMV..
1620271364958.png
this is the output.. i dont know what is wrong
1620271453676.png
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,500
Reaction score
726
First Language
indonesian
I think maybe the last show text should be \v[5] instead...?
since you store pp to variable 5...

i don't see any other problem though...
 

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
178
Reaction score
38
I think maybe the last show text should be \v[5] instead...?
since you store pp to variable 5...

i don't see any other problem though...
it's still the same i tried \v[4] \v[5], on that line, and they output the same.. its like the shuffle is only done once..

EDIT:
I swapped with another version of fisher yates.. this once works
JavaScript:
var i = arr.length, j, temp;
while(--i > 0){
    j = Math.floor(Math.random()*(i+1));
    temp = arr[j];
    arr[j] = arr[i];
    arr[i] = temp;
}
 
Last edited:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,368
Reaction score
1,403
First Language
Spanish
Primarily Uses
RMVXA
generically:
Code:
i = t4[random(t4.length-1)]
pp.unshift(t4.pop(i))

get total of items.
randomize based on total.
remove index number from total -> total decreases by 1.
repeat.

you don't need to reorder pp, you need to create pp based on the items of t4.
this
JavaScript:
var i = arr.length, j, temp;
while(--i > 0){
    j = Math.floor(Math.random()*(i+1));
    temp = arr[j];
    arr[j] = arr[i];
    arr[i] = temp;
}

is the bubble method for sorting.
 

xabileug

Veteran
Veteran
Joined
Jul 1, 2014
Messages
178
Reaction score
38
generically:
Code:
i = t4[random(t4.length-1)]
pp.unshift(t4.pop(i))
is this shorter method? this is for deck of cards. im making a game dealing cards, players get 4 cards on their hand.
 

Latest Threads

Latest Profile Posts

image_2021-06-13_213812.png

Todays Lesson: Tiles are a pain to make xD
The game is not even 2% complete, but i just wanted to release something for funsies. :)
It's on my google drive.
It would be awesome if i could get a couple ideas and the like!
So yesterday Dad took me to Volcano Bay, and it was almost ruined by a thunderstorm... then it passed by and the lightning warning got lifted, leading to an awesome time sliding and swimming. Hopefully we get to go to the arcade tonight. The one we're planning on has a restaurant built in with AWESOME food. Not to mention how big the arcade itself is!
image_2021-06-13_150033.png

Maybe I'll actually try making a retro pack. Already have the shark fin made so why not xD
Hey everyone, for everybody following along with my RPG Maker MZ streams: There will unfortunately not be a stream tonight. There is a big exciting event that will go live next week that has been taking all my time, so look forward to that!

Forum statistics

Threads
112,197
Messages
1,066,522
Members
145,805
Latest member
Amber22
Top