mardi 21 juin 2016

Randomize an array, and putting them back in the order the items were click

I'm trying to develop a card cycle simulator for a card game. I have tried looking into the best practice of doing so, and randomizing an array will always output random cards. I need a function that will randomize the fist set of cards, and renter them in the order they were selected.

Example:

I will use numbers to represent the cards

Say there were 5 cards out of 8 you can choose:

The order was 1, 5, 3, 8, 6, 2, 7, 4

So you first hand would be 1, 5, 3, 8, 6

You select 5

I want the 5 to be added to the end of the list

So your next hand would be 1, 3, 8, 6, 2

And the array would have 7, 4, 2 remaining

Say you draw card 1

Your hand would be 3, 8, 6, 2, 7

And the array would have 4, 2, 1 in the pool

Sorry my example may be very confusing, but I'm sure someone on here could point me in the right direction.

Another way of putting it is I initially want a randomized array that outputs x amount of cards, the remaining x cards will be in their precise order, and the selected cards will be placed at the end of the array to be selected in that order.

Also I'm comfortable with using PHP and Jquery for this, what would this function be called? I'm having a lot of trouble doing this.

Thanks for the help!




Aucun commentaire:

Enregistrer un commentaire