Spielerando

Shop (Buy and Sell)

A shop swaps coins for items. Buying costs the full price or does not happen, and it checks the shelf, the bag and the coins first. Selling pays only a share of the price, rounded down for each item, so buying and selling in a circle can never earn coins, and sold items go back on the shelf.

Also called: Merchant, Store, Vendor, Trading post.

A hedgehog shopkeeper in a clay burrow shop hands a glowing lantern across the counter to an otter customer, while a silver coin drops onto a stack of coins in front of them.
Thimblewick Hollow, an invented burrow-town trading game. Invented game, image generated with AI.

Paste this to your AI

Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.

Add "Shop (Buy and Sell)" to my game.

What it should do: A shop turns coins into things the player wants and things the player no longer needs back into coins, without ever letting the player print money.

Use these starting values:
- sellShare: 0.4 share
- bagLimit: 20 items

Watch out for these common mistakes:
- Rounding makes a profit: Tell your AI: work out the sale price for one item, round it down, and multiply by the amount. Never let the sale price go above the buy price.
- Selling by the pile pays more than selling one by one: Tell your AI: round the price of a single item first, then multiply.
- An item worth nothing is swallowed: Tell your AI: if an item would sell for zero, refuse the sale and say why, instead of taking it.
- A purchase half-happens: Tell your AI: check the shelf, the bag and the coins first, and only then change anything. Either the whole purchase happens or none of it.
- The shelf runs out or never fills: Tell your AI: check the shelf every time before a purchase, and put sold items back on the shelf.
- A strange amount: Tell your AI: only accept whole amounts above zero, and ignore everything else.

Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP

What it does

A shop turns coins into things the player wants and things the player no longer needs back into coins, without ever letting the player print money.

Good starting values

ValueStart withWhat it changes
sellShare0.4 shareHow much of an item's price the shop pays when it buys the item back. A low share makes buying a real decision. It never goes above 1, because the shop would then pay for a player who buys and sells in a circle.
bagLimit20 itemsHow many items the bag holds in all. A small bag makes the player choose what to buy and what to sell.

What usually goes wrong

Rounding makes a profit

The shop works out the share for the whole pile and rounds up, or rounds each price up. A cheap item bought for 3 coins then sells for 3, and a pile sells for more than it cost. A player can loop through the shop for free coins.

Fix: Tell your AI: work out the sale price for one item, round it down, and multiply by the amount. Never let the sale price go above the buy price.

Selling by the pile pays more than selling one by one

If the share is applied to the total, a pile of ten cheap items pays more than ten single sales, because the rounding happens once instead of ten times. Players find out and always sell in piles.

Fix: Tell your AI: round the price of a single item first, then multiply.

An item worth nothing is swallowed

A cheap item's sale price rounds down to zero. The shop takes the item, gives nothing back, and the player loses it, often by accident.

Fix: Tell your AI: if an item would sell for zero, refuse the sale and say why, instead of taking it.

A purchase half-happens

The coins are taken, then the bag turns out to be full, so the player pays and gets nothing. Or the item arrives but the coins were never taken.

Fix: Tell your AI: check the shelf, the bag and the coins first, and only then change anything. Either the whole purchase happens or none of it.

The shelf runs out or never fills

A shop with a fixed stock lets two players or two quick clicks buy the last item twice. And a shop that does not take sold items back on the shelf slowly loses its goods.

Fix: Tell your AI: check the shelf every time before a purchase, and put sold items back on the shelf.

A strange amount

An amount of zero, below zero or with a fraction can turn a purchase into a sale or give coins away. A sale of minus three items would pay the player to take items.

Fix: Tell your AI: only accept whole amounts above zero, and ignore everything else.

How to check it works

Works well with

Common questions

how should a game shop pay when the player sells an item

Pay a share of the buy price, rounded down for each single item. Around 40 percent is a good start. Never pay the full price or more, or the player can earn coins by buying and selling in a circle.

what do i tell my ai to add a shop to my game

Paste this: Add a shop with a price list and a count of each item on its shelf. A purchase checks the shelf, the bag room and the coins first, and then either happens in full or not at all. Selling pays 40 percent of the price, rounded down per item, and puts the item back on the shelf.

why can players make infinite money in a shop

Usually the selling price is the same as or above the buying price, or the rounding goes in the player's favour. Round every sale down for a single item and keep the sell share at 1 or below.

what happens when the bag is full and the player buys something

The purchase is refused before any coins move, and the game tells the player why. Taking the coins first and finding no room afterwards is the common bug.

Where it comes from

We could not find a reliable origin for this one yet.

Where this mechanic comes from has not been researched yet.

Games are named only as references. Names and marks belong to their owners, and nothing here is endorsed by them.

What was checked

This is what separates the blueprint from a catalogue entry: the values on this page come from code that runs.

Your AI gets the code

Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it