Skip to content

Instantly share code, notes, and snippets.

@horstjens
Last active August 2, 2024 07:02
Show Gist options
  • Save horstjens/2ae879e97e03aaa3a83e96ca321276fb to your computer and use it in GitHub Desktop.
Save horstjens/2ae879e97e03aaa3a83e96ca321276fb to your computer and use it in GitHub Desktop.
freesimplegui_pokemongui
import FreeSimpleGUI as sg
import random
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
#import numpy as np
import matplotlib.pyplot as plt
# format mini language https://docs.python.org/3/library/string.html#formatspec
class Pokemon:
def __init__(self, name):
self.name = name
self.hp_full = 100
self.hp = 100
self.speed = 10
self.attack = 10
self.defense = 10
self.magic = 10
def display_stats(self):
# print(f"---- stats of {self.name} -----")
for k, v in self.__dict__.items():
if not k.startswith("__"):
pass
# print(f"{k:>18}:{v:>5}")
class Ignivor(Pokemon):
def __init__(self, name):
self.name = name
self.hp_full = 96
self.hp = 96
self.speed = 14
self.attack = 4
self.defense = 2
self.magic = 11
self.history = []
def fullheal(self):
self.hp = self.hp_full
self.history = [self.hp_full]
class Hydropy(Pokemon):
def __init__(self, name):
self.name = name
self.hp_full = 100
self.hp = 100
self.speed = 9
self.attack = 9
self.defense = 7
self.magic = 4
self.history = []
def fullheal(self):
self.hp = self.hp_full
self.history = [self.hp_full]
def fight(a, b, battleturn, verbose=False):
if verbose:
window["multi"].print(f"round:{battleturn} ========== {a.name} vs. {b.name} =========")
# ---- faster monster attacks first ----
speed_a = a.speed + roll("1D6")[0]
speed_b = b.speed + roll("1D6")[0]
if verbose:
window["multi"].print(" speed rolls:", speed_a," | ",speed_b)
window["multi"].print(" "+"➠ "*a.speed + "➟ "*(speed_a-a.speed))
window["multi"].print(" "+"➤ "*b.speed + "➢ "*(speed_b-b.speed))
if speed_a == speed_b:
speed_a += random.choice((1, -1))
if speed_a > speed_b:
#pass
if verbose:
window["multi"].print(a.name, "attacks first")
attack(a, b, verbose)
# counterstrike
if b.hp > 0:
if verbose:
window["multi"].print(b.name, "strikes back")
attack(b, a, verbose)
else:
if verbose:
window["multi"].print(b.name, "attacks first")
attack(b, a, verbose)
if a.hp > 0:
if verbose:
window["multi"].print(a.name, "strikes back")
attack(a, b, verbose)
if verbose:
window["multi"].print("------- end result: -------------")
window["multi"].print(f"{a.name}: {a.hp} hp left of {a.hp_full} ")#({a.hp/a.hp_full*100:.2f}%)
window["multi"].print("■ "*int(a.hp/a.hp_full*100))
window["multi"].print(f"{b.name}: {b.hp} hp left of {b.hp_full} ")#({b.hp/b.hp_full*100:.2f}%)
window["multi"].print("□ "*int(b.hp/b.hp_full*100))
# ---- update history ------
a.history.append(a.hp)
b.history.append(b.hp)
def attack(attacker, defender, verbose=False):
# physical or magic ?
diff_physic = attacker.attack - defender.defense
diff_magic = attacker.magic - defender.magic
if diff_physic == diff_magic:
diff_physic += random.choice((-1, 1))
if ((diff_physic > 0) and (diff_magic > 0)) or (
(diff_physic < 0) and (diff_magic < 0)):
if diff_physic > diff_magic:
physical_attack(attacker, defender, verbose)
else:
magical_attack(attacker, defender, verbose)
elif diff_physic > 0:
physical_attack(attacker, defender, verbose)
else:
magical_attack(attacker, defender, verbose)
# print("enter stats:")
def storastikP(a, b, verbose=False):
# main loop
battleturn = 1
while a.hp > 0 and b.hp > 0:
fight(a, b, battleturn, verbose)
battleturn += 1
if a.hp > 0:
return a.name
elif b.hp > 0:
return b.name
else:
return None
# print("to contiue please press enter")
# input()
def roll(dicestring="1d6"):
# guardians, checking if dicestring is valid
dicestring = dicestring.strip()
dicestring = dicestring.replace(" ", "")
if "d" not in dicestring.lower():
raise ValueError("neiter 'd' nor 'D' found in dicestring", dicestring)
if dicestring.lower().count("d") > 1:
raise ValueError("more than one 'd'(or 'D') found inside dicestring", dicestring)
dice, sides = dicestring.lower().split("d")
if not (dice.isnumeric() and sides.isnumeric()):
raise ValueError("non-numeric char (except 'd'/'D') found in dicestring", dicestring)
# null? neee
if (dice == "0") or (sides == "0"):
return (0, "0")
# xD1
if (sides == "1") and ("D" in dicestring):
dicestring = dicestring.replace("D", "d") # workes
# print (dicestring)
# repeat ?
if "d" in dicestring:
repeat = False
elif "D" in dicestring:
repeat = True
dice = int(dice)
sides = int(sides)
if dice > 1000000:
raise ValueError("numbervalue exceedes maximum numbervalue. maximum numbervalue=1000000")
# print("number of dice:", dice)
# print("number of sides per die:", sides)
resultstring = ""
result = 0
for i in range(dice):
x = random.randint(1, sides)
while repeat and (x == sides):
result += (x - 1)
resultstring += f"({x}-1)+"
x = random.randint(1, sides)
resultstring += f"{x}"
if i < dice - 1:
resultstring += "+"
result += x
resultstring += f"={result}"
return result, resultstring
def magical_attack(attacker, defender, verbose=False):
attack_value = attacker.magic + roll("2D6")[0]
defense_value = defender.magic + roll("2D6")[0]
if verbose:
window["multi"].print("magical attack:")
window["multi"].print(" "+"⚡"*attacker.magic + "⚝ "*(attack_value-attacker.magic))
window["multi"].print(" "+"⚼ "*defender.magic + "⚴ "*(defense_value-defender.magic))
window["multi"].print("magical attack:", "⚡"*attack_value, "\n vs."," "* defense_value)
if attack_value > defense_value:
damage = attack_value - defense_value
# print as % of full hp
if verbose:
window["multi"].print(f"damage: {damage} hp: ")#({damage/defender.hp_full*100:.2f} % of full hp)
defender.hp -= damage
if defender.hp <= 0:
pass
#window["multi"].print("defender dies!")
else:
defender.hp -= 1
if verbose:
window["multi"].print("defender takes damage out of pitty")
def physical_attack(attacker, defender, verbose=False):
attack_value = attacker.attack + roll("2D6")[0]
defense_value = defender.defense + roll("2D6")[0]
if verbose:
window["multi"].print("physical attack:")
window["multi"].print(" "+"⚔ "*attacker.attack + "⚒ "*(attack_value-attacker.attack))
window["multi"].print(" "+"🛡 "*defender.defense + "☐ "*(defense_value-defender.defense))
window["multi"].print("physical attack:", "⚔ "*attack_value, "\n vs.","🛡 "* defense_value)
if attack_value > defense_value:
damage = attack_value - defense_value
# print as % of full hp
if verbose:
window["multi"].print(f"damage: {damage} hp: ")#({damage/defender.hp_full*100:.2f} % of full hp)
defender.hp -= damage
if defender.hp <= 0:
pass
# print("defender dies!")
else:
defender.hp -= 1
if verbose:
window["multi"].print("defender takes damage out of pitty")
# --------- matplotlib helper functions -----
def BarplotSimple(igni_victories, hydro_victories, none_victories):
# matplotlib
#all = igni_victories + hydro_victories + none_victories
fig, ax = plt.subplots()
ax.bar(1, igni_victories, label="igni")
ax.bar(2, hydro_victories, label="hydro")
ax.bar(3, none_victories, label="None")
ax.legend()
ax.set_xticks([]) # empty array -> display nothing
ax.set_xlabel("winner")
#ax.("")
ax.set_ylabel("victories")
return fig
def PyplotSimple(igni_hp, hydro_hp):
# matplotlib drawing function
fig, ax = plt.subplots()
plt.plot(list(range(1,len(hydro_hp)+1)), hydro_hp, 'r--', label="hydro")
plt.plot(list(range(1,len(igni_hp) +1)), igni_hp, 'g--', label="igni")
# plt.plot(turn, igni_hp[turn], 'r--')
ax.legend()
ax.set_xlabel("battle round")
ax.set_ylabel("hitpoints")
#fig = plt.gcf() # get the figure to show
return fig
def draw_figure(canvas, figure):
if not hasattr(draw_figure, 'canvas_packed'):
draw_figure.canvas_packed = {}
figure_canvas_agg = FigureCanvasTkAgg(figure, canvas)
figure_canvas_agg.draw()
widget = figure_canvas_agg.get_tk_widget()
if widget not in draw_figure.canvas_packed:
draw_figure.canvas_packed[widget] = figure
widget.pack(side='top', fill='both', expand=1)
return figure_canvas_agg
def delete_figure_painted(figure_painted):
figure_painted.get_tk_widget().forget()
try:
draw_figure.canvas_packed.pop(figure_painted.get_tk_widget())
except Exception as e:
print(f'Error removing {figure_painted} from list', e)
plt.close('all')
# ------------------- end matplotlib helper functions -----
ignivor = Ignivor("igni")
hydropy = Hydropy("hydro")
siege = []
c_left = sg.Column(layout=[
[sg.Text("igni")],
[sg.Input(key="ignivor.hp_full", default_text=f"{ignivor.hp_full}", size=(10,1))],
[sg.Input(key='ignivor.hp', default_text=f"{ignivor.hp}", size=(10,1))],
[sg.Input(key='ignivor.attack', default_text=f"{ignivor.attack}", size=(10,1))],
[sg.Input(key='ignivor.defense', default_text=f"{ignivor.defense}", size=(10,1))],
[sg.Input(key='ignivor.magic', default_text=f"{ignivor.magic}", size=(10,1))],
[sg.Input(key='ignivor.speed', default_text=f"{ignivor.speed}", size=(10,1))],
],
)
c_mitte = sg.Column(layout=[
[sg.Push(), sg.Text("vs"), sg.Push(), ],
[sg.Push(), sg.Text("full HP"), sg.Push(), ],
[sg.Push(), sg.Text("curent HP"), sg.Push(), ],
[sg.Push(), sg.Text("attack value"), sg.Push(), ],
[sg.Push(), sg.Text("defense value"), sg.Push(), ],
[sg.Push(), sg.Text("magic value"), sg.Push(), ],
[sg.Push(), sg.Text("speed value"), sg.Push(), ],
]
)
c_rechts = sg.Column(layout=[
[sg.Push(), sg.Text("hydro")],
[sg.Push(), sg.Input(key="hydropy.hp_full", default_text=f"{hydropy.hp_full}", size=(10,1))],
[sg.Push(), sg.Input(key='hydropy.hp', default_text=f"{hydropy.hp}", size=(10,1))],
[sg.Push(), sg.Input(key='hydropy.attack', default_text=f"{hydropy.attack}", size=(10,1))],
[sg.Push(), sg.Input(key='hydropy.defense', default_text=f"{hydropy.defense}", size=(10,1))],
[sg.Push(), sg.Input(key='hydropy.magic', default_text=f"{hydropy.magic}", size=(10,1))],
[sg.Push(), sg.Input(key='hydropy.speed', default_text=f"{hydropy.speed}", size=(10,1))],
],
)
sg.theme('LightGreen')
#figure_w, figure_h = 40,20 # for matplotlib canvas
# Define the window's contents
layout = [[c_left, c_mitte, c_rechts,sg.Text(size=(70, 8), key='-OUTPUT-', font=("Nimbus Mono PS", 16))],
[sg.Multiline(autoscroll=True, size=(80, 24), key="multi", disabled=True, font=("Nimbos Mono PS", 10)),
sg.Canvas( #size=(figure_w, figure_h),
key='-CANVAS-')],
#[],
[sg.Button('OK', size=(31, 2)), sg.Button('Single', size=(31, 2)), sg.Button('Quit', size=(31, 2))]]
# Create the window
window = sg.Window('Pokemon fight system', layout, finalize=True)
figure_painted = None
# Display and interact with the Window using an Event Loop
while True:
event, values = window.read()
# See if user wants to quit or window was closed
if event == sg.WINDOW_CLOSED or event == 'Quit':
break
if event == "Single":
window["multi"].print("================= new battle ==========")
for attr_name in ("hp_full", "hp", "attack", "defense", "magic", "speed"):
ignivor.__setattr__(attr_name, int(values["ignivor." + attr_name]))
hydropy.__setattr__(attr_name, int(values["hydropy." + attr_name]))
ignivor.fullheal()
hydropy.fullheal()
result = storastikP(ignivor, hydropy,verbose=True)
window["-OUTPUT-"].update(f"sieger ist:{result}\nhp igni: {ignivor.history}\nhp hydro: {hydropy.history}")
#print(ignivor.history)
#print("wurm")
if figure_painted:
delete_figure_painted(figure_painted)
fig = PyplotSimple(ignivor.history, hydropy.history) # function call
figure_painted = draw_figure(window['-CANVAS-'].TKCanvas, fig) # draw the figure
# battle between 2 pokemons
#window["multi"].print(f'turn:{battleturn}==={hydropy.hp}=vs.={ignivor.hp}')
if event == "OK":
# ignivor.hp_full=int(values["ignivor.hp_full"])
for attr_name in ("hp_full", "hp", "attack", "defense", "magic", "speed"):
ignivor.__setattr__(attr_name, int(values["ignivor." + attr_name]))
hydropy.__setattr__(attr_name, int(values["hydropy." + attr_name]))
siege = []
window["multi"].print("calculating 1000 fights...")
for i in range(1000):
ignivor.fullheal()
hydropy.fullheal()
siege.append(storastikP(ignivor, hydropy, verbose=False))
gesamt = len(siege)
Pigni = siege.count("igni") / gesamt
Phydro = siege.count("hydro") / gesamt
Pnone = siege.count(None) / gesamt
window["-OUTPUT-"].update(
f'igni : {siege.count("igni"):>5} {"*" * int(Pigni * 50)} \nhydro: {siege.count("hydro"):>5} {"*" * int(Phydro * 50)} \nNone : {siege.count(None):>5} {"*" * int(Pnone * 50)}')
# print(" ", siege.count("igni"), " ", siege.count("hydro"), " ", siege.count(None))
# diagram
if figure_painted:
delete_figure_painted(figure_painted)
fig = BarplotSimple(siege.count("igni"), siege.count("hydro"), siege.count(None))
figure_painted = draw_figure(window['-CANVAS-'].TKCanvas, fig) # draw the figure
window.close()
import FreeSimpleGUI as sg
import random
# format mini language https://docs.python.org/3/library/string.html#formatspec
class Pokemon:
def __init__(self, name):
self.name = name
self.hp_full = 100
self.hp = 100
self.speed = 10
self.attack = 10
self.defense = 10
self.magic = 10
def display_stats(self):
# print(f"---- stats of {self.name} -----")
for k, v in self.__dict__.items():
if not k.startswith("__"):
pass
# print(f"{k:>18}:{v:>5}")
class Ignivor(Pokemon):
def __init__(self, name):
self.name = name
self.hp_full = 96
self.hp = 96
self.speed = 14
self.attack = 4
self.defense = 2
self.magic = 11
self.history = []
def fullheal(self):
self.hp = self.hp_full
self.history = [self.hp_full]
class Hydropy(Pokemon):
def __init__(self, name):
self.name = name
self.hp_full = 100
self.hp = 100
self.speed = 9
self.attack = 9
self.defense = 7
self.magic = 4
self.history = []
def fullheal(self):
self.hp = self.hp_full
self.history = [self.hp_full]
def fight(a, b, battleturn, verbose=False):
window["multi"].print(f"round:{battleturn} ========== {a.name} vs. {b.name} =========")
# ---- faster monster attacks first ----
speed_a = a.speed + roll("1D6")[0]
speed_b = b.speed + roll("1D6")[0]
if verbose:
window["multi"].print(" speed rolls:", speed_a," | ",speed_b)
window["multi"].print(" "+"➠ "*a.speed + "➟ "*(speed_a-a.speed))
window["multi"].print(" "+"➤ "*b.speed + "➢ "*(speed_b-b.speed))
if speed_a == speed_b:
speed_a += random.choice((1, -1))
if speed_a > speed_b:
#pass
if verbose:
window["multi"].print(a.name, "attacks first")
attack(a, b)
# counterstrike
if b.hp > 0:
if verbose:
window["multi"].print(b.name, "strikes back")
attack(b, a)
else:
if verbose:
window["multi"].print(b.name, "attacks first")
attack(b, a)
if a.hp > 0:
if verbose:
window["multi"].print(a.name, "strikes back")
attack(a, b)
if verbose:
window["multi"].print("------- end result: -------------")
window["multi"].print(f"{a.name}: {a.hp} hp left of {a.hp_full} ")#({a.hp/a.hp_full*100:.2f}%)
window["multi"].print("■ "*int(a.hp/a.hp_full*100))
window["multi"].print(f"{b.name}: {b.hp} hp left of {b.hp_full} ")#({b.hp/b.hp_full*100:.2f}%)
window["multi"].print("□ "*int(b.hp/b.hp_full*100))
# ---- update history ------
a.history.append(a.hp)
b.history.append(b.hp)
def attack(attacker, defender):
# physical or magic ?
diff_physic = attacker.attack - defender.defense
diff_magic = attacker.magic - defender.magic
if diff_physic == diff_magic:
diff_physic += random.choice((-1, 1))
if ((diff_physic > 0) and (diff_magic > 0)) or (
(diff_physic < 0) and (diff_magic < 0)):
if diff_physic > diff_magic:
physical_attack(attacker, defender)
else:
magical_attack(attacker, defender)
elif diff_physic > 0:
physical_attack(attacker, defender)
else:
magical_attack(attacker, defender)
# print("enter stats:")
def storastikP(a, b, verbose=False):
# main loop
battleturn = 1
while a.hp > 0 and b.hp > 0:
fight(a, b, battleturn, verbose)
battleturn += 1
if a.hp > 0:
return a.name
elif b.hp > 0:
return b.name
else:
return None
# print("to contiue please press enter")
# input()
def roll(dicestring="1d6"):
# guardians, checking if dicestring is valid
dicestring = dicestring.strip()
dicestring = dicestring.replace(" ", "")
if "d" not in dicestring.lower():
raise ValueError("neiter 'd' nor 'D' found in dicestring", dicestring)
if dicestring.lower().count("d") > 1:
raise ValueError("more than one 'd'(or 'D') found inside dicestring", dicestring)
dice, sides = dicestring.lower().split("d")
if not (dice.isnumeric() and sides.isnumeric()):
raise ValueError("non-numeric char (except 'd'/'D') found in dicestring", dicestring)
# null? neee
if (dice == "0") or (sides == "0"):
return (0, "0")
# xD1
if (sides == "1") and ("D" in dicestring):
dicestring = dicestring.replace("D", "d") # workes
# print (dicestring)
# repeat ?
if "d" in dicestring:
repeat = False
elif "D" in dicestring:
repeat = True
dice = int(dice)
sides = int(sides)
if dice > 1000000:
raise ValueError("numbervalue exceedes maximum numbervalue. maximum numbervalue=1000000")
# print("number of dice:", dice)
# print("number of sides per die:", sides)
resultstring = ""
result = 0
for i in range(dice):
x = random.randint(1, sides)
while repeat and (x == sides):
result += (x - 1)
resultstring += f"({x}-1)+"
x = random.randint(1, sides)
resultstring += f"{x}"
if i < dice - 1:
resultstring += "+"
result += x
resultstring += f"={result}"
return result, resultstring
def magical_attack(attacker, defender):
attack_value = attacker.magic + roll("2D6")[0]
defense_value = defender.magic + roll("2D6")[0]
window["multi"].print("magical attack:")
window["multi"].print(" "+"⚡"*attacker.magic + "⚝ "*(attack_value-attacker.magic))
window["multi"].print(" "+"⚼ "*defender.magic + "⚴ "*(defense_value-defender.magic))
window["multi"].print("magical attack:", "⚡"*attack_value, "\n vs."," "* defense_value)
if attack_value > defense_value:
damage = attack_value - defense_value
# print as % of full hp
window["multi"].print(f"damage: {damage} hp: ")#({damage/defender.hp_full*100:.2f} % of full hp)
defender.hp -= damage
if defender.hp <= 0:
pass
window["multi"].print("defender dies!")
else:
defender.hp -= 1
window["multi"].print("defender takes damage out of pitty")
def physical_attack(attacker, defender):
attack_value = attacker.attack + roll("2D6")[0]
defense_value = defender.defense + roll("2D6")[0]
window["multi"].print("physical attack:")
window["multi"].print(" "+"⚔ "*attacker.attack + "⚒ "*(attack_value-attacker.attack))
window["multi"].print(" "+"🛡 "*defender.defense + "☐ "*(defense_value-defender.defense))
window["multi"].print("physical attack:", "⚔ "*attack_value, "\n vs.","🛡 "* defense_value)
if attack_value > defense_value:
damage = attack_value - defense_value
# print as % of full hp
window["multi"].print(f"damage: {damage} hp: ")#({damage/defender.hp_full*100:.2f} % of full hp)
defender.hp -= damage
if defender.hp <= 0:
pass
# print("defender dies!")
else:
defender.hp -= 1
window["multi"].print("defender takes damage out of pitty")
ignivor = Ignivor("igni")
hydropy = Hydropy("hydro")
siege = []
c_left = sg.Column(layout=[
[sg.Text("igni")],
[sg.Input(key="ignivor.hp_full", default_text=f"{ignivor.hp_full}", size=(10,1))],
[sg.Input(key='ignivor.hp', default_text=f"{ignivor.hp}", size=(10,1))],
[sg.Input(key='ignivor.attack', default_text=f"{ignivor.attack}", size=(10,1))],
[sg.Input(key='ignivor.defense', default_text=f"{ignivor.defense}", size=(10,1))],
[sg.Input(key='ignivor.magic', default_text=f"{ignivor.magic}", size=(10,1))],
[sg.Input(key='ignivor.speed', default_text=f"{ignivor.speed}", size=(10,1))],
],
)
c_mitte = sg.Column(layout=[
[sg.Push(), sg.Text("vs"), sg.Push(), ],
[sg.Push(), sg.Text("full HP"), sg.Push(), ],
[sg.Push(), sg.Text("curent HP"), sg.Push(), ],
[sg.Push(), sg.Text("attack value"), sg.Push(), ],
[sg.Push(), sg.Text("defense value"), sg.Push(), ],
[sg.Push(), sg.Text("magic value"), sg.Push(), ],
[sg.Push(), sg.Text("speed value"), sg.Push(), ],
]
)
c_rechts = sg.Column(layout=[
[sg.Push(), sg.Text("hydro")],
[sg.Push(), sg.Input(key="hydropy.hp_full", default_text=f"{hydropy.hp_full}", size=(10,1))],
[sg.Push(), sg.Input(key='hydropy.hp', default_text=f"{hydropy.hp}", size=(10,1))],
[sg.Push(), sg.Input(key='hydropy.attack', default_text=f"{hydropy.attack}", size=(10,1))],
[sg.Push(), sg.Input(key='hydropy.defense', default_text=f"{hydropy.defense}", size=(10,1))],
[sg.Push(), sg.Input(key='hydropy.magic', default_text=f"{hydropy.magic}", size=(10,1))],
[sg.Push(), sg.Input(key='hydropy.speed', default_text=f"{hydropy.speed}", size=(10,1))],
],
)
# Define the window's contents
layout = [[c_left, c_mitte, c_rechts,],
[sg.Multiline(autoscroll=True, size=(80, 20), key="multi", disabled=True, font=("Nimbos Mono PS", 10))],
[sg.Text(size=(80, 4), key='-OUTPUT-', font=("Nimbus Mono PS", 20))],
[sg.Button('OK', size=(31, 2)), sg.Button('Single', size=(31, 2)), sg.Button('Quit', size=(31, 2))]]
# Create the window
window = sg.Window('Pokemon fight system', layout)
# Display and interact with the Window using an Event Loop
while True:
event, values = window.read()
# See if user wants to quit or window was closed
if event == sg.WINDOW_CLOSED or event == 'Quit':
break
if event == "Single":
for attr_name in ("hp_full", "hp", "attack", "defense", "magic", "speed"):
ignivor.__setattr__(attr_name, int(values["ignivor." + attr_name]))
hydropy.__setattr__(attr_name, int(values["hydropy." + attr_name]))
ignivor.fullheal()
hydropy.fullheal()
result = storastikP(ignivor, hydropy)
window["-OUTPUT-"].update(f"sieger ist:{result}\n{ignivor.history}\n{hydropy.history}")
print(ignivor.history)
#print("wurm")
# battle between 2 pokemons
#window["multi"].print(f'turn:{battleturn}==={hydropy.hp}=vs.={ignivor.hp}')
if event == "OK":
# ignivor.hp_full=int(values["ignivor.hp_full"])
for attr_name in ("hp_full", "hp", "attack", "defense", "magic", "speed"):
ignivor.__setattr__(attr_name, int(values["ignivor." + attr_name]))
hydropy.__setattr__(attr_name, int(values["hydropy." + attr_name]))
siege = []
for i in range(1000):
ignivor.fullheal()
hydropy.fullheal()
siege.append(storastikP(ignivor, hydropy))
gesamt = len(siege)
Pigni = siege.count("igni") / gesamt
Phydro = siege.count("hydro") / gesamt
Pnone = siege.count(None) / gesamt
window["-OUTPUT-"].update(
f'igni : {siege.count("igni"):>5} {"*" * int(Pigni * 50)} \nhydro: {siege.count("hydro"):>5} {"*" * int(Phydro * 50)} \nNone : {siege.count(None):>5} {"*" * int(Pnone * 50)}')
# print(" ", siege.count("igni"), " ", siege.count("hydro"), " ", siege.count(None))
window.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment