261 lines
17 KiB
HTML
261 lines
17 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link rel="stylesheet" href="../../coverage.css"/> <title> the_great_game/merchants/markets.clj </title>
|
|
</head>
|
|
<body>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
001 (ns the-great-game.merchants.markets
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
002 "Adjusting quantities and prices in markets."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
003 (:require [taoensso.timbre :as l :refer [info error]]
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
004 [the-great-game.utils :refer [deep-merge]]))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
005
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
006 (defn new-price
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
007 "If `stock` is greater than the maximum of `supply` and `demand`, then
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
008 there is surplus and `old` price is too high, so shold be reduced. If
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
009 lower, then it is too low and should be increased."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
010 [old stock supply demand]
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
011 (let
|
|
</span><br/>
|
|
<span class="covered" title="10 out of 10 forms covered">
|
|
012 [delta (dec' (/ (max supply demand 1) (max stock 1)))
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
013 scaled (/ delta 100)]
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
014 (+ old scaled)))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
015
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
016
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
017 (defn adjust-quantity-and-price
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
018 "Adjust the quantity of this `commodity` currently in stock in this `city`
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
019 of this `world`. Return a fragmentary world which can be deep-merged into
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
020 this world."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
021 [world city commodity]
|
|
</span><br/>
|
|
<span class="partial" title="2 out of 4 forms covered">
|
|
022 (let [c (cond
|
|
</span><br/>
|
|
<span class="covered" title="8 out of 8 forms covered">
|
|
023 (keyword? city) (-> world :cities city)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 4 forms covered">
|
|
024 (map? city) city)
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
025 id (:id c)
|
|
</span><br/>
|
|
<span class="covered" title="10 out of 10 forms covered">
|
|
026 p (or (-> c :prices commodity) 0)
|
|
</span><br/>
|
|
<span class="covered" title="10 out of 10 forms covered">
|
|
027 d (or (-> c :demands commodity) 0)
|
|
</span><br/>
|
|
<span class="covered" title="10 out of 10 forms covered">
|
|
028 st (or (-> c :stock commodity) 0)
|
|
</span><br/>
|
|
<span class="covered" title="10 out of 10 forms covered">
|
|
029 su (or (-> c :supplies commodity) 0)
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
030 decrement (min st d)
|
|
</span><br/>
|
|
<span class="partial" title="5 out of 6 forms covered">
|
|
031 increment (cond
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
032 ;; if we've two turns' production of this commodity in
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
033 ;; stock, halt production
|
|
</span><br/>
|
|
<span class="covered" title="5 out of 5 forms covered">
|
|
034 (> st (* su 2))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
035 0
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
036 ;; if it is profitable to produce this commodity, the
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
037 ;; craftspeople of the city will do so.
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
038 (> p 1) su
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
039 ;; otherwise, if there isn't a turn's production in
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
040 ;; stock, top up the stock, so that there's something for
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
041 ;; incoming merchants to buy
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
042 (> su st)
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
043 (- su st)
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
044 :else
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
045 0)
|
|
</span><br/>
|
|
<span class="covered" title="6 out of 6 forms covered">
|
|
046 n (new-price p st su d)]
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
047 (if
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
048 (not= p n)
|
|
</span><br/>
|
|
<span class="covered" title="24 out of 24 forms covered">
|
|
049 (l/info "Price of" commodity "at" id "has changed from" (float p) "to" (float n)))
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
050 {:cities {id
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
051 {:stock
|
|
</span><br/>
|
|
<span class="covered" title="7 out of 7 forms covered">
|
|
052 {commodity (+ (- st decrement) increment)}
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
053 :prices
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
054 {commodity n}}}}))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
055
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
056
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
057 (defn update-markets
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
058 "Return a world like this `world`, with quantities and prices in markets
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
059 updated to reflect supply and demand. If `city` or `city` and `commodity`
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
060 are specified, return a fragmentary world with only the changes for that
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
061 `city` (and `commodity` if specified) populated."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
062 ([world]
|
|
</span><br/>
|
|
<span class="covered" title="2 out of 2 forms covered">
|
|
063 (reduce
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
064 deep-merge
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
065 world
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
066 (map
|
|
</span><br/>
|
|
<span class="covered" title="4 out of 4 forms covered">
|
|
067 #(update-markets world %)
|
|
</span><br/>
|
|
<span class="covered" title="5 out of 5 forms covered">
|
|
068 (keys (:cities world)))))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
069 ([world city]
|
|
</span><br/>
|
|
<span class="covered" title="2 out of 2 forms covered">
|
|
070 (reduce
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
071 deep-merge
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
072 {}
|
|
</span><br/>
|
|
<span class="covered" title="8 out of 8 forms covered">
|
|
073 (map #(update-markets world city %)
|
|
</span><br/>
|
|
<span class="covered" title="5 out of 5 forms covered">
|
|
074 (keys (:commodities world)))))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
075 ([world city commodity]
|
|
</span><br/>
|
|
<span class="covered" title="5 out of 5 forms covered">
|
|
076 (adjust-quantity-and-price world city commodity)))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
077
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
078
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
079 (defn run
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
080 "Return a world like this `world`, with quantities and prices in markets
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
081 updated to reflect supply and demand."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
082 [world]
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
083 (update-markets world))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
084
|
|
</span><br/>
|
|
</body>
|
|
</html>
|