Advertisement
Menadh

Untitled

Feb 29th, 2024 (edited)
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.80 KB | None | 0 0
  1. import random
  2.  
  3. def roll_dice():
  4.     return [random.randint(1, 4) for _ in range(3)]
  5.  
  6. def update_units(units, stats_diff):
  7.     for unit in units:
  8.         for i in range(3):
  9.             unit[i+1] -= stats_diff[i]  # Adjusting stats, skipping the unit name at index 0
  10.  
  11. def calculate_total_points(units):
  12.     total_points = 0
  13.     for unit in units:
  14.         total_points += sum(unit[1:])  # Summing up stats, skipping the unit name at index 0
  15.     return total_points
  16.  
  17. def print_army(army_name, units):
  18.     print(army_name + ":")
  19.     for unit in units:
  20.         print(f"{unit[0]}, {unit[1]}/{unit[2]}/{unit[3]}")
  21.  
  22. def simulate_battle(army1, army2):
  23.     rolls_army1 = roll_dice()
  24.     rolls_army2 = roll_dice()
  25.  
  26.     print("Army 1 rolls:", rolls_army1)
  27.     print("Army 2 rolls:", rolls_army2)
  28.  
  29.     stats_diff_army1 = [0, 0, 0]
  30.     stats_diff_army2 = [0, 0, 0]
  31.  
  32.     # Update stats_diff for Army 1
  33.     for i in range(3):
  34.         if rolls_army1[i] < rolls_army2[i]:
  35.             stats_diff_army1[i] = rolls_army2[i] - rolls_army1[i]
  36.  
  37.     # Update stats_diff for Army 2
  38.     for i in range(3):
  39.         if rolls_army2[i] < rolls_army1[i]:
  40.             stats_diff_army2[i] = rolls_army1[i] - rolls_army2[i]
  41.  
  42.     update_units(army1, stats_diff_army1)  # Update Army 1 with differences for Army 2
  43.     update_units(army2, stats_diff_army2)  # Update Army 2 with differences for Army 1
  44.  
  45.     print("\nThe outcome is:\n")
  46.     print_army("Army 1", army1)
  47.     print_army("Army 2", army2)
  48.  
  49.     total_points_army1 = calculate_total_points(army1)
  50.     total_points_army2 = calculate_total_points(army2)
  51.  
  52.     print("\nArmy 1 lost", sum(stats_diff_army1), "points total.")
  53.     print("Army 2 lost", sum(stats_diff_army2), "points total.")
  54.  
  55.     if total_points_army1 > total_points_army2:
  56.         print("\nArmy 1 wins.")
  57.         coin_flip = random.choice(["Heads", "Tails"])
  58.         if coin_flip == "Heads":
  59.             captured_points = [stats_diff_army2[0], stats_diff_army2[2]]  # Capturing MP and MO points
  60.             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.")
  61.     elif total_points_army1 < total_points_army2:
  62.         print("\nArmy 2 wins.")
  63.         coin_flip = random.choice(["Heads", "Tails"])
  64.         if coin_flip == "Heads":
  65.             captured_points = [stats_diff_army1[0], stats_diff_army1[2]]  # Capturing MP and MO points
  66.             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.")
  67.     else:
  68.         print("\nThe battle is a stalemate.")
  69.  
  70. # Example armies
  71. army1 = [["CAV 1", 8, 8, 8], ["CAV 2", 8, 8, 8]]
  72. army2 = [["INF 1", 6, 6, 6], ["INF 2", 6, 6, 6]]
  73.  
  74. simulate_battle(army1, army2)
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement