# How do I Split Deck into two?

Get help using Construct 2

### » Tue Jul 19, 2016 3:21 pm

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,
B
5
S
1
Posts: 65
Reputation: 507

### » Tue Jul 19, 2016 3:31 pm

@ErudioLtd
Have you checked out kittiewan's Memory Match tut?
She has a simple effective way to shuffle cards:

https://www.scirra.com/tutorials/280/cr ... match-game
B
17
S
9
G
5
Posts: 74
Reputation: 4,145

### » Wed Jul 20, 2016 10:17 am

@SimoneT

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.
B
5
S
1
Posts: 65
Reputation: 507

### » Wed Jul 20, 2016 12:50 pm

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.
B
29
S
10
G
10
Posts: 97
Reputation: 6,614

### » Wed Jul 20, 2016 1:48 pm

@ErudioLtd

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.
B
17
S
9
G
5
Posts: 74
Reputation: 4,145

Great,
Thanks
B
5
S
1
Posts: 65
Reputation: 507

### » Wed Jul 20, 2016 3:11 pm

Alternatively you do not need to shuffle the deck. just randomize the card drawn.
B
29
S
10
G
10
Posts: 97
Reputation: 6,614