From e9a51f060f88de70092fa00af6e5ef2eebb2994d Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sat, 23 Dec 2023 20:55:59 +0000 Subject: [PATCH] All tests now pass. --- doc/Appraisal.md | 2 +- .../the_great_game/gossip/news_items.clj | 21 ++++++------- .../the_great_game/merchants/planning.clj | 3 +- .../the_great_game/gossip/news_items_test.clj | 31 +++++++++---------- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/doc/Appraisal.md b/doc/Appraisal.md index bc2295b..3ba7b1a 100644 --- a/doc/Appraisal.md +++ b/doc/Appraisal.md @@ -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. -## 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. diff --git a/src/cc/journeyman/the_great_game/gossip/news_items.clj b/src/cc/journeyman/the_great_game/gossip/news_items.clj index 1be80a3..44a8cb1 100644 --- a/src/cc/journeyman/the_great_game/gossip/news_items.clj +++ b/src/cc/journeyman/the_great_game/gossip/news_items.clj @@ -30,7 +30,8 @@ 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 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.utils :refer [inc-or-one truthy?]] [taoensso.timbre :as l])) @@ -115,12 +116,10 @@ :war {:verb :war :keys [:actor :other :location] :inferences [{:verb :war :actor :other :other :actor}]}}) - (def all-known-verbs "All verbs currently known to the gossip system." (set (keys news-topics))) - (defn interest-in-character "Integer representation of how interesting this `character` is to this `gossip`. @@ -134,7 +133,6 @@ (filter #(= (:actor %) character) (:knowledge gossip)) (filter #(= (:other %) character) (:knowledge gossip))))) - (defn interesting-character? "Boolean representation of whether this `character` is interesting to this `gossip`." @@ -246,7 +244,7 @@ "True if anything about this news `item` is interesting to this `gossip`." [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 (interesting-character? gossip (:actor item)) (interesting-character? gossip (:other item)) @@ -257,7 +255,7 @@ (defn infer "Infer a new knowledge item from this `item`, following this `rule`." [item rule] -;; (l/info "Applying rule '" rule "' to item '" item "'") + (l/info "Applying rule '" rule "' to item '" item "'") (reduce merge item (cons @@ -330,16 +328,17 @@ g (assoc gossip :knowledge - (cons + (set + (cons item' - (:knowledge gossip)))] + (:knowledge gossip))))] (if follow-inferences? (assoc g :knowledge - (concat (:knowledge g) (make-all-inferences item'))) - g))) - gossip)) + (union (:knowledge g) (make-all-inferences item'))) + g)) + gossip))) diff --git a/src/cc/journeyman/the_great_game/merchants/planning.clj b/src/cc/journeyman/the_great_game/merchants/planning.clj index dd2e622..333eead 100644 --- a/src/cc/journeyman/the_great_game/merchants/planning.clj +++ b/src/cc/journeyman/the_great_game/merchants/planning.clj @@ -146,8 +146,7 @@ #(let [q (-> world :cities origin :stock %)] (and (number? q) (pos? q))) (keys available)))] - (if - (not (empty? plans)) + (when-not (empty? plans) (first (sort-by #(- 0 (:dist-to-home %)) diff --git a/test/cc/journeyman/the_great_game/gossip/news_items_test.clj b/test/cc/journeyman/the_great_game/gossip/news_items_test.clj index 0a81179..a806033 100644 --- a/test/cc/journeyman/the_great_game/gossip/news_items_test.clj +++ b/test/cc/journeyman/the_great_game/gossip/news_items_test.clj @@ -3,12 +3,12 @@ [cc.journeyman.the-great-game.gossip.news-items :refer [all-known-verbs compatible-item? degrade-location infer 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 (testing "To what degree characters are of interest to the gossip" (let [expected 1 - gossip {:home [{0, 0} :test-home] + gossip {:home [{:x 0 :y 0} :test-home] :interesting-verbs all-known-verbs ;; already knows about adam :knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]} @@ -17,7 +17,7 @@ :adam)] (is (= actual expected))) (let [expected 0 - gossip {:home [{0, 0} :test-home] + gossip {:home [{:x 0 :y 0} :test-home] :interesting-verbs all-known-verbs ;; already knows about adam :knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]} @@ -27,7 +27,7 @@ (is (= actual expected)))) (testing "Whether characters are of interest to the gossip" (let [expected true - gossip {:home [{0, 0} :test-home] + gossip {:home [{:x 0 :y 0} :test-home] :interesting-verbs all-known-verbs ;; already knows about adam :knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]} @@ -36,7 +36,7 @@ :adam)] (is (= actual expected))) (let [expected false - gossip {:home [{0, 0} :test-home] + gossip {:home [{:x 0 :y 0} :test-home] :interesting-verbs all-known-verbs ;; already knows about adam :knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]} @@ -158,12 +158,12 @@ (testing "Degrading locations" (let [expected [:galloway] actual (degrade-location - {:home [{0 0} :test-home :galloway]} + {:home [{:x 0 :y 0} :test-home :galloway]} [{-4 55} :auchencairn :galloway])] (is (= actual expected))) (let [expected nil actual (degrade-location - {:home [{0 0} :test-home :galloway]} + {:home [{:x 0 :y 0} :test-home :galloway]} [:froboz])] (is (= actual expected))))) @@ -195,17 +195,16 @@ (deftest learn-tests (testing "Learning from an interesting news item." - (let [expected {:home [{0 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] + (let [gossip {:home [{:x 0 :y 0} :test-home] :interesting-verbs all-known-verbs ;; already knows about adam - :knowledge [{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}]} - actual (learn-news-item + :knowledge #{{:verb :sell :actor :adam :other :charles :object :wheat :quantity 10 :price 5 :location [:test-home]}}} + g' (learn-news-item gossip {: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")))))