diff org/types.org @ 16:7698e9bdff2b

upgraded pokemon-types to clojure version 1.3
author Robert McIntyre <rlm@mit.edu>
date Mon, 06 Aug 2012 17:22:39 -0400
parents da4c47650d38
children 0f6ace87343a
line wrap: on
line diff
     1.1 --- a/org/types.org	Sun Feb 05 11:24:40 2012 -0700
     1.2 +++ b/org/types.org	Mon Aug 06 17:22:39 2012 -0400
     1.3 @@ -132,18 +132,19 @@
     1.4  table with its corresponding Pok\eacute{}mon type.
     1.5  
     1.6  
     1.7 -#+srcname: header
     1.8 +#+name: header
     1.9  #+begin_src clojure :results silent
    1.10  (ns pokemon.types
    1.11    (:use clojure.set)
    1.12 -  (:use clojure.contrib.combinatorics)
    1.13 -  (:use clojure.contrib.math)
    1.14 -  (:use clojure.contrib.def)
    1.15 +;;  (:use clojure.contrib.combinatorics)
    1.16 +  (:use clojure.math.combinatorics)
    1.17 +  (:use clojure.math.numeric-tower)
    1.18 +;;  (:use clojure.contrib.def)
    1.19    (:use rlm.rlm-commands)
    1.20    (:require rlm.map-utils))
    1.21  #+end_src
    1.22  
    1.23 -#+srcname: data 
    1.24 +#+name: data 
    1.25  #+begin_src clojure :results silent
    1.26  (in-ns 'pokemon.types)
    1.27  ;; record type strengths as a vector of vectors
    1.28 @@ -246,7 +247,7 @@
    1.29  is immune to Ground (susceptibility of 0). [[http://bulbapedia.bulbagarden.net/wiki/Zapdos][Zapdos']] type,
    1.30  Electric/Flying, is immune to Ground because $2 \times 0 = 0$.
    1.31  
    1.32 -#+srcname: types
    1.33 +#+name: types
    1.34  #+begin_src clojure :results silent
    1.35  (in-ns 'pokemon.types)
    1.36  
    1.37 @@ -316,7 +317,7 @@
    1.38  way of finding the best node, and to always expand the best node at
    1.39  every step.
    1.40  
    1.41 -#+srcname: search
    1.42 +#+name: search
    1.43  #+begin_src clojure :results silent
    1.44  (in-ns 'pokemon.types)
    1.45  
    1.46 @@ -336,7 +337,7 @@
    1.47         ;; LOWER values of the function are preferred
    1.48         (compare (- val-a val-b) 0)))))
    1.49  
    1.50 -(defn-memo best-first-step [successors [visited unvisited]]
    1.51 +(defn best-first-step [successors [visited unvisited]]
    1.52    (cond (empty? unvisited) nil
    1.53  	true
    1.54  	(let [best-node (first unvisited)
    1.55 @@ -347,6 +348,7 @@
    1.56  	       visited*)]
    1.57  	  (println best-node)
    1.58  	  [visited* unvisited*])))
    1.59 +(alter-var-root #'best-first-step memoize)
    1.60  
    1.61  ;; memoize partial from core so that for example 
    1.62  ;; (= (partial + 1) (partial + 1))
    1.63 @@ -378,11 +380,12 @@
    1.64  Now that we have a basic best-first-search, it's convenient to write a
    1.65  few pok\eacute{}mon-type specific convenience functions.
    1.66  
    1.67 -#+srcname: pokemon-search
    1.68 +#+name: pokemon-search
    1.69  #+begin_src clojure :results silent
    1.70  (in-ns 'pokemon.types)
    1.71 -(defvar type-compare (comparatize susceptance)
    1.72 -  "compare two type combinations W.R.T. their susceptibilities")
    1.73 +(def type-compare
    1.74 +  "compare two type combinations W.R.T. their susceptibilities"
    1.75 +  (comparatize susceptance))
    1.76  
    1.77  (defn type-successors
    1.78    "Return the set of types that can be made by appending a single type
    1.79 @@ -419,9 +422,9 @@
    1.80  	       (partial type-successors* n)
    1.81  	       (multitypes 1)))))))
    1.82  	 
    1.83 -(defvar immortals
    1.84 -  (comp (partial filter immortal?) pokemon-type-search)
    1.85 -  "find all the immortal pokemon types ")
    1.86 +(def immortals
    1.87 +  "find all the immortal pokemon types."
    1.88 +  (comp (partial filter immortal?) pokemon-type-search))
    1.89  
    1.90  #+end_src
    1.91  
    1.92 @@ -460,7 +463,7 @@
    1.93  doing anything too crazy with lazy-sequences and late-binding, this
    1.94  simple macro will do the job.
    1.95  
    1.96 -#+srcname: old-school
    1.97 +#+name: old-school
    1.98  #+begin_src clojure :results silent
    1.99  (in-ns 'pokemon.types)
   1.100  
   1.101 @@ -553,7 +556,7 @@
   1.102  Many people start out a battle with either a Normal pok\eacute{}mon or an
   1.103  Electric pok\eacute{}mon. Here's some justification for that choice.
   1.104  
   1.105 -#+srcname: weaknesses
   1.106 +#+name: weaknesses
   1.107  #+begin_src clojure  :results silent
   1.108  (in-ns 'pokemon.types)
   1.109  (defn critical-weaknesses [type]
   1.110 @@ -606,7 +609,7 @@
   1.111  
   1.112  ** The Worst Pok\eacute{}mon Types
   1.113  
   1.114 -#+srcname: weak-types
   1.115 +#+name: weak-types
   1.116  #+begin_src clojure :results silent
   1.117  (in-ns 'pokemon.types)
   1.118