0 Favourites

# How do I Split Deck into two?

• 7 posts
• Hi,

I want to make a card game and am wondering what is the best way to distribute cards into two piles whilst still both randomizing the cards position in the deck and Making sure each card only appears once (Deleting it from the possible outcomes once it is pulled)

Any Help Appreciated,

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Have you checked out kittiewan's Memory Match tut?

She has a simple effective way to shuffle cards:

• Yes i have seen her tutorials but they talk about laying all cards out in a tableau where as i want the cards to shuffle and then be equally split into two piles.

• What structure are you using to hold the deck? An array?

If so, you can randomize (shuffle) your array order, then pull the top half of the cards into one structure, and the rest to another structure.

• Good, makotto is right. You need to create your cards, split them and then shuffle you array:

(the +1 is your card back)

Event 1: On start of Layout=> Set DeckArray width to NumberOfCardsInYourDeck +1

(I am assuming that frame0 is your card back and 1 to whatever are your card faces)

Event 2: For 0 to NumberOfCardsInYourDeck ("deck") => Create Card at X,Y (it doesn't matter yet), set Card.ArrayNumber to loopindex("deck"), DeckArray set value at loopindex("deck")

Event 3: Compare 0 < Card.ArrayNumber >= NumberOfCardsInYourDeck/2 => set position to X, Y (pile 1)

Event 4: Compare NumberOfCardsInYourDeck/2 < Card.ArrayNumber >= NumberOfCardsInYourDeck => set position to X, Y (pile 2)

(Now you shuffle like in the tutorial)

Event 5: For 1 to NumberOfShuffles => set Slot1 to ceil(random(0, NumberOfCardsInYourDeck)), set Slot2 to ceil(random(0, NumberOfCardsInYourDeck)), set Card1 to DeckArray.At(Slot1), set Card2 to DeckArray.At(Slot2), DeckArray set value at Slot2 to Card1, DeckArray set value at Slot1 to Card2

For each Card => set Card.FaceFrameNumber to DeckArray.At(Card.ArrayNumber)

When you flip cards: set animation frame to Card.FaceFrameNumber

Cards created, split and shuffled!

Hope this helps.

• Great,

Thanks

• Alternatively you do not need to shuffle the deck. just randomize the card drawn.

• 7 posts