the-great-game.merchants.merchants

Trade planning for merchants, primarily.

add-known-prices

(add-known-prices merchant world)

Add the current prices at this merchant’s location in the world to a new cacke of known prices, and return it.

add-stock

(add-stock a b)

Where a and b are both maps all of whose values are numbers, return a map whose keys are a union of the keys of a and b and whose values are the sums of their respective values.

augment-plan

(augment-plan merchant world plan)

Augment this plan constructed in this world for this merchant with the :quantity of goods which should be bought and the :expected-profit of the trade.

Returns the augmented plan.

burden

(burden merchant world)

The total weight of the current cargo carried by this merchant in this world.

can-afford

(can-afford merchant world commodity)

Return the number of units of this commodity which this merchant can afford to buy in this world.

can-carry

(can-carry merchant world commodity)

Return the number of units of this commodity which this merchant can carry in this world, given their current burden.

expected-price

(expected-price merchant commodity city)

Find the price anticipated, given this world, by this merchant for this commodity in this city. If no information, assume 1. merchant should be passed as a map, commodity and city should be passed as keywords.

generate-trade-plans

(generate-trade-plans merchant world commodity)

Generate all possible trade plans for this merchant and this commodity in this world.

Returned plans are maps with keys:

  • :merchant - the id of the merchant for whom the plan was created;
  • :origin - the city from which the trade starts;
  • :destination - the city to which the trade is planned;
  • :commodity - the commodity to be carried;
  • :buy-price - the price at which that commodity can be bought;
  • :expected-price - the price at which the merchant anticipates that commodity can be sold;
  • :distance - the number of stages in the planned journey
  • :dist-to-home - the distance from destination to the merchant’s home city.

make-target-filter

(make-target-filter targets)

Construct a filter which, when applied to a list of maps, will pass those which match these targets, where each target is a tuple [key value].

move-merchant

(move-merchant merchant world)

Handle general en route movement of this merchant in this world.

nearest-with-targets

(nearest-with-targets plans targets)

Return the distance to the nearest destination among those of these plans which match these targets. Plans are expected to be plans as returned by generate-trade-plans, q.v.; targets are expected to be as accepted by make-target-filter, q.v.

plan-and-buy

(plan-and-buy merchant world)

Return a world like this world, in which this merchant has planned a new trade, and bought appropriate stock for it. If no profitable trade can be planned, the merchant is simply moved towards their home.

plan-trade

(plan-trade merchant world commodity)

Find the best destination in this world for this commodity given this merchant and this origin. If two cities are anticipated to offer the same price, the nearer should be preferred; if two are equally distant, the ones nearer to the merchant’s home should be preferred. merchant may be passed as a map or a keyword; commodity should be passed as a keyword.

The returned plan is a map with keys:

  • :merchant - the id of the merchant for whom the plan was created;
  • :origin - the city from which the trade starts;
  • :destination - the city to which the trade is planned;
  • :commodity - the commodity to be carried;
  • :buy-price - the price at which that commodity can be bought;
  • :expected-price - the price at which the merchant anticipates that commodity can be sold;
  • :distance - the number of stages in the planned journey
  • :dist-to-home - the distance from destination to the merchant’s home city.

re-plan

(re-plan merchant world)

Having failed to sell a cargo at current location, re-plan a route to sell the current cargo. Returns a revised world.

run

(run world)

Return a world like this world, but with each merchant moved.

select-cargo

(select-cargo merchant world)

A merchant, in a given location in a world, will choose to buy a cargo within the limit they are capable of carrying, which they can anticipate selling for a profit at a destination.

sell-and-buy

(sell-and-buy merchant world)

Return a new world like this world, in which this merchant has sold their current stock in their current location, and planned a new trade, and bought appropriate stock for it.