What kind of data are you storing? You should only save references to cards for your player, unless there are some random stats that may change (in that case you'll have to store those as well).
Since you didn't specify any language, I'm assuming C++. Similar techniques can be used in other languages as well, they'll just require some different syntax.
First of all, you'll need your cards identified by some unique ID. Since there might be unassigned IDs, I'll be using a
std::map for now:
std::map<unsigned int, CardInformation> cardData;
This now allows me to access the card information for any specific card. For example, let's assume you'd like to retrieve the card data for ID 50123:
const CardInformation &myCard = cardData;
As you can see, this is pretty straightforward. Now, as part of your player's dataset, you'll want some collection of cards - or more specific: card IDs.
You could use a
std::vector for this, which is more than sufficient. However, this makes counting cards quite cumbersome. So instead, I'm using another
std::map, which would then be part of the player data:
std::map<unsigned int, unsigned char> playerDeck; // own up to 255 copies of each card!
This now allows you to do some pretty neat and simple tricks.
How about giving the player one copy of card ID 1023?
Does the player have card ID 323 in his deck? (naïve approach; will slow down/fill your map over time)
const bool hasCard = playerDeck > 0;
Does the player have card ID 323 in his deck? (better approach)
const bool hasCard = (playerDeck.find(323) != playerDeck.end());
How to let the player remove card ID 50 from the deck? (Note this won't remove empty entries)
So, how to store the data in a game file or submit it for a networked game? Pretty easy: Just iterate over the
std::map containing the deck and store/submit values if the value is not 0. Keep in mind that submitting your deck to the enemy might not be a good idea and subject to abuse (to see the enemy's/your deck).