Move opens into instructions/parentheses; implement :auto-close to set probability of adding a close from opens produced by instructions
This commit is contained in:
parent
5eb34a811a
commit
a10addcc9e
@ -2,7 +2,7 @@
|
||||
"The genetic material in Propeller. A `plushy` is a list of Push instructions that represent a Push program.
|
||||
They hold the genetic material for an `individual`. In the initial population, we create random plushys."
|
||||
{:doc/format :markdown}
|
||||
(:require [propeller.push.instructions :as instructions]
|
||||
(:require [propeller.push.instructions.parentheses :as parentheses]
|
||||
[propeller.utils :as utils]))
|
||||
|
||||
(defn make-random-plushy
|
||||
@ -21,7 +21,7 @@ They hold the genetic material for an `individual`. In the initial population, w
|
||||
[plushy argmap]
|
||||
(let [opener? #(and (vector? %) (= (first %) 'open))] ;; [open <n>] marks opens
|
||||
(loop [push () ;; iteratively build the Push program from the plushy
|
||||
plushy (mapcat #(let [n (get instructions/opens %)]
|
||||
plushy (mapcat #(let [n (get parentheses/opens %)]
|
||||
(if (and n
|
||||
(> n 0))
|
||||
[% ['open n]]
|
||||
|
33
src/propeller/push/instructions/parentheses.cljc
Normal file
33
src/propeller/push/instructions/parentheses.cljc
Normal file
@ -0,0 +1,33 @@
|
||||
(ns propeller.push.instructions.parentheses)
|
||||
|
||||
;; Number of blocks opened by instructions (default = 0)
|
||||
(def opens
|
||||
"Number of blocks opened by instructions. The default is 0."
|
||||
{:exec_dup 1
|
||||
:exec_dup_times 1
|
||||
:exec_dup_items 0 ; explicitly set to 0 to make it clear that this is intended
|
||||
:exec_eq 0 ; explicitly set to 0 to make it clear that this is intended
|
||||
:exec_pop 1
|
||||
:exec_rot 3
|
||||
:exec_shove 1
|
||||
:exec_swap 2
|
||||
:exec_yank 0 ; explicitly set to 0 to make it clear that this is intended
|
||||
:exec_yank_dup 0 ; explicitly set to 0 to make it clear that this is intended
|
||||
:exec_deep_dup 0 ; explicitly set to 0 to make it clear that this is intended
|
||||
:exec_print 1
|
||||
:exec_if 2
|
||||
:exec_when 1
|
||||
:exec_while 1
|
||||
:exec_do_while 1
|
||||
:exec_do_range 1
|
||||
:exec_do_count 1
|
||||
:exec_do_times 1
|
||||
:exec_k 2
|
||||
:exec_s 3
|
||||
:exec_y 1
|
||||
:string_iterate 1
|
||||
:vector_boolean_iterate 1
|
||||
:vector_string_iterate 1
|
||||
:vector_integer_iterate 1
|
||||
:vector_float_iterate 1
|
||||
})
|
@ -3,7 +3,8 @@
|
||||
(:require [clojure.zip :as zip]
|
||||
[clojure.repl :as repl]
|
||||
[propeller.tools.metrics :as metrics]
|
||||
[propeller.tools.math :as math]))
|
||||
[propeller.tools.math :as math]
|
||||
[propeller.push.instructions.parentheses :as parentheses]))
|
||||
|
||||
(defn filter-by-index
|
||||
"filters a collection by a list of indices"
|
||||
@ -50,11 +51,21 @@
|
||||
"Returns a random instruction from a supplied pool of instructions, evaluating
|
||||
ERC-producing functions to a constant literal."
|
||||
[instructions argmap]
|
||||
(let [instruction (rand-nth instructions)]
|
||||
(if (fn? instruction)
|
||||
(instruction)
|
||||
instruction)))
|
||||
|
||||
(if (:auto-close argmap)
|
||||
(let [instructions (remove #(= % 'close) instructions)
|
||||
p (/ (apply + (filter identity
|
||||
(map #(get parentheses/opens %) instructions)))
|
||||
(count instructions))]
|
||||
(if (< (rand) p)
|
||||
'close
|
||||
(let [instruction (rand-nth instructions)]
|
||||
(if (fn? instruction)
|
||||
(instruction)
|
||||
instruction))))
|
||||
(let [instruction (rand-nth instructions)]
|
||||
(if (fn? instruction)
|
||||
(instruction)
|
||||
instruction))))
|
||||
|
||||
(defn count-points
|
||||
"Returns the number of points in tree, where each atom and each pair of parentheses
|
||||
|
Loading…
x
Reference in New Issue
Block a user