• Register

Live the carefree days of summer as a boy, collecting and trading baseball cards.

Report RSS The Mechanics of Trading Cards

Trading cards with an NPC requires the computer to decide if a trade is worthwhile. I explain the current algorithms in use and request your feedback and help.

Posted by on

The core of Waxpack Summer is trading cards. Currently, the game only supports trading with NPCs, so I had to devise a system that would make trading with the computer somewhat realistic. As I continue to build the game, these algorithms can surely be tweaked and improved, but for now, I just wanted to get the basics working.

Improved Look for the Trading Screen

It all starts with how a card set is generated. At the start of the game, after the player selects a summer to play, the game brings in all of the team and player data. Each player's card is created and given a scarcity level. Right now, this is how that level is assigned:

Batters

Batting average from .000 to .249 = Common

Batting average from .250 to .349 = Uncommon

Batting average greater than .349 = Rare

Pitchers

Earned run average greater than 3.25 = Common

Earned run average from 2.50 to 3.25 = Uncommon

Earned run average less than 2.50 = Rare

Players get cards by purchasing them at the store with money earned from mowing lawns. Each pack is randomly generated, taking into account the scarcity levels.

Now we are to the point where we want to trade cards with an NPC. What I've done, in order to give the NPC an easy way to determine if they want to make the trade or not is to assign a "trade weight". Different factors of the trade alter the trade weight (initially set to 0) either positively or negatively. In the end, if the trade weight is greater than 0, the NPC will make the trade. If not, he will refuse the trade.

Here are the trade weight adjusters:

Is the player offering more cards than he is requesting? +1 per additional card

Does the friend already have the card the player is offering? -1

Does the friend need the card the player is offering? +1

Total the scarcity levels for each side's offer using the following:

Common = 0

Uncommon = 1

Rare = 2

If the player is offering less total scarcity than the friend, subtract the difference.If the player is offering more total scarcity than the friend, add the difference.

Let's see this in action.

Friend Refusing a Trade

You can see here that I'm offering Dennis Martinez to my friend in return for Chet Lemon. Martinez is a 3.66 ERA pitcher and Lemon is a .318 batter. Using the weight adjusters, the friend doesn't like the trade.

Friend Accepting a Trade

Now you can see I sweetened the deal by also throwing in a Vic Correll card. Now my friend accepts the trade.

So, as I've mentioned, this is a pretty basic method for handling the AI functions for trading. Obviously there are a few flaws that need to be fixed. For example, I'm only looking at the last year's stats for the player. If it's a superstar card, but the player had an off year last year, he would still command a high demand.

I welcome any suggestions any of you may have on what would make a stronger algorithm to determine if a trade would be made or not. This is something that I can continuously improve and it is an interesting challenge. I hope you enjoyed this look at how the trading functions work at this point, and I look forward to hearing from you.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: