Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- terrain_weight_question = int(input("0 for no terrain weights, 1 for terrain weights: "))
- min_width = 6 # minimum width checked
- max_width = 50 # maximum width checked
- total_provinces = 2667
- # You can change the weights as you like. Currently they are based on fabricensis's document and are therefore written as a divison.
- # Right now they are set up to be a sum of 1, but that is not really necessary
- # IS COMBINED WITH JUNGLE
- forest_base = 84
- forest_increase = 42
- forest_weight = 703/total_provinces
- hills_base = 80
- hills_increase = 40
- hills_weight = 401/total_provinces
- marsh_base = 78
- marsh_increase = 26
- marsh_weight = 51/total_provinces
- mountain_base = 75
- mountain_increase = 25
- mountain_weight = 297/total_provinces
- # IS COMBINED WITH DESERT
- plains_base = 90
- plains_increase = 45
- plains_weight = 1094/total_provinces
- urban_base = 96
- urban_increase = 32
- urban_weight = 121/total_provinces
- # Weights are from fabricensis, remember that forest and jungle & plains and desert are combined when changing the weights
- # These could probably be set up a lot smarter:
- terrain_weight_list = [forest_weight, hills_weight, marsh_weight, mountain_weight, plains_weight, urban_weight]
- terrain_list = [forest_base, hills_base, marsh_base, mountain_base, plains_base, urban_base]
- terrain_increase_list = [forest_increase, hills_increase, marsh_increase, mountain_increase, plains_increase, urban_increase]
- # weights for the different directions. Not too difficult to add more.
- one_direction_weight = 1
- two_direction_weight = 2
- three_direction_weight = 1
- direction_weight_list = [one_direction_weight, two_direction_weight, three_direction_weight]
- # removing empty weights from the terrain list
- newlist = []
- for i in terrain_weight_list:
- if i != 0:
- newlist.append(i)
- terrain_weight_list = newlist
- def width_modifier(cw): #cw = combat width
- current_modifier = 0 # used for the modifier of the unit later
- test_number = 0 # number of the current test (basically n)
- for terrain in range(len(terrain_weight_list)): # cycles through every terrain
- # adds terrain weights if user said so
- if terrain_weight_question == 1:
- current_terrain_weight = terrain_weight_list[terrain]
- else:
- current_terrain_weight = 1
- for flanking_directions in range(3): # cycles through 1, 2 or 3 direction attack
- current_width = 0 # current width occupied by our troops in the battle
- battle_width = (terrain_list[terrain] + terrain_increase_list[terrain]*flanking_directions) #combat width of the battle
- divisions_used = 0 # number of divions in combat
- # creates weight variable as flanking direction weight
- current_weight = direction_weight_list[flanking_directions]
- # adds terrain weight to the variable
- current_weight *= current_terrain_weight
- # Calculates how many divisions to be used in the combat
- while current_width+cw < (battle_width*1.22) and not current_width > battle_width:
- current_width += cw
- divisions_used += 1
- # creates modifier penalty used in the final calculation to find modifier/effectiveness
- modifier_penalty = 0
- # calculates penalty for any overstacked divisions
- if divisions_used > (8 + 4*flanking_directions):
- overstacked_divisions = divisions_used-(8 + 4*flanking_directions)
- if overstacked_divisions * 0.02 < 0.99: # makes sure to only do the calculation while the total is under 99% (because that is the limit for stacking penalty)
- modifier_penalty = overstacked_divisions * 0.02 #add the overstacked divisons to the modifier penalty
- else: # set the overstacking penalty to 99% if the actual value is over
- modifier_penalty = 0.99
- # if it doesnt fit perfect, then calculate all penalties to the total modifier
- if battle_width % cw != 0:
- if current_width > battle_width: # checks for any overstacked combat width
- overstacked_width = current_width - battle_width
- modifier_penalty += overstacked_width * 0.015 #adds the overstacked width to the modifier penalty
- elif current_width < battle_width:
- modifier_penalty += (battle_width-current_width)*0.01 #adds the unused width as modifier penalty
- # actual calculation for adding the modifier for this cycle into the average
- current_modifier = (current_modifier*test_number + ((1-modifier_penalty)*current_weight)) / (test_number + current_weight) # adjusts the current modifier average to add 1 - modifier penalties
- test_number += 1
- return current_modifier
- # Runs through all widths between 6 and 50 and makes them into y values of a future plot
- y_markers = []
- for y in range(min_width, max_width+1):
- y_markers.append(width_modifier(y))
- # Plot Customization
- plt.grid(color="black", linestyle="solid")
- plt.xticks(np.arange(10, 46, 5))
- plt.xlim(6, 50)
- plt.ylim(0.775, 0.975)
- plt.xlabel("Combat Width")
- plt.ylabel("Average Modifier/Effectiveness")
- if terrain_weight_question == 1:
- plt.title("Width Modifier w/ Terrain Weights")
- else:
- plt.title("Width Modifier w/out Terrain Weights")
- # Creates and shows plot
- plt.plot(np.arange(6,51), y_markers)
- plt.show()
- # Manual width checking
- for i in range(3):
- print("Input combat width to check exact value. This will disappear after 3 uses.", 3-i, "uses left")
- test_width = int(input(""))
- print(width_modifier(test_width))
Add Comment
Please, Sign In to add comment