Skip to content

Commit e789cac

Browse files
Add files via upload
1 parent aeb31f5 commit e789cac

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

POKéMON BATTLE.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ def effective(e,t1,t2=None):#Attack Type, Defending Pokemon Type 1, Defending Po
4747
effectiveness *= e[list_index2]
4848
return effectiveness
4949
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+
5063
#LCG PRNG from Pokémon Gen-I
5164
class LCG:
5265
def __init__(self, seed):
@@ -74,7 +87,7 @@ def get_attack(poke):
7487
#Code for a physical attack
7588
def physical_attack(pokea,poked,attack_name,active_attacker):#Attacking Pokemon, Defending Pokemon, Attack
7689
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)
7891
try:
7992
damage = damage * effective(attack_name.move_type,poked.type1,poked.type2)
8093
except:
@@ -154,14 +167,27 @@ def attack(pokea,poked,attack_name,active_attacker):#Attacking Pokemon, Defendin
154167
prnt("But it missed")
155168
#Opponent Logic
156169
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):
159185
attack(opponent,active,opponent.move1,False)
160-
elif(atk_select == 2):
186+
elif(opponent_attack==2):
161187
attack(opponent,active,opponent.move2,False)
162-
elif(atk_select == 3):
188+
elif(opponent_attack==3):
163189
attack(opponent,active,opponent.move3,False)
164-
else:
190+
elif(opponent_attack==4):
165191
attack(opponent,active,opponent.move4,False)
166192
#Code to launch a battle, and the battle logic
167193
def battle():

trainers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ def red():
3636
return([pkmn.venusaur(),pkmn.charizard(),pkmn.blastoise()])
3737
def professor_oak():
3838
return([pkmn.tauros(),pkmn.exeggutor(),pkmn.arcanine()])
39-
trainer_list = [brock(),misty(),lt_surge(),erika(),koga(),sabrina(),blaine(),giovanni(),lorelei(),bruno(),agatha(),lance(),blue(),red(),professor_oak()]
40-
trainer_names = ["Brock","Misty","Lt. Surge","Erika","Koga","Sabrina","Blaine","Giovanni","Lorelei","Bruno","Agatha","Lance","Blue","Red","Professor Oak"]
39+
def legendary_trio():
40+
return([pkmn.articuno(),pkmn.zapdos(),pkmn.moltres()])
41+
trainer_list = [brock(),misty(),lt_surge(),erika(),koga(),sabrina(),blaine(),giovanni(),lorelei(),bruno(),agatha(),lance(),blue(),red(),professor_oak(),legendary_trio()]
42+
trainer_names = ["Brock","Misty","Lt. Surge","Erika","Koga","Sabrina","Blaine","Giovanni","Lorelei","Bruno","Agatha","Lance","Blue","Red","Professor Oak","Legendary Trio"]

0 commit comments

Comments
 (0)