Matt Skoll

unread,
Apr 3, 2015, 7:40:09 PM4/3/15
to mitappinv...@googlegroups.com
I'm trying to make a "card shuffling" app and I'm not sure if AI2 can handle it...better yet, if I can handle it.
I want to be able to have a database of 52 playing cards (hell ill start off with 5 or 10 if thats easier). A button that when pressed randomly shows one of the cards from the database. Every time the "show new card" button is hit, it shows a new card in random order. The catch it seems, is that the "pool" of cards doesn't shrink. Meaning, every time "show new card" is pressed I don't want it pulling from the full 52 card deck. I would like to have it pull from the REMAINING cards if possible. I would have another button like "shuffle" that when hit would start at 52 cards again.
I have no idea if this makes any sense, but I would really hope that someone could point me in the right direction if this is even possible with the AI2 in it's current form.

A desperate dad trying to impress his kids, thanks you all very much for your help!!

Matt

Enis

unread,
Apr 3, 2015, 8:57:28 PM4/3/15
to mitappinv...@googlegroups.com
Hi Matt...

Certainly possible.  You have a deck of 52 cards... make those a list.  Then, each time you draw a card, you remove it from the list.

You choose the card using the random block, with which you choose an index.  THe index is the number of the card in the list.  Show it, then remove it from the list and randomize again.

Matt Skoll

unread,
Apr 4, 2015, 12:30:11 AM4/4/15
to mitappinv...@googlegroups.com
Thanks again for the help Enis, clearly this is out of my depth. Thought this would be a bit easier.

Matt

Enis

unread,
Apr 4, 2015, 12:41:27 AM4/4/15
to mitappinv...@googlegroups.com
Matt...

Don't give up that easily!  It's really NOT that difficult!

Do you know how to make a list?  If so, then make a 52 item list... The easiest way to do it is with a CSV text file.  Something like this:

Ah,2h,3h,4h,5h,6h,7h,8h,9h,10h,Jh,Qh,Kh,As,2s,3s,4s,5s,6s,7s,8s,9s,10s,Js,Qs,Ks,Ad,2d,3d,4d,5d,6d,7d,8d,9d,10d,Jd,Qd,Kd,Ac,2c,3c,4c,5c,6c,7c,8c,9c,10cJc,Qc,Kc

That's the deck of cards in a CSV line.  Save that to a text file.  Add it to the media section of the Designer.

Then, in your app, create a Global Variable called Cards, and set to to create empty list.

Then you'll read the file in using the file component.  Once it's in, then assign the list to the items in that CSV file.

Now, you've got your list to play with.  Copy that list to another temporary list.  Use that temporary list to draw cards, then delete the entry drawn.  You can go all the way down to 1 card.  When you've gotten there, set that temporary list back to the global Cards list, and you're ready to start again!!!


Matt Skoll

unread,
Apr 4, 2015, 2:45:41 PM4/4/15
to mitappinv...@googlegroups.com
Thank you Enis, you are a very patient person!
Are there tutorials that would lead up to doing something like this? Is there a particular "order" I should go in?

Taifun

unread,
Apr 4, 2015, 3:11:35 PM4/4/15
to mitappinv...@googlegroups.com
start with the first and continue with the next... and so on...

Do the tutorials to learn the basics of App Inventor.

You will not find a tutorial, which does exactly what you are looking for. But doing the tutorials (not only reading a little bit) help you to understand, how things are working. This is important and this is the first step to do.

Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

Matt Skoll

unread,
Apr 9, 2015, 11:00:03 AM4/9/15
to mitappinv...@googlegroups.com
Umm, what tutorial would that be? Working on the other ones trying to "absorb" them, just don't want to miss it.
Also, is there another resource for tutorials?

Matt

SteveJG

unread,
Apr 9, 2015, 1:32:48 PM4/9/15
to mitappinv...@googlegroups.com
Try this car example by ABG and build on it  https://groups.google.com/forum/#!searchin/mitappinventortest/unicode$20/mitappinventortest/pHPzRWFUJFc/_OGB1a9GdbUJ  

There may be simpler way to do this building on Enis' suggestions.


Regards,
Steve
Reply all
Reply to author
Forward
0 new messages