comparison org/types.org @ 8:4f9ef752e2f0

more cleanup and better docstrings for clojure functions
author Robert McIntyre <rlm@mit.edu>
date Wed, 02 Nov 2011 07:01:49 -0700
parents d6b8dab05d9d
children fd38763de457
comparison
equal deleted inserted replaced
7:d6b8dab05d9d 8:4f9ef752e2f0
74 | dragon | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | .5 | 74 | dragon | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | .5 |
75 | dark | 1 | 1 | 1 | 1 | 1 | 1 | .5 | 1 | 1 | 1 | 2 | 1 | 1 | 2 | 1 | .5 | .5 | 75 | dark | 1 | 1 | 1 | 1 | 1 | 1 | .5 | 1 | 1 | 1 | 2 | 1 | 1 | 2 | 1 | .5 | .5 |
76 | steel | 1 | .5 | .5 | .5 | 1 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 1 | 1 | .5 | 76 | steel | 1 | .5 | .5 | .5 | 1 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 1 | 1 | .5 |
77 77
78 The rows are attack types, while the columns are defense types. To 78 The rows are attack types, while the columns are defense types. To
79 see the multiplier for a pokemon attack against a certain type, follow 79 see the multiplier for a pok\eacute{}mon attack against a certain type, follow
80 the row for the attack type to the column of the defending type. 80 the row for the attack type to the column of the defending type.
81 81
82 ** Generation I Type System 82 ** Generation I Type System
83 #+label: pokemon-matchups-gen-1 83 #+label: pokemon-matchups-gen-1
84 #+tblname: pokemon-table-gen-one 84 #+tblname: pokemon-table-gen-one
370 370
371 #+end_src 371 #+end_src
372 372
373 373
374 Now that we have a basic best-first-search, it's convenient to write a 374 Now that we have a basic best-first-search, it's convenient to write a
375 few pokemon-type specific convenience functions. 375 few pok\eacute{}mon-type specific convenience functions.
376 376
377 #+srcname: pokemon-search 377 #+srcname: pokemon-search
378 #+begin_src clojure :results silent 378 #+begin_src clojure :results silent
379 (in-ns 'pokemon.types) 379 (in-ns 'pokemon.types)
380 (defvar type-compare (comparatize susceptance) 380 (defvar type-compare (comparatize susceptance)
474 474
475 #+results[f43470fdf460ed546e9c57879abc9eda56da129f]: 475 #+results[f43470fdf460ed546e9c57879abc9eda56da129f]:
476 : [:ghost :psychic] 476 : [:ghost :psychic]
477 477
478 Ghost and Psychic also manages to have no weaknesses to any of the original 478 Ghost and Psychic also manages to have no weaknesses to any of the original
479 types. 479 types, using the old Generation I rules.
480 480
481 #+begin_src clojure :results output :exports both 481 #+begin_src clojure :results output :exports both
482 (clojure.pprint/pprint 482 (clojure.pprint/pprint
483 (pokemon.types/old-school 483 (pokemon.types/old-school
484 (pokemon.types/susceptibility [:ghost :psychic]))) 484 (pokemon.types/susceptibility [:ghost :psychic])))
543 :bug 1/16} 543 :bug 1/16}
544 #+end_example 544 #+end_example
545 545
546 ** Explanations for Common Pok\eacute{}mon Strategies 546 ** Explanations for Common Pok\eacute{}mon Strategies
547 547
548 Many people start out a battle with either a normal pok\eacute{}mon or an 548 Many people start out a battle with either a Normal pok\eacute{}mon or an
549 electric pok\eacute{}mon, and here's some justification for that choice. 549 Electric pok\eacute{}mon. Here's some justification for that choice.
550 550
551 #+srcname: weaknesses 551 #+srcname: weaknesses
552 #+begin_src clojure :results silent 552 #+begin_src clojure :results silent
553 (in-ns 'pokemon.types) 553 (in-ns 'pokemon.types)
554 (defn critical-weaknesses [type] 554 (defn critical-weaknesses [type]
617 "might as well get rid of types that are resistant to any type" 617 "might as well get rid of types that are resistant to any type"
618 [type] 618 [type]
619 (not (every? #(< 0 %) (vals (susceptibility type))))) 619 (not (every? #(< 0 %) (vals (susceptibility type)))))
620 620
621 (defn type-successors-weak 621 (defn type-successors-weak
622 "Generate ways to weaken the given type combination. Discard type
623 combinations that either strengthen the given type combination or
624 that make it stronger"
622 [limit type] 625 [limit type]
623 (set (if (<= limit (count type)) '() 626 (set (if (<= limit (count type)) '()
624 (filter #(< 0 (type-compare-weak type %)) 627 (filter #(< 0 (type-compare-weak type %))
625 (remove resistant? (type-successors type)))))) 628 (remove resistant? (type-successors type))))))
626 629
627 (defn pokemon-type-search-weak 630 (defn pokemon-type-search-weak
628 "Search among type-combos no greater than length n, limited by limit 631 "Search among type-combos no greater than length n, limited by limit
629 steps of best-first-search." 632 steps of best-first-search. Find the weakest type combination
633 possible in terms of susceptance."
630 ([n] (pokemon-type-search-weak n Integer/MAX_VALUE)) 634 ([n] (pokemon-type-search-weak n Integer/MAX_VALUE))
631 ([n limit] 635 ([n limit]
632 (first (last 636 (first (last
633 (take 637 (take
634 limit 638 limit