Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def roll_dice():
- return [random.randint(1, 4) for _ in range(3)]
- def update_units(units, stats_diff):
- for unit in units:
- for i in range(3):
- unit[i+1] -= stats_diff[i] # Adjusting stats, skipping the unit name at index 0
- def calculate_total_points(units):
- total_points = 0
- for unit in units:
- total_points += sum(unit[1:]) # Summing up stats, skipping the unit name at index 0
- return total_points
- def print_army(army_name, units):
- print(army_name + ":")
- for unit in units:
- print(f"{unit[0]}, {unit[1]}/{unit[2]}/{unit[3]}")
- def simulate_battle(army1, army2):
- rolls_army1 = roll_dice()
- rolls_army2 = roll_dice()
- print("Army 1 rolls:", rolls_army1)
- print("Army 2 rolls:", rolls_army2)
- stats_diff_army1 = [0, 0, 0]
- stats_diff_army2 = [0, 0, 0]
- # Update stats_diff for Army 1
- for i in range(3):
- if rolls_army1[i] < rolls_army2[i]:
- stats_diff_army1[i] = rolls_army2[i] - rolls_army1[i]
- # Update stats_diff for Army 2
- for i in range(3):
- if rolls_army2[i] < rolls_army1[i]:
- stats_diff_army2[i] = rolls_army1[i] - rolls_army2[i]
- update_units(army1, stats_diff_army1) # Update Army 1 with differences for Army 2
- update_units(army2, stats_diff_army2) # Update Army 2 with differences for Army 1
- print("\nThe outcome is:\n")
- print_army("Army 1", army1)
- print_army("Army 2", army2)
- total_points_army1 = calculate_total_points(army1)
- total_points_army2 = calculate_total_points(army2)
- print("\nArmy 1 lost", sum(stats_diff_army1), "points total.")
- print("Army 2 lost", sum(stats_diff_army2), "points total.")
- if total_points_army1 > total_points_army2:
- print("\nArmy 1 wins.")
- coin_flip = random.choice(["Heads", "Tails"])
- if coin_flip == "Heads":
- captured_points = [stats_diff_army2[0], stats_diff_army2[2]] # Capturing MP and MO points
- print("\nArmy 1 flips a coin. It comes up heads, and Army 1 captures the", captured_points[0], "MP points and", captured_points[1], "MO points Army 2 lost.")
- elif total_points_army1 < total_points_army2:
- print("\nArmy 2 wins.")
- coin_flip = random.choice(["Heads", "Tails"])
- if coin_flip == "Heads":
- captured_points = [stats_diff_army1[0], stats_diff_army1[2]] # Capturing MP and MO points
- print("\nArmy 2 flips a coin. It comes up heads, and Army 2 captures the", captured_points[0], "MP points and", captured_points[1], "MO points Army 1 lost.")
- else:
- print("\nThe battle is a stalemate.")
- # Example armies
- army1 = [["CAV 1", 8, 8, 8], ["CAV 2", 8, 8, 8]]
- army2 = [["INF 1", 6, 6, 6], ["INF 2", 6, 6, 6]]
- simulate_battle(army1, army2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement