285 lines
17 KiB
HTML
285 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/merchant_utils.clj </title>
|
|
</head>
|
|
<body>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
001 (ns the-great-game.merchants.merchant-utils
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
002 "Useful functions for doing low-level things with merchants.")
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
003
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
004 (defn expected-price
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
005 "Find the price anticipated, given this `world`, by this `merchant` for
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
006 this `commodity` in this `city`. If no information, assume 1.
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
007 `merchant` should be passed as a map, `commodity` and `city` should be passed as keywords."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
008 [merchant commodity city]
|
|
</span><br/>
|
|
<span class="covered" title="5 out of 5 forms covered">
|
|
009 (or
|
|
</span><br/>
|
|
<span class="covered" title="2 out of 2 forms covered">
|
|
010 (:price
|
|
</span><br/>
|
|
<span class="covered" title="2 out of 2 forms covered">
|
|
011 (last
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
012 (sort-by
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
013 :date
|
|
</span><br/>
|
|
<span class="covered" title="7 out of 7 forms covered">
|
|
014 (-> merchant :known-prices city commodity))))
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
015 1))
|
|
</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 burden
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
018 "The total weight of the current cargo carried by this `merchant` in this
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
019 `world`."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
020 [merchant world]
|
|
</span><br/>
|
|
<span class="partial" title="3 out of 4 forms covered">
|
|
021 (let [m (cond
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
022 (keyword? merchant)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
023 (-> world :merchants merchant)
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
024 (map? merchant)
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
025 merchant)
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
026 cargo (:stock m)]
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
027 (reduce
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
028 +
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
029 0
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
030 (map
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 12 forms covered">
|
|
031 #(* (cargo %) (-> world :commodities % :weight))
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
032 (keys cargo)))))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
033
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
034
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
035 (defn can-carry
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
036 "Return the number of units of this `commodity` which this `merchant`
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
037 can carry in this `world`, given their current burden."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
038 [merchant world commodity]
|
|
</span><br/>
|
|
<span class="partial" title="3 out of 4 forms covered">
|
|
039 (let [m (cond
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
040 (keyword? merchant)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
041 (-> world :merchants merchant)
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
042 (map? merchant)
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
043 merchant)]
|
|
</span><br/>
|
|
<span class="covered" title="2 out of 2 forms covered">
|
|
044 (quot
|
|
</span><br/>
|
|
<span class="covered" title="9 out of 9 forms covered">
|
|
045 (- (:capacity m) (burden m world))
|
|
</span><br/>
|
|
<span class="covered" title="7 out of 7 forms covered">
|
|
046 (-> world :commodities commodity :weight))))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
047
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
048 (defn can-afford
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
049 "Return the number of units of this `commodity` which this `merchant`
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
050 can afford to buy in this `world`."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
051 [merchant world commodity]
|
|
</span><br/>
|
|
<span class="partial" title="3 out of 4 forms covered">
|
|
052 (let [m (cond
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
053 (keyword? merchant)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
054 (-> world :merchants merchant)
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
055 (map? merchant)
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
056 merchant)
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
057 l (:location m)]
|
|
</span><br/>
|
|
<span class="covered" title="2 out of 2 forms covered">
|
|
058 (quot
|
|
</span><br/>
|
|
<span class="covered" title="3 out of 3 forms covered">
|
|
059 (:cash m)
|
|
</span><br/>
|
|
<span class="covered" title="9 out of 9 forms covered">
|
|
060 (-> world :cities l :prices commodity))))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
061
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
062 (defn add-stock
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
063 "Where `a` and `b` are both maps all of whose values are numbers, return
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
064 a map whose keys are a union of the keys of `a` and `b` and whose values
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
065 are the sums of their respective values."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
066 [a b]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 2 forms covered">
|
|
067 (reduce
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 1 forms covered">
|
|
068 merge
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 1 forms covered">
|
|
069 a
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
070 (map
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 21 forms covered">
|
|
071 #(hash-map % (+ (or (a %) 0) (or (b %) 0)))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
072 (keys b))))
|
|
</span><br/>
|
|
<span class="blank" title="0 out of 0 forms covered">
|
|
073
|
|
</span><br/>
|
|
<span class="covered" title="1 out of 1 forms covered">
|
|
074 (defn add-known-prices
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
075 "Add the current prices at this `merchant`'s location in the `world`
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
076 to a new cacke of known prices, and return it."
|
|
</span><br/>
|
|
<span class="not-tracked" title="0 out of 0 forms covered">
|
|
077 [merchant world]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 4 forms covered">
|
|
078 (let [m (cond
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
079 (keyword? merchant)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
080 (-> world :merchants merchant)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
081 (map? merchant)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 1 forms covered">
|
|
082 merchant)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
083 k (:known-prices m)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
084 l (:location m)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
085 d (:date world)
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 7 forms covered">
|
|
086 p (-> world :cities l :prices)]
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 2 forms covered">
|
|
087 (reduce
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 1 forms covered">
|
|
088 merge
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 1 forms covered">
|
|
089 k
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 3 forms covered">
|
|
090 (map
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 17 forms covered">
|
|
091 #(hash-map % (apply vector cons {:price (p %) :date d} (k %)))
|
|
</span><br/>
|
|
<span class="not-covered" title="0 out of 5 forms covered">
|
|
092 (-> world :commodities keys)))))
|
|
</span><br/>
|
|
</body>
|
|
</html>
|