Skip to content

Commit

Permalink
Testing nomadism updating/reading
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Sep 8, 2014
1 parent c078533 commit b17f557
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/civs/logic/tribe_choices.clj
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@
:become-semi-sedentary
chance-to-become-semi-sedentary
(fn [game tribe]
(let [new-culture (assoc (culture game tribe) :nomadism :semi-sedentary)]
(let [game (update-nomadism game tribe :semi-sedentary)]
{
:tribe tribe
:game (update-by-id game (.political-entity-id tribe) #(assoc % :culture new-culture))
:game game
:params {}
}))))

Expand All @@ -82,12 +81,11 @@
chance-to-become-sedentary
(fn [game tribe]
(let [ pos (.position tribe)
new-culture (assoc (.culture tribe) :nomadism :sedentary)
game (update-nomadism game tribe :sedentary)
language (get-language game tribe)
settlement-name (if (nil? language) :unnamed (.name language))]
{
:game (:game (create-settlement game settlement-name pos (:id tribe) current-turn))
:tribe (assoc tribe :culture new-culture)
:params {}
}))))

Expand Down
25 changes: 17 additions & 8 deletions src/civs/model/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
[civs.model.language]))

(defrecord PoliticalEntity [id name society groups culture])
(defrecord Game [world settlements groups political-entities next_id])
(declare culture)
(declare society)
(declare update-political-entity)
(declare to-political-entity)

; ###########################################################
; Generic
Expand Down Expand Up @@ -39,14 +41,23 @@
; To develop agriculture a population must be :semi-sedentary
; To become :sedentary a population must know agriculture

(defn sedentary? [game t]
(= :sedentary (.nomadism (culture game t))))
(defn sedentary? [game x]
(= :sedentary (.nomadism (culture game x))))

(defn semi-sedentary? [game x]
(= :semi-sedentary (.nomadism (culture game x))))

(defn nomadic? [game x]
(= :nomadic (.nomadism (culture game x))))

(defn semi-sedentary? [game t]
(= :semi-sedentary (.nomadism (culture game t))))
(defn valid-nomadism? [v]
(in? [:nomadic :semi-sedentary :sedentary] v))

(defn nomadic? [game t]
(= :nomadic (.nomadism (culture game t))))
(defn update-nomadism [game x nomadism]
{:pre [(valid-nomadism? nomadism)]
:post [(instance? Game %)]}
(let [pe (to-political-entity game x)]
(update-political-entity game (.id pe) (fn [pe _] (assoc-in pe [:culture :nomadism] nomadism)))))

(defrecord Culture [nomadism knowledge language])

Expand Down Expand Up @@ -256,8 +267,6 @@
; Game
; ###########################################################

(defrecord Game [world settlements groups political-entities next_id])

(defn create-game [world]
(Game. world {} {} {} 1))

Expand Down
30 changes: 29 additions & 1 deletion test/civs/model/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,42 @@
(is (= true (in? (list 1 2 3) 1)))
(is (= false (in? (list 1 2 3) 4))))


; ###########################################################
; Population
; ###########################################################

(deftest test-total-persons
(is (= 15 (total-persons (Population. 1 2 3 4 5)))))

(deftest test-active-persons
(is (= 5 (active-persons (Population. 1 2 3 4 5)))))

; ###########################################################
; Culture
; ###########################################################

(defn- consider-base-group [f]
(let [ga (create-game w77)
{ga :game gr :group} (create-tribe ga "name" {:x 15 :y 18} (Population. 1 2 3 4 5) initial-culture initial-society)]
(f ga gr)))

(deftest test-get-and-set-nomadism
(consider-base-group
(fn [ga gr]
(let [ga (update-nomadism ga gr :nomadic)]
(is (nomadic? ga gr))
(is (not (semi-sedentary? ga gr)))
(is (not (sedentary? ga gr))))
(let [ga (update-nomadism ga gr :semi-sedentary)]
(is (not (nomadic? ga gr)))
(is (semi-sedentary? ga gr))
(is (not (sedentary? ga gr))))
(let [ga (update-nomadism ga gr :sedentary)]
(is (not (nomadic? ga gr)))
(is (not (semi-sedentary? ga gr)))
(is (sedentary? ga gr))))))


(deftest test-is-dead?
(is (= false (is-dead? (Group. nil nil nil (Population. 1 2 3 4 5) nil))))
(is (= true (is-dead? (Group. nil nil nil (Population. 0 0 0 0 0) nil)))))
Expand Down

0 comments on commit b17f557

Please sign in to comment.