-
-
Save kindlychung/d529b518cb1e87bd83a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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