We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I'm reading a csv file which looks roughly like the following:
Each row is a different playing card.
My question is this: I'd like to pick a few rows at random (ace of hearts, five of diamonds, three of spades) and load their respective fields into my program but I need to make sure that no duplicate cards show up.
How do I limit the choices of a random table entry so that it only chooses entries that haven't been chosen before?
The way I'm doing it just now is finding a random row in my table, setting an int to that random row number called randcard, Then, say I wanted to find the jpg name of randcard, I'd do:
String s = table.getString(3,randcard)
But the problem is how to then pull another random card (row) from the deck, ignoring the ones that can't still be in there.
I hope this makes sense, thanks for your time. James
Answers
There are several ways. One of them is to store the cards you have drawn in a list. Then when you draw another card, you check if it is already in the list, and redraw if it is there. Not the most efficient way, but simple enough.
Another way is to make a copy of the list of cards. When you draw one, you just remove it from the list.
Made a Card class to represent a Table structured loaded from a ".csv" file. ;)
Since I don't have your original file (and images), I've made a sketch to create a similar 1.
If your original ".csv" file doesn't work w/ my program, you gotta generate a new 1 too:
And finally my model solution: :bz
A fast array based approach: