Oberyn: Have they told you who I am?
Gregor: Some dead man!
import random
# Define the gladiators
gladiator_1 = {
"name": "Gregor Clegane",
"hp": 150,
"damage": 30,
"speed": 5,
}
gladiator_2 = {
"name": "Oberyn Martell",
"hp": 80,
"damage": 10,
"speed": 8,
}
# Define the fight function
def fight(gladiator_1, gladiator_2):
# Print the initial status of the gladiators
print(f"{gladiator_1['name']} has {gladiator_1['hp']} HP and {gladiator_1['speed']} speed")
print(f"{gladiator_2['name']} has {gladiator_2['hp']} HP and {gladiator_2['speed']} speed")
print()
# Fight until one of the gladiators is dead
while gladiator_1["hp"] > 0 and gladiator_2["hp"] > 0:
# Determine the order of the attacks based on the speed of the gladiators
if gladiator_1["speed"] >= gladiator_2["speed"]:
attacker_1 = gladiator_1
attacker_2 = gladiator_2
else:
attacker_1 = gladiator_2
attacker_2 = gladiator_1
# Check for a random event at the beginning of each turn
random_event(attacker_1, gladiator_2)
random_event(attacker_2, gladiator_1)
# Gregor Clegane has a 10% chance to kill Oberyn in one hit
if attacker_2["name"] == "Gregor Clegane" and attacker_1["name"] == "Oberyn Martell" and random.randint(1, 10) == 5:
print(f"{attacker_2['name']} explodes {attacker_1['name']}'s skull in one hit!")
attacker_1["hp"] = 0
print("Ellaria Sand: AAAAAAAAAAAAAAAAAAAAAAH")
else:
# The attacker hits the defender
print(f"{attacker_1['name']} hits {attacker_2['name']}")
attacker_2["hp"] -= attacker_2["damage"]
# Print the current HP of the gladiators
print(f"{gladiator_1['name']} has {gladiator_1['hp']} HP")
print(f"{gladiator_2['name']} has {gladiator_2['hp']} HP")
# Print the winner of the fight
if gladiator_1["hp"] > 0:
print(f"{gladiator_1['name']} wins!")
else:
print(f"{gladiator_2['name']} wins!")
# Define the random_event function
def random_event(attacker_1, attacker_2):
# Generate a random number between 1 and 10
r = random.randint(1, 10)
# 10% chance of a missed attack
if r == 1:
print(f"{attacker_1['name']} missed the attack!")
# 20% chance of a critical hit
elif r <= 3:
print(f"{attacker_1['name']} landed a critical hit!")
gladiator_2["hp"] -= attacker_2["damage"] * 2
# Check if both gladiators have 0 or fewer hit points
if gladiator_1["hp"] <= 0 and gladiator_2["hp"] <= 0:
print("Oberyn and Gregor killed each other in an epic finish. The crowd goes wild!")
# Run the fight
fight(gladiator_1, gladiator_2)
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)