Skip to content

Commit

Permalink
Merge branch 'v0.1.2' of github.com:garbados/the-longtime-game into v…
Browse files Browse the repository at this point in the history
…0.1.2
  • Loading branch information
garbados committed Nov 13, 2023
2 parents ad2fd3b + 1a36a8a commit 40cfcae
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/the_longtime_game/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@
(let [population (-> herd :individuals count)
optimal (calc-optimal-population herd)
delta (- optimal population)
n (int (Math/abs (Math/log delta)))]
n (int (Math/log (max 1 (Math/abs delta))))]
(if (> delta 0)
[(rand-int n) (rand-int 2)]
[(rand-int 2) (rand-int n)])))
Expand Down
17 changes: 15 additions & 2 deletions src/the_longtime_game/event.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@
individual
#(update % :traits disj :weary))))})

(def funeral
{:name "Funeral"
:text-fn event-text/funeral
:selects [{}]
:filter-fn
#(< 1 (count (:new-dead %)))
:marshal-fn
(fn [herd & _]
(first (:new-dead herd)))
:effect
(fn [herd & _] herd)})

(def gruxnis-attack!
{:name "Grux'nis attack"
:text-fn event-text/gruxnis-attack!
Expand Down Expand Up @@ -138,12 +150,13 @@
gruxnis-attack!
ration-rot
plague
wound-healed])
wound-healed
crossed-paths])

(def general-events
[journeying-ends
offshoot-joins
crossed-paths])
funeral])

(s/def ::event
(s/with-gen
Expand Down
74 changes: 71 additions & 3 deletions src/the_longtime_game/event_text.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns the-longtime-game.event-text
(:require [clojure.string :as string]
[the-longtime-game.core :as core]))
[the-longtime-game.core :as core]
[the-longtime-game.text :as text]))

(def -trait->adj
{:angry "strong"
Expand Down Expand Up @@ -86,8 +87,51 @@
"")))

(defn gruxnis-attack!
[herd [victim ibba] & _]
"TODO")
[_herd [victim ibba] & _]
(text/join-text
"A Grux'nis is a great beast,
a glorious testament to the fecund murk
of the Yuliak Range's swampy base.
Tough and shiny scales,
quick and vicious beak,
and toesome flippers that flop on land
but fly in water.
They eat the bottom-feeders of the upland bogs,
but can be drawn by chance down the riverfloes
to the paths of the herds."
(:name victim) "was attacked on the beach,"
"where" (:name ibba) "fought it off with adroit hand and crushing arm."
"The beast was only scared back into the water, but not to end its ways.
So the threat remained."
(:name ibba) "traveled out lonesome to riddle with other herds"
"of how to pacify a Grux'nis.
In their heart they could not accept killing the animal outright,
though some argued easily for the necessity.
Facile, they thought.
But still they took a spear and went to kill the thing.
They goaded it with caught fish,
but recognized in its rampaging eye a worm --
a worm that aggravates the temper,
and elicits rampant violence,
that can be driven out with a tincture.
Deftly they fought with the beast, as the sun rose and fell,
nipping it with a blade bathed in sleeping poison.
Blow by blow, the Grux'nis staggered,
until it felt, and slept!
Asleep," (:name ibba) "could treat it."
"It awoke bound but clear-eyed."
(:name ibba) "would not take chances,"
"not more than this chance of knowing a Grux'nis in peace,
and though it struggled she watched it.
It was nervous now more than hungry, more than vicious.
So after a time they brought it to the river's edge and undid the bonds.
It fled, disappearing into the river with all the sound of a single droplet.
After that there were no more attacks.
The relief at violence averted brought great celebration."
"But" (:name ibba) "wondered still, where that creature"
"would go now. Back to the upland bogs, perhaps?
Or perhaps... to stay near,
to protect the one that saved its mind."))

(def journeying-ends
(fn [herd & _]
Expand Down Expand Up @@ -186,3 +230,27 @@
(:name sadcow) "offers a small thanks,"
"but their eyes go to the horizon,"
"the world open to them unfettered."])))

(def funeral
(fn [_herd [mourncow] deadcow]
(text/join-text
"All living things return to soil.
Life comes from life through death.
That is the cycle.
For the dead, the soil is turned over,
so that they lie deep beneath it,
and a sapling is placed over them.
What remains to mark their passing
is a mound in the earth
that becomes a limb of the land."
(:name deadcow) "was a friend of" (:name mourncow) ";"
"they will try to remember them fondly,
however bitterly their absence tastes.
They leave a complex legacy, a hole in the tapestry of the herd
that will take generations to scar over.
A friend heaps dirt on a hole in the ground
where their confidant will remain forever,
until the pieces of them return,
spoken by the tongues of the wind.
Life goes on,
differently.")))
29 changes: 15 additions & 14 deletions test/the_longtime_game/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,21 @@
`core/update-individuals
`core/update-nutrients]))

(deftest test-stable-population-growth
(let [herd (core/gen-herd)
optimal (core/calc-optimal-population herd)
herd*
(reduce
(fn [herd _]
(let [[journeyings deaths] (core/shift-population herd)
[new-adults new-dead] (core/calc-pop-changes herd journeyings deaths)]
(core/apply-pop-changes herd new-adults new-dead)))
herd
(range 100))]
(is (> (* 3/2 optimal)
(count (:individuals herd*))
(* 1/2 optimal)))))
(defspec test-stable-population-growth 5
(props/for-all
[herd (s/gen ::core/herd)]
(let [optimal (core/calc-optimal-population herd)
delta (- (count (:individuals herd)) optimal)
herd*
(reduce
(fn [herd _]
(let [[journeyings deaths] (core/shift-population herd)
[new-adults new-dead] (core/calc-pop-changes herd journeyings deaths)]
(core/apply-pop-changes herd new-adults new-dead)))
herd
(range 100))
delta* (- (count (:individuals herd*)) optimal)]
(is (> (Math/abs delta) (Math/abs delta*))))))

(deftest test-inc-max-skill
(testing "Skills should not change when inc'd if all skills are maxed."
Expand Down

0 comments on commit 40cfcae

Please sign in to comment.