All tests now pass.

This commit is contained in:
Simon Brooke 2023-12-23 20:55:59 +00:00
parent 936e0922ce
commit e9a51f060f
4 changed files with 27 additions and 30 deletions

View file

@ -26,7 +26,7 @@ So: how does one gain experience? I'm going to assume that anyone who's bought a
Of course, some people may be more observant than others, so it's possible that some people may gain appraisal skill on the basis of less exposure than others. But at this moment that's not a thing I'm planning to model. Of course, some people may be more observant than others, so it's possible that some people may gain appraisal skill on the basis of less exposure than others. But at this moment that's not a thing I'm planning to model.
## What does appraisal skill by you? ## What does appraisal skill buy you?
In any category of goods, some individual items are better than others, and this difference may be significant. A person with good appraisal skill will recognise this difference. So a person with good skills, offered two items at the same price, will be able to select the better one; if bargaining for an item, will be prepared to offer a higher price for the better one; if selling items, will be prepared to sell the better one only for a higher price. In any category of goods, some individual items are better than others, and this difference may be significant. A person with good appraisal skill will recognise this difference. So a person with good skills, offered two items at the same price, will be able to select the better one; if bargaining for an item, will be prepared to offer a higher price for the better one; if selling items, will be prepared to sell the better one only for a higher price.

View file

@ -30,7 +30,8 @@
This namespace at present considers the `:knowledge` of a gossip to be a flat This namespace at present considers the `:knowledge` of a gossip to be a flat
list of propositions, each of which must be checked every time any new list of propositions, each of which must be checked every time any new
proposition is offered. This is woefully inefficient. " proposition is offered. This is woefully inefficient. "
(:require [cc.journeyman.the-great-game.world.location :refer [distance-between]] (:require [clojure.set :refer [union]]
[cc.journeyman.the-great-game.world.location :refer [distance-between]]
[cc.journeyman.the-great-game.time :refer [game-time]] [cc.journeyman.the-great-game.time :refer [game-time]]
[cc.journeyman.the-great-game.utils :refer [inc-or-one truthy?]] [cc.journeyman.the-great-game.utils :refer [inc-or-one truthy?]]
[taoensso.timbre :as l])) [taoensso.timbre :as l]))
@ -115,12 +116,10 @@
:war {:verb :war :keys [:actor :other :location] :war {:verb :war :keys [:actor :other :location]
:inferences [{:verb :war :actor :other :other :actor}]}}) :inferences [{:verb :war :actor :other :other :actor}]}})
(def all-known-verbs (def all-known-verbs
"All verbs currently known to the gossip system." "All verbs currently known to the gossip system."
(set (keys news-topics))) (set (keys news-topics)))
(defn interest-in-character (defn interest-in-character
"Integer representation of how interesting this `character` is to this "Integer representation of how interesting this `character` is to this
`gossip`. `gossip`.
@ -134,7 +133,6 @@
(filter #(= (:actor %) character) (:knowledge gossip)) (filter #(= (:actor %) character) (:knowledge gossip))
(filter #(= (:other %) character) (:knowledge gossip))))) (filter #(= (:other %) character) (:knowledge gossip)))))
(defn interesting-character? (defn interesting-character?
"Boolean representation of whether this `character` is interesting to this "Boolean representation of whether this `character` is interesting to this
`gossip`." `gossip`."
@ -246,7 +244,7 @@
"True if anything about this news `item` is interesting to this `gossip`." "True if anything about this news `item` is interesting to this `gossip`."
[gossip item] [gossip item]
(and (not (known-item? gossip item)) (and (not (known-item? gossip item))
(interesting-verb? gossip item) ;; news is only interesting if the topic is. (interesting-verb? gossip (:verb item)) ;; news is only interesting if the topic is.
(or (or
(interesting-character? gossip (:actor item)) (interesting-character? gossip (:actor item))
(interesting-character? gossip (:other item)) (interesting-character? gossip (:other item))
@ -257,7 +255,7 @@
(defn infer (defn infer
"Infer a new knowledge item from this `item`, following this `rule`." "Infer a new knowledge item from this `item`, following this `rule`."
[item rule] [item rule]
;; (l/info "Applying rule '" rule "' to item '" item "'") (l/info "Applying rule '" rule "' to item '" item "'")
(reduce merge (reduce merge
item item
(cons (cons
@ -330,16 +328,17 @@
g (assoc g (assoc
gossip gossip
:knowledge :knowledge
(set
(cons (cons
item' item'
(:knowledge gossip)))] (:knowledge gossip))))]
(if follow-inferences? (if follow-inferences?
(assoc (assoc
g g
:knowledge :knowledge
(concat (:knowledge g) (make-all-inferences item'))) (union (:knowledge g) (make-all-inferences item')))
g))) g))
gossip)) gossip)))

View file

@ -146,8 +146,7 @@
#(let [q (-> world :cities origin :stock %)] #(let [q (-> world :cities origin :stock %)]
(and (number? q) (pos? q))) (and (number? q) (pos? q)))
(keys available)))] (keys available)))]
(if (when-not (empty? plans)
(not (empty? plans))
(first (first
(sort-by (sort-by
#(- 0 (:dist-to-home %)) #(- 0 (:dist-to-home %))

View file

@ -3,12 +3,12 @@
[cc.journeyman.the-great-game.gossip.news-items :refer [cc.journeyman.the-great-game.gossip.news-items :refer
[all-known-verbs compatible-item? degrade-location infer [all-known-verbs compatible-item? degrade-location infer
interest-in-character interesting-character? interest-in-location interest-in-character interesting-character? interest-in-location
interesting-location? learn-news-item make-all-inferences]])) interesting-location? learn-news-item make-all-inferences known-item?]]))
(deftest interesting-character-tests (deftest interesting-character-tests
(testing "To what degree characters are of interest to the gossip" (testing "To what degree characters are of interest to the gossip"
(let [expected 1 (let [expected 1
gossip {:home [{0, 0} :test-home] gossip {:home [{:x 0 :y 0} :test-home]
:interesting-verbs all-known-verbs :interesting-verbs all-known-verbs
;; already knows about adam ;; already knows about adam
:knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]} :knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]}
@ -17,7 +17,7 @@
:adam)] :adam)]
(is (= actual expected))) (is (= actual expected)))
(let [expected 0 (let [expected 0
gossip {:home [{0, 0} :test-home] gossip {:home [{:x 0 :y 0} :test-home]
:interesting-verbs all-known-verbs :interesting-verbs all-known-verbs
;; already knows about adam ;; already knows about adam
:knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]} :knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]}
@ -27,7 +27,7 @@
(is (= actual expected)))) (is (= actual expected))))
(testing "Whether characters are of interest to the gossip" (testing "Whether characters are of interest to the gossip"
(let [expected true (let [expected true
gossip {:home [{0, 0} :test-home] gossip {:home [{:x 0 :y 0} :test-home]
:interesting-verbs all-known-verbs :interesting-verbs all-known-verbs
;; already knows about adam ;; already knows about adam
:knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]} :knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]}
@ -36,7 +36,7 @@
:adam)] :adam)]
(is (= actual expected))) (is (= actual expected)))
(let [expected false (let [expected false
gossip {:home [{0, 0} :test-home] gossip {:home [{:x 0 :y 0} :test-home]
:interesting-verbs all-known-verbs :interesting-verbs all-known-verbs
;; already knows about adam ;; already knows about adam
:knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]} :knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]}
@ -158,12 +158,12 @@
(testing "Degrading locations" (testing "Degrading locations"
(let [expected [:galloway] (let [expected [:galloway]
actual (degrade-location actual (degrade-location
{:home [{0 0} :test-home :galloway]} {:home [{:x 0 :y 0} :test-home :galloway]}
[{-4 55} :auchencairn :galloway])] [{-4 55} :auchencairn :galloway])]
(is (= actual expected))) (is (= actual expected)))
(let [expected nil (let [expected nil
actual (degrade-location actual (degrade-location
{:home [{0 0} :test-home :galloway]} {:home [{:x 0 :y 0} :test-home :galloway]}
[:froboz])] [:froboz])]
(is (= actual expected))))) (is (= actual expected)))))
@ -195,17 +195,16 @@
(deftest learn-tests (deftest learn-tests
(testing "Learning from an interesting news item." (testing "Learning from an interesting news item."
(let [expected {:home [{0 0} :test-home] (let [gossip {:home [{:x 0 :y 0} :test-home]
:interesting-verbs all-known-verbs
:knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}
{:verb :sex, :actor :adam, :other :belinda, :location [:test-home], :nth-hand 1}
{:verb :sex, :actor :belinda, :other :adam, :location [:test-home], :nth-hand 1}]}
gossip {:home [{0, 0} :test-home]
:interesting-verbs all-known-verbs :interesting-verbs all-known-verbs
;; already knows about adam ;; already knows about adam
:knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]} :knowledge #{{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}}}
actual (learn-news-item g' (learn-news-item
gossip gossip
{:verb :sex :actor :adam :other :belinda :location [:test-home]})] {:verb :sex :actor :adam :other :belinda :location [:test-home]})]
(is (= actual expected))))) (and
(is (known-item? g' {:verb :sex :actor :adam :other :belinda :location [:test-home]})
"has learned the item that was given")
(is (known-item? g' {:verb :sex, :actor :belinda, :other :adam, :location [:test-home]})
"has learned information that can be inferred from that item")))))