Using Lists of Lists for Random Card Shuffles

The easiest way is to use list (not list of list);

  1. generate a list containing number 1,2,3, ... 52, in which, 1-13 for spades, 14-26 for hearts.....
  2. shuffle the list
  3. seperate the list/cards to 2 player, for example, item 1 to 26 for player1, 27 to 52 for player2
  4. use the Quotient of (num-1) / 13 +1 to check the suit, 1 for spade, 2 for hearts....
    and the reminder of (num-1)/13 +1 to get the index/value. 1 for ace, 11 for jack, 12 for queen....
3 Likes

That's what I eventually did. @ABG and @TIMAI2 have been helping me to get a better version, and what you said kinda sound like my souped-up one I'm using. It is so cool that for something as simple (yet complex when you try it) as sorting and dealing a deck has so many different ways and solutions to do it. Thanks @Mary_L220 for the idea, and @KevinWang for yet another way to do it.

Here's my current version:

https://community.appinventor.mit.edu/uploads/short-url/pgwpCwP9zjUIRNdOtSntmRmUCZn.aia

Note that the extra procedures are for future games, like solitaire and war. Right now I'm working on the cards in bobsprite

Can someone help me on how to unshuffle the cards ? I am creating sound game app with matching type. But the photos are shuffling and the sound of the animals is not shuffling. Can somebody help ? Please .

Can you share your relevant blocks and explain in detail the problem you have?

EDIT: Anyway, I suppose you are doing something like this:

maybe you can find the solution (or a better way) there.

(Canned Reply: ABG - Download those blocks and post them here)

Please download and post each of those event block(s)/procedures here ...
P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See Download Block Images for a demo.

do you means that, you have 2 lists, one for photos one for sounds, you shuffled both lists, but now they are not in same order?

You can make them in one list, like
[ ["name1", "sound1"], ["name2", "sound2"],["name3", "sound3"],["name4", "sound4"] ]

now you can shuffle your list, the photo name and sound file are in a list, name at index 1, and sound at index 2.

1 Like

Sir here is my project sir . Can you check sir ?

The list of lists should be hidden behind a value procedure mapping pictures into sounds.

Only the pictures would need shuffling in this approach.

Can you send ang image of sample code sir ?


1 Like

Can i send to you my apk or aia sir. For you to see my codes ?

Thank you sir. You gave me some ideas. Appreciated. But may game sir is memory game app. Is it ok ?

You are allowed to post the exported .aia file here.

I can't read fuzzy block images and will not run .apk files.

1 Like

Hi sir, I don't know how you loop sir because there is no symbol🥺

Here are some resources to help you learn to use the AI2 tools A very good way to learn App Inventor is to read the free Inventor’s Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps … the links are at the bottom of the Web page. The book ‘teaches’ users how to program with AI2 blocks.

There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps

How to do a lot of basic things with App Inventor are described here: How do you...? .

There are several of loop blocks in the control blocks section.

While do

For each number

For each item in list

Clock Timer

Hi sir, yes sir but i can post my aia here through google drive sir coz my project is higher than 8mb. :cry:

Here you can download my project sir and check if you dont mind and you have extra time sir ? My only problem sir is how to add the sound and if the images will shuffle the sound will also shuffle . But I dont know how sir. Please help me sir :cry:

Reduce the size of every image using the website tinypng

You didn't set the download to share.

Yes sir. I will reduce sir . Please wait . Thank you