changeset 169:4857f59f63a6

added functions to read and set DV values for pokemon.
author Robert McIntyre <rlm@mit.edu>
date Wed, 21 Mar 2012 01:37:10 -0500
parents 04dfda91db9c
children 09caf6a5bbf4
files clojure/com/aurellem/exp/pokemon-layout clojure/com/aurellem/exp/pokemon.clj save-states/at-pc-lv-100-pikachu.sav
diffstat 3 files changed, 199 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/exp/pokemon-layout	Tue Mar 20 20:26:00 2012 -0500
     1.2 +++ b/clojure/com/aurellem/exp/pokemon-layout	Wed Mar 21 01:37:10 2012 -0500
     1.3 @@ -33,8 +33,8 @@
     1.4  D182                   \l	  				    
     1.5  D183                   /h Special Stat Experience
     1.6  D184                   \l				    
     1.7 -D185                     				    
     1.8 -D186                    				    
     1.9 +D185                   Diversification -- Defense, Attack (HP)
    1.10 +D186                   Diversification -- Special, Speed (HP)  
    1.11  D187                   Current/Maximum PP Move 1		    
    1.12  D188                   Current/Maximum PP Move 2		    
    1.13  D189                   Current/Maximum PP Move 3		    
    1.14 @@ -77,8 +77,8 @@
    1.15  D1AE                   \l	 			      
    1.16  D1AF                   /h Special Stat Experience
    1.17  D1B0                   \l				      
    1.18 -D1B1                     				      
    1.19 -D1B2                    				      
    1.20 +D1B1                   Diversification -- Defense, Attack (HP)   
    1.21 +D1B2                   Diversification -- Special, Speed (HP)       
    1.22  D1B3                   Current/Maximum PP Move 1	      
    1.23  D1B4                   Current/Maximum PP Move 2	      
    1.24  D1B5                   Current/Maximum PP Move 3	      
    1.25 @@ -121,8 +121,8 @@
    1.26  D1DA                   \l	  				    
    1.27  D1DB                   /h Special Stat Experience
    1.28  D1DC                   \l				    
    1.29 -D1DD                     				    
    1.30 -D1DE                    				    
    1.31 +D1DD                   Diversification -- Defense, Attack (HP)	    
    1.32 +D1DE                   Diversification -- Special, Speed (HP)     
    1.33  D1DF                   Current/Maximum PP Move 1		    
    1.34  D1E0                   Current/Maximum PP Move 2		    
    1.35  D1E1                   Current/Maximum PP Move 3		    
    1.36 @@ -165,8 +165,8 @@
    1.37  D206                   \l	  				    
    1.38  D207                   /h Special Stat Experience
    1.39  D208                   \l				    
    1.40 -D209                     				    
    1.41 -D20A                    				    
    1.42 +D209                   Diversification -- Defense, Attack (HP)	    
    1.43 +D20A                   Diversification -- Special, Speed (HP)	    
    1.44  D20B                   Current/Maximum PP Move 1		    
    1.45  D20C                   Current/Maximum PP Move 2		    
    1.46  D20D                   Current/Maximum PP Move 3		    
    1.47 @@ -209,8 +209,8 @@
    1.48  D232                   \l	  				     
    1.49  D233                   /h Special Stat Experience
    1.50  D234                   \l				     
    1.51 -D235                     				     
    1.52 -D236                    				     
    1.53 +D235                   Diversification -- Defense, Attack (HP)     
    1.54 +D236                   Diversification -- Special, Speed (HP)    
    1.55  D237                   Current/Maximum PP Move 1		     
    1.56  D238                   Current/Maximum PP Move 2		     
    1.57  D239                   Current/Maximum PP Move 3		     
    1.58 @@ -253,8 +253,8 @@
    1.59  D25E                   \l	  				     
    1.60  D25F                   /h Special Stat Experience
    1.61  D260                   \l				     
    1.62 -D261                     				     
    1.63 -D262                    				     
    1.64 +D261                   Diversification -- Defense, Attack (HP)  
    1.65 +D262                   Diversification -- Special, Speed (HP)  
    1.66  D263                   Current/Maximum PP Move 1		     
    1.67  D264                   Current/Maximum PP Move 2		     
    1.68  D265                   Current/Maximum PP Move 3		     
     2.1 --- a/clojure/com/aurellem/exp/pokemon.clj	Tue Mar 20 20:26:00 2012 -0500
     2.2 +++ b/clojure/com/aurellem/exp/pokemon.clj	Wed Mar 21 01:37:10 2012 -0500
     2.3 @@ -657,6 +657,193 @@
     2.4  (defn pre-battle [] (read-state "prepare-for-battle"))
     2.5  
     2.6  
     2.7 +(defn pika-lvl-100-DV-0 []
     2.8 +  (read-state "at-pc-lv-100-pikachu"))
     2.9  
    2.10 +;; Performed following experiment:
    2.11 +;; Raised Pikachu to Lvl 100 with rare-candies,
    2.12 +;; then put it at the head of the party and
    2.13 +;; set 0xD185 and 0xD186 to zero.
    2.14  
    2.15 +;; then, for each pattern, deposited pikachu into
    2.16 +;; Box 1 and immediately widthdrew it and observed the
    2.17 +;; stats.
    2.18  
    2.19 +
    2.20 +;; Pikachu L:100 Base Stats with DVs = 0
    2.21 +;; HP      :  187
    2.22 +;; Attack  :  123
    2.23 +;; Defense :   73
    2.24 +;; Speed   :  194
    2.25 +;; Special :  112
    2.26 +
    2.27 +;; 0xD185:
    2.28 +
    2.29 +;; 00000001
    2.30 +;; Defense => 75  (+2)
    2.31 +;; HP => 195      (+8)
    2.32 +
    2.33 +;; 00000010
    2.34 +;; Defense => 77  (+4)
    2.35 +
    2.36 +;; 00000100
    2.37 +;; Defense => 81  (+8)
    2.38 +
    2.39 +;; 00001000
    2.40 +;; Defense => 89  (+16)
    2.41 +
    2.42 +;; 00010000
    2.43 +;; HP => 203      (+16)
    2.44 +;; Attack => 125  (+2)
    2.45 +
    2.46 +;; 00100000
    2.47 +;; Attack => 127  (+4)
    2.48 +
    2.49 +;; 01000000
    2.50 +;; Attack -> 131  (+8)
    2.51 +
    2.52 +;; 10000000
    2.53 +;; Attack -> 139  (+16)
    2.54 +
    2.55 +;; 0xD186
    2.56 +
    2.57 +;; 00000001
    2.58 +;; HP => 189      (+2)
    2.59 +;; Special =>     (+2)
    2.60 +
    2.61 +;; 00000010
    2.62 +;; Special => 116 (+4)
    2.63 +
    2.64 +;; 00000100
    2.65 +;; Special => 120 (+8)
    2.66 +
    2.67 +;; 00001000
    2.68 +;; Special => 128 (+16)
    2.69 +
    2.70 +;; 00010000
    2.71 +;; HP => 191      (+4)
    2.72 +;; Speed => 196   (+2)
    2.73 +
    2.74 +;; 00100000
    2.75 +;; Speed => 198   (+4)
    2.76 +
    2.77 +;; 01000000
    2.78 +;; Speed => 202   (+8)
    2.79 +
    2.80 +;; 10000000
    2.81 +;; Speed => 210   (+16)
    2.82 +
    2.83 +(def pokemon-1-DV-start 0xD185)
    2.84 +
    2.85 +(defn pokemon-DV-start-point [poke-num]
    2.86 +  (+ (* poke-num pokemon-record-width)
    2.87 +     pokemon-1-DV-start))
    2.88 +
    2.89 +(def reverse-4-bit
    2.90 +  {0   0
    2.91 +   1   8
    2.92 +   2   4
    2.93 +   3   12
    2.94 +   5   10
    2.95 +   6   6
    2.96 +   7   14
    2.97 +   9   9
    2.98 +   15  15
    2.99 +   13  11
   2.100 +
   2.101 +   8   1 
   2.102 +   4   2 
   2.103 +   12  3 
   2.104 +   10  5
   2.105 +   11  13
   2.106 +   14  7 })
   2.107 +   
   2.108 +(defn read-DV
   2.109 +  ([^SaveState state poke-num]
   2.110 +     (assert (<= 0 poke-num 5))
   2.111 +     (let [[raw-DV-1
   2.112 +            raw-DV-2]
   2.113 +           (subvec (vec (memory state))
   2.114 +                   (pokemon-DV-start-point poke-num)
   2.115 +                   (+ 2 (pokemon-DV-start-point poke-num)))
   2.116 +           defense-DV (bit-and raw-DV-1 0x0F)
   2.117 +           attack-DV (bit-shift-right
   2.118 +                       (bit-and raw-DV-1 0xF0)
   2.119 +                        4)
   2.120 +           special-DV (bit-and raw-DV-2 0x0F)
   2.121 +           speed-DV (bit-shift-right
   2.122 +                        (bit-and raw-DV-2 0xF0)
   2.123 +                        4)
   2.124 +           HP-DV
   2.125 +           (+
   2.126 +            (if (bit-test special-DV 0)   1 0)
   2.127 +            (if (bit-test speed-DV 0)     2 0)
   2.128 +            (if (bit-test defense-DV 0)   4 0)
   2.129 +            (if (bit-test attack-DV 0)    8 0))]
   2.130 +       {:attack  attack-DV
   2.131 +        :defense  defense-DV
   2.132 +        :speed  speed-DV
   2.133 +        :special  special-DV
   2.134 +        :hp  HP-DV}))
   2.135 +  ([poke-num]
   2.136 +     (read-DV @current-state poke-num)))
   2.137 +     
   2.138 +
   2.139 +(defn give-DV
   2.140 +  ([^SaveState state poke-num dv-values]
   2.141 +     
   2.142 +     (assert (<= 0 poke-num 5))
   2.143 +     (map #(assert (<= 0 % 15)) (vals dv-values))
   2.144 +     (let [raw-dv-1*
   2.145 +           (+ (:defense dv-values)
   2.146 +              (bit-shift-left (:attack dv-values) 4))
   2.147 +           raw-dv-2*
   2.148 +           (+ (:special dv-values)
   2.149 +              (bit-shift-left (:speed dv-values) 4))
   2.150 +           hp-dv (:hp dv-values)
   2.151 +           hp-masks-1
   2.152 +           [[0 (bit-test hp-dv 2)]
   2.153 +            [4 (bit-test hp-dv 3)]]
   2.154 +           hp-masks-2
   2.155 +           [[0 (bit-test hp-dv 0)]
   2.156 +            [4 (bit-test hp-dv 1)]]
   2.157 +           set-hp-bits
   2.158 +           (fn [init [index hp?]]
   2.159 +             (if hp?
   2.160 +               (bit-set init index)
   2.161 +               (bit-clear init index)))
   2.162 +
   2.163 +           raw-dv-1 (reduce set-hp-bits raw-dv-1*
   2.164 +                            hp-masks-1)
   2.165 +                     
   2.166 +           raw-dv-2 (reduce set-hp-bits raw-dv-2*
   2.167 +                            hp-masks-2)
   2.168 +           
   2.169 +           dv-start (pokemon-DV-start-point poke-num)]
   2.170 +
   2.171 +       (if (or (not= raw-dv-1* raw-dv-1)
   2.172 +               (not= raw-dv-2* raw-dv-2))
   2.173 +         (println "Warning: inconsistent DV-values."
   2.174 +                  "Using HP settings."))
   2.175 +       
   2.176 +       (set-memory 
   2.177 +        (set-memory state dv-start raw-dv-1)
   2.178 +        (inc dv-start) raw-dv-2)))
   2.179 +  ([poke-num dv-values]
   2.180 +     (give-DV @current-state poke-num dv-values)))
   2.181 +
   2.182 +(def good-DVs
   2.183 +  {:attack  15
   2.184 +   :defense 15
   2.185 +   :speed   15
   2.186 +   :special 15
   2.187 +   :hp      15})
   2.188 +
   2.189 +(def bad-DVs
   2.190 +  {:attack  0
   2.191 +   :defense 0
   2.192 +   :speed   0
   2.193 +   :special 0
   2.194 +   :hp      0})
   2.195 +
   2.196 +   
   2.197 \ No newline at end of file
     3.1 Binary file save-states/at-pc-lv-100-pikachu.sav has changed