Skip to content

Instantly share code, notes, and snippets.

@kindlychung
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kindlychung/d529b518cb1e87bd83a0 to your computer and use it in GitHub Desktop.
Save kindlychung/d529b518cb1e87bd83a0 to your computer and use it in GitHub Desktop.
(ns kaiyin.wumpus.game
(:require [kaiyin.wumpus.graphing :refer [dot-label]]))
(def city-nodes (atom nil))
(def city-edges (atom nil))
(def player-pos (ref nil))
(def visited-nodes (ref #{}))
(def player-status (atom :in-progress))
(def ^:dynamic *node-num* 8)
(def ^:dynamic *edge-num* 5)
(def ^:dynamic *worm-num* 3)
(def ^:dynamic *cop-odds* 4)
(defn filterb
[pred coll]
(let [rt (filter pred coll)]
(if (empty? rt)
nil
rt)))
(defn all-nodes []
(range 1 (inc *node-num*)))
(all-nodes)
(defn rand-node []
(inc (rand-int *node-num*)))
(defn edge-pair [x y]
(when-not (= x y)
[[x y] [y x]]))
(defn sample-2diff-nodes []
(let [[x y] [(rand-node) (rand-node)]]
(if (= x y)
(sample-2diff-nodes)
[x y])))
(edge-pair 1 1)
(take 4 (repeatedly #(sample-2diff-nodes)))
(def ^:dynamic t-edges (take 4 (repeatedly #(sample-2diff-nodes))))
(defn make-edge-vec []
(->> (repeatedly #(sample-2diff-nodes))
(take *edge-num*)
(apply concat)
set
vec))
(binding [t-edges (take 4 (repeatedly #(sample-2diff-nodes)))])
(prn t-edges)
(binding [t-edges (make-edge-vec)])
(prn t-edges)
(binding [t-edges (apply concat t-edges)])
(prn t-edges)
(ns kaiyin.wumpus.game
(:require [kaiyin.wumpus.graphing :refer [dot-label]]))
(def city-nodes (atom nil))
(def city-edges (atom nil))
(def player-pos (ref nil))
(def visited-nodes (ref #{}))
(def player-status (atom :in-progress))
(def ^:dynamic *node-num* 8)
(def ^:dynamic *edge-num* 5)
(def ^:dynamic *worm-num* 3)
(def ^:dynamic *cop-odds* 4)
(defn filterb
[pred coll]
(let [rt (filter pred coll)]
(if (empty? rt)
nil
rt)))
(defn all-nodes []
(range 1 (inc *node-num*)))
(all-nodes)
(defn rand-node []
(inc (rand-int *node-num*)))
(defn edge-pair [x y]
(when-not (= x y)
[[x y] [y x]]))
(defn sample-2diff-nodes []
(let [[x y] [(rand-node) (rand-node)]]
(if (= x y)
(sample-2diff-nodes)
[x y])))
(edge-pair 1 1)
(take 4 (repeatedly #(sample-2diff-nodes)))
(def ^:dynamic t-edges (take 4 (repeatedly #(sample-2diff-nodes))))
(defn make-edge-vec []
(->> (repeatedly #(sample-2diff-nodes))
(take *edge-num*)
(apply concat)
set
vec))
(defn get-connected
[edge-list]
(set (mapcat identity edge-list)))
(binding [t-edges (take 4 (repeatedly #(sample-2diff-nodes)))]
(prn t-edges))
(binding [t-edges (make-edge-vec)]
(prn t-edges))
(binding [t-edges (apply concat t-edges)]
(prn t-edges))
(binding [t-edges (take 4 (repeatedly #(sample-2diff-nodes)))])
(prn t-edges)
(binding [t-edges (make-edge-vec)])
(prn t-edges)
(binding [t-edges (apply concat t-edges)])
(prn t-edges)
([6 1] [1 2] [5 2] [3 1])
([6 1] [1 2] [5 2] [3 1])
([6 1] [1 2] [5 2] [3 1])
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment