Skip to content

Instantly share code, notes, and snippets.

@halogenandtoast halogenandtoast/progress.clj Secret
Last active Aug 29, 2015

Embed
What would you like to do?
(ns progress.core
(:gen-class)
(:require [clojure.pprint :refer [pprint]])
(:require [clojure.data.json :as json]))
(defn prompt [string]
(print string)
(flush)
(read-line))
(defn make-player [n]
{
:name (prompt (str "Player " n " Name: "))
:hand []
:knowledge {:science [] :engineering [] :culture [] :general []}
:technologies { :science [] :engineering [] :culture []}
:developments []
:power {:prestige 0 :population 0 :army 0}
:skills
{:action 2
:draw 3
:hand_size 5
:shuffle 1
:development 1
:research 4
:quick_draw {:draw 1 :discard 0}}})
(defn get-players [number-of-players]
(mapv
#(make-player (inc %))
(range number-of-players)))
(defn load-deck [deck-name]
(-> deck-name
slurp
(json/read-str :key-fn keyword)
:cards
shuffle))
(defn make-game []
(let [number-of-players (read-string (prompt "Number of players: "))]
{:number-of-players number-of-players
:running true
:age 1
:players (get-players number-of-players)
:decks [(load-deck "age1.json")]}))
(defn draw-cards [card-count game]
(let [index (dec (:age game)) deck (nth (:decks game) index)]
[(take card-count deck)
(update-in game [:decks index] #(drop card-count %))])))
(defn deal-cards [game player-number number-of-cards]
(let [[cards state] (draw-cards number-of-cards game)]
(update-in state [:players player-number :hand] #(into cards %))))
(defn deal-initial-hands [game]
(reduce
#(deal-cards %1 %2 5)
game
(range (:number-of-players game))))
(defn play-turn [game turn]
(println (str "Playing turn " turn))
(if (= turn 3)
(merge game { :running false })
game))
(defn shuffle-deck [game deck-number]
(update-in game [:decks deck-number] shuffle))
(defn shuffle-decks [game]
(reduce
shuffle-deck
game
(range (count (:decks game)))))
(defn setup-game [game]
(let [game' (shuffle-decks game)]
(deal-initial-hands game')))
(defn play-game [game]
(loop [state (setup-game game) turn 1]
(let [new_state (play-turn state turn)]
(when (:running new_state)
(recur new_state (inc turn))))))
(defn -main
[& args]
(let [game (make-game)]
(play-game game)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.