Today is the Fifth Plough of the Plough

Implemented almost the whole of the Myth of the God Incarnate calendar
This commit is contained in:
Simon Brooke 2020-04-14 08:30:41 +01:00
parent bd76e93568
commit 7e7a55c8ec
39 changed files with 2085 additions and 167 deletions

View file

@ -0,0 +1,4 @@
(ns the-great-game.gossip.gossip-test
(:require [clojure.test :refer :all]
[the-great-game.gossip.gossip :refer :all]))

View file

@ -0,0 +1,132 @@
(ns the-great-game.gossip.news-items-test
(:require [clojure.test :refer :all]
[the-great-game.gossip.news-items :refer :all]))
(deftest location-test
(testing "Interest in locations"
(let [expected 1
actual (interest-in-location
{:knowledge [{:verb :steal
:actor :albert
:other :belinda
:object :foo
:location [{:x 35 :y 23} :auchencairn :galloway]}]}
:galloway)]
(is (= actual expected)))
(let [expected 2
actual (interest-in-location
{:knowledge [{:verb :steal
:actor :albert
:other :belinda
:object :foo
:location [{:x 35 :y 23} :auchencairn :galloway :scotland]}]}
[:galloway :scotland])]
(is (= actual expected)))
(let [expected 0
actual (interest-in-location
{:knowledge [{:verb :steal
:actor :albert
:other :belinda
:object :foo
:location [{:x 35 :y 23} :auchencairn :galloway]}]}
[:dumfries])]
(is (= actual expected)))
(let [expected 7071.067811865475
actual (interest-in-location
{:home [{:x 35 :y 23}]}
[{:x 34 :y 24}])]
(is (= actual expected)
"TODO: 7071.067811865475 is actually a bad answer."))
(let [expected 0
actual (interest-in-location
{:home [{:x 35 :y 23}]}
[{:x 34 :y 24000}])]
(is (= actual expected)
"Too far apart (> 10000)."))
(let [expected true
actual (interesting-location?
{:knowledge [{:verb :steal
:actor :albert
:other :belinda
:object :foo
:location [{:x 35 :y 23} :auchencairn :galloway]}]}
:galloway)]
(is (= actual expected)))
(let [expected true
actual (interesting-location?
{:knowledge [{:verb :steal
:actor :albert
:other :belinda
:object :foo
:location [{:x 35 :y 23} :auchencairn :galloway]}]}
[:galloway :scotland])]
(is (= actual expected)))
(let [expected false
actual (interesting-location?
{:knowledge [{:verb :steal
:actor :albert
:other :belinda
:object :foo
:location [{:x 35 :y 23} :auchencairn :galloway]}]}
[:dumfries])]
(is (= actual expected)))
(let [expected true
actual (interesting-location?
{:home [{:x 35 :y 23}]}
[{:x 34 :y 24}])]
(is (= actual expected)))
(let [expected false
actual (interesting-location?
{:home [{:x 35 :y 23}]}
[{:x 34 :y 240000}])]
(is (= actual expected))))
(testing "Degrading locations"
(let [expected [:galloway]
actual (degrade-location
{:home [{0 0} :test-home :galloway]}
[{-4 55} :auchencairn :galloway])]
(is (= actual expected)))
(let [expected nil
actual (degrade-location
{:home [{0 0} :test-home :galloway]}
[:froboz])]
(is (= actual expected)))))
(deftest inference-tests
(testing "Ability to infer new knowledge from news items: single rule tests"
(let [expected {:verb :marry, :actor :belinda, :other :adam}
actual (infer {:verb :marry :actor :adam :other :belinda}
{:verb :marry :actor :other :other :actor})]
(is (= actual expected)))
(let [expected {:verb :attack, :actor :adam, :other :belinda}
actual (infer {:verb :rape :actor :adam :other :belinda}
{:verb :attack})]
(is (= actual expected)))
(let [expected {:verb :sex, :actor :belinda, :other :adam}
actual (infer {:verb :rape :actor :adam :other :belinda}
{:verb :sex :actor :other :other :actor})]
(is (= actual expected))))
(testing "Ability to infer new knowledge from news items: all applicable rules"
(let [expected #{{:verb :sex, :actor :belinda, :other :adam, :location nil, :nth-hand 1}
{:verb :sex, :actor :adam, :other :belinda, :location nil, :nth-hand 1}
{:verb :attack, :actor :adam, :other :belinda, :location nil, :nth-hand 1}}
;; dates will not be and cannot be expected to be equal
actual (make-all-inferences
{:verb :rape :actor :adam :other :belinda :location :test-home})
actual' (map #(dissoc % :date) actual)]
(is (= actual' expected)))))
;; (deftest learn-tests
;; (testing "Learning from an interesting news item."
;; (let [expected {:home [{0 0} :test-home],
;; :knowledge ({:verb :rape, :actor :adam, :other :belinda, :location nil, :nth-hand 1}
;; {:verb :sex, :actor :belinda, :other :adam, :location nil, :nth-hand 1}
;; {:verb :attack, :actor :adam, :other :belinda, :location nil, :nth-hand 1}
;; {:verb :sex, :actor :adam, :other :belinda, :location nil, :nth-hand 1})}
;; actual (learn-news-item
;; {:home [{0, 0} :test-home]
;; :knowledge []}
;; {:verb :rape :actor :adam :other :belinda :location [:test-home]})
;; actual' (assoc actual :knowledge (map #(dissoc % :date) (:knowledge actual)))]
;; (is (= actual' expected)))))

View file

@ -0,0 +1,79 @@
(ns the-great-game.time-test
(:require [clojure.test :refer :all]
;; [clojure.core.async :refer [thread <!]]
[the-great-game.time :refer :all]))
(deftest now-tests
(testing "Time progresses"
(let [t1 (now)]
(is (> t1 game-start-time))
(Thread/sleep 1000)
(is (> (now) t1)))))
(deftest game-time-tests
(testing "Getting game-time"
(is (= (game-time (inc game-start-time)) 1))))
(deftest calendar-tests
(testing "In-game calendar functions"
(let [expected :foot
actual (day 0)]
(is (= actual expected)))
(let [expected :stomach
actual (day (* 5 game-day-length))]
(is (= actual expected)))
(let [expected :foot
actual (day (* days-in-week game-day-length))]
(is (= actual expected)))
(let [expected :first ;; waiting day
actual (day (* 360 game-day-length))]
(is (= actual expected)))
(let [expected :first
actual (week 0)]
(is (= actual expected)))
(let [expected :second
actual (week (* days-in-week game-day-length))]
(is (= actual expected)))
(let [expected :first
actual (week (* days-in-season game-day-length))]
(is (= actual expected)))
(let [expected :foot
actual (season 0)]
(is (= actual expected)))
(let [expected :mouth
actual (season (* 180 game-day-length))]
(is (= actual expected)))
(let [expected :eye
actual (season (* 359 game-day-length))]
(is (= actual expected)))
(let [expected :waiting
actual (season (* 360 game-day-length))]
(is (= actual expected)))
(let [expected :foot
actual (season (* 365 game-day-length))]
(is (= actual expected)))))
(deftest date-string-tests
(testing "Date-string formatting"
(let [expected "First Foot of the Foot"
actual (date-string 0)]
(is (= actual expected)))
(let [expected "First Foot of the Nose"
actual (date-string
(* days-in-season game-day-length))]
(is (= actual expected)))
(let [expected "Third Mouth of the Mouth"
actual (date-string (* 180 game-day-length))]
(is (= actual expected)))
(let [expected "Fifth Plough of the Eye"
actual (date-string (* 359 game-day-length))]
(is (= actual expected)))
(let [expected "First waiting day"
actual (date-string (* 360 game-day-length))]
(is (= actual expected)))
(let [expected "First Foot of the Foot"
actual (date-string (* 365 game-day-length))]
(is (= actual expected)))))

View file

@ -0,0 +1,36 @@
(ns the-great-game.world.location-test
(:require [clojure.test :refer :all]
[the-great-game.world.location :refer :all]))
(deftest get-coords-test
(testing "Get coordinates of location"
(let [expected {:x 5 :y 7}
actual (get-coords {:x 5 :y 7})]
(is (= actual expected)))
(let [expected {:x -4 :y 55}
actual (get-coords [{:x -4 :y 55} :auchencairn :galloway :scotland])]
(is (= actual expected)))
(let [expected nil
actual (get-coords [:auchencairn :galloway :scotland])]
(is (= actual expected)))
))
(deftest distance-test
(testing "Distance between two locations"
(let [expected 4.242640687119285
actual (distance-between {:x 5 :y 5} {:x 2 :y 2})]
(is (= actual expected)))
(let [expected 3
actual (distance-between {:x 5 :y 5} {:x 2 :y 5})]
(is (= actual expected)))
(let [expected 50.80354318352215
actual (distance-between
{:x 5 :y 5}
[{:x -4 :y 55} :auchencairn :galloway :scotland])]
(is (= actual expected)))
(let [expected nil
actual (distance-between
{:x 5 :y 5}
[:auchencairn :galloway :scotland])]
(is (= actual expected)))
))