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.

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
| Value | Start with | What it changes |
|---|---|---|
| sellShare | 0.4 share | How 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. |
| bagLimit | 20 items | How 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
- You have 100 coins and the shop has 5 potions at 30 coins each. you buy 2 potions: you have 40 coins and 2 potions, and the shop has 3 left.
- You have 100 coins and a potion costs 30. you try to buy 4 potions: nothing is bought and you keep all 100 coins.
- The shop has only 1 lantern left. you try to buy 2 lanterns: nothing is bought, even if you could pay.
- Your bag holds at most 3 items and already holds 2. you try to buy 2 more, then 1: the first purchase is refused and nothing changes, and the second goes through.
- You hold 2 potions, a potion costs 30, and the shop pays 40 percent. you sell both: you get 24 coins and the shop has the potions back on its shelf.
- You hold 10 ropes, a rope costs 12, and the shop pays 40 percent. you sell them all at once, or one at a time: you get 4 coins per rope, 40 in total, either way.
- You hold a pebble that the shop sells for 2 coins, so it would buy back for less than one coin. you try to sell it: the sale is refused, you keep the pebble and no coins change.
- You hold 1 rope. you try to sell 2: nothing is sold.
- You have 100 coins. you buy 3 potions and sell them straight back: you have 46 coins and the shop is as it was. Even if the shop paid back the full price you would have 100, never more.
- You carry a feather that is not on the shop's price list. you try to sell it: the sale is refused and you keep the feather.
- You hold 4 potions. you try to buy or sell 0, minus 3, one and a half, or a number that is not a number: nothing happens and your coins and bag are unchanged.
Works well with
- Currency Wallet: Keep one place that changes coins, so the shop and the rest of the game cannot disagree. Let the wallet hold the coins and decide whether a price can be paid. The shop asks the wallet and then moves the items.
- Inventory System: A purchase that does not fit must be refused whole, not paid for and lost. Check the room in the bag first, then pay, then add the items in one go.
- Loot Table: A shelf that changes on every visit makes it impossible to plan a purchase. Roll the shop's goods when it opens or restocks, then keep them on the shelf as plain counts.
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.
What was checked
- 14 tests pass on the reference code.
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