@@ -47,6 +47,19 @@ def effective(e,t1,t2=None):#Attack Type, Defending Pokemon Type 1, Defending Po
47
47
effectiveness *= e [list_index2 ]
48
48
return effectiveness
49
49
na = None
50
+ def expected_value (pokea ,poked ,attack_name ):
51
+ if (attack_name .move_type in [ty .fire , ty .water , ty .grass , ty .electric , ty .psychic ]):
52
+ damage = (((14.285714285714286 * attack_name .power * (pokea .special / poked .special ))/ 50 )+ 2 )* 0.925
53
+ else :
54
+ damage = (((14.285714285714286 * attack_name .power * (pokea .attack / poked .defense ))/ 50 )+ 2 )* 0.925
55
+ try :
56
+ damage = damage * effective (attack_name .move_type ,poked .type1 ,poked .type2 )
57
+ except :
58
+ damage = damage * effective (attack_name .move_type ,poked .type1 )
59
+ if ((attack_name .move_type == pokea .type1 ) or (attack_name .move_type == pokea .type2 )):
60
+ damage = damage * 1.5
61
+ return (damage * (attack_name .accuracy / 100 ))
62
+
50
63
#LCG PRNG from Pokémon Gen-I
51
64
class LCG :
52
65
def __init__ (self , seed ):
@@ -74,7 +87,7 @@ def get_attack(poke):
74
87
#Code for a physical attack
75
88
def physical_attack (pokea ,poked ,attack_name ,active_attacker ):#Attacking Pokemon, Defending Pokemon, Attack
76
89
try :
77
- damage = (((14.285714285714286 * attack_name .power * (pokea .attack / poked .defense ))/ 50 )+ 2 )
90
+ damage = (((14.285714285714286 * attack_name .power * (pokea .attack / poked .defense ))/ 50 )+ 2 )* ( random . randint ( 85 , 100 ) / 100 )
78
91
try :
79
92
damage = damage * effective (attack_name .move_type ,poked .type1 ,poked .type2 )
80
93
except :
@@ -154,14 +167,27 @@ def attack(pokea,poked,attack_name,active_attacker):#Attacking Pokemon, Defendin
154
167
prnt ("But it missed" )
155
168
#Opponent Logic
156
169
def opponent_attack ():
157
- atk_select = random .randint (1 ,4 )
158
- if (atk_select == 1 ):
170
+ '''dmg = 0
171
+ if(expected_value(opponent,active,opponent.move1)>dmg):
172
+ opponent_attack = 1
173
+ dmg = expected_value(opponent,active,opponent.move1)
174
+ if(expected_value(opponent,active,opponent.move2)>dmg):
175
+ opponent_attack = 2
176
+ dmg = expected_value(opponent,active,opponent.move2)
177
+ if(expected_value(opponent,active,opponent.move3)>dmg):
178
+ opponent_attack = 3
179
+ dmg = expected_value(opponent,active,opponent.move3)
180
+ if(expected_value(opponent,active,opponent.move4)>dmg):
181
+ opponent_attack = 4
182
+ dmg = expected_value(opponent,active,opponent.move4)'''
183
+ opponent_attack = random .randint (1 ,4 )
184
+ if (opponent_attack == 1 ):
159
185
attack (opponent ,active ,opponent .move1 ,False )
160
- elif (atk_select == 2 ):
186
+ elif (opponent_attack == 2 ):
161
187
attack (opponent ,active ,opponent .move2 ,False )
162
- elif (atk_select == 3 ):
188
+ elif (opponent_attack == 3 ):
163
189
attack (opponent ,active ,opponent .move3 ,False )
164
- else :
190
+ elif ( opponent_attack == 4 ) :
165
191
attack (opponent ,active ,opponent .move4 ,False )
166
192
#Code to launch a battle, and the battle logic
167
193
def battle ():
0 commit comments