Any way to make this algorithm more efficient? Using random blocks to sort 56 cards

Hello all,
The question says it all: Any way to make this algorithm more efficient? Using random blocks to sort 56 cards into 2 decks of equal length.

Here are the blocks used:


https://community-appinventor-mit-edu.ezproxy.canberra.edu.au/uploads/short-url/nxp4F0MJsqyU29BVDZyB4TPfOVP.aia

Sort deck once, split into 2.

1 Like

Start with two empty hands, and alternate between them as destinations for random selection and removal from given deck ...

shuffle_and_deal.aia (4.3 KB)

1 Like

@ABG, Dang, that's way more complex than mine, but it doesn't have the possibility of being infinitely called over and over again if the selection is already in the list. I forgot about the remove item from list block. I should use that to remove the selected card from the list every time it loops. That removes the possibility of duplicates, and being called over and over again. I will use this for further research.

@TIMAI2 Here is what have so far:

I'm figuring out how to add different amounts of players. But it has to be an amount of players that divides out evenly. To add a player amount that divides out odd, i'd need 2 new procedures that divides it out, checks to see if it has decimals, set the decks to that number of cards after zeroing it, and then adds the left over cards to the extra deck.
RN, im working on the dealing part.

@TIMAI2 @ABG How does this look now?

Blocks

It is a little chunky. The next version I make I plan for it to have a list of the decks (list of lists), so it isn't so chunky.

Any feedback @ABG and @TIMAI2?

You didn't like my alternative then ?

1 Like

I loved it, @TIMAI2! But I want to create my own. The goal is to make it universal and make a card game app out of it. So in effect, it would be 1 big procedure with parameters based on the card game chosen, # of players, etc. Also, to make it universal for everyone in any app could use it.

Your blocks do not exactly look "universal"

At least put a 0 (zero) in front of each of your 1-9 numbers e.g. Spades01, even though I prefer @ABG's suggested format of 01S, 03C, 13H...

1 Like

Here's a 4 player version, with more generality for additional players...

shuffle_and_deal.aia (4.6 KB)

As before, it takes fewer blocks to generate a deck than to enumerate one in a global init.

1 Like