Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import matplotlib.ticker as ticker
- import numpy as np
- map_type = int(input("0 for general, 1 for across the rhine, 2 for sonnenblum, 3 for custom, 4 for no weighting: "))
- min_width = 6 # minimum width checked
- max_width = 50 # maximum width checked
- total_provinces = 2667
- """
- # IS COMBINED WITH JUNGLE
- forest_base = 84
- forest_increase = 42
- hills_base = 80
- hills_increase = 40
- marsh_base = 78
- marsh_increase = 26
- mountain_base = 75
- mountain_increase = 25
- # IS COMBINED WITH DESERT
- plains_base = 90
- plains_increase = 45
- urban_base = 96
- urban_increase = 32
- """
- forest_base = 76
- forest_increase = 40
- hills_base = 72
- hills_increase = 36
- jungle_base = 74 #new
- jungle_increase = 34 #new
- marsh_base = 68
- marsh_increase = 22
- mountain_base = 65
- mountain_increase = 25
- # IS COMBINED WITH DESERT
- plains_base = 82
- plains_increase = 49
- urban_base = 86
- urban_increase = 28
- # 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 for general scope, but that should not be necessary.
- # You may get wierd results if you have really large numbers tho (computer rounding errors).
- if map_type == 0: #General
- forest_weight = 527/total_provinces # 703 - jungle
- hills_weight = 401/total_provinces
- jungle_weight = 176/total_provinces # 1/4 of 703
- marsh_weight = 51/total_provinces
- mountain_weight = 297/total_provinces
- plains_weight = 1094/total_provinces
- urban_weight = 121/total_provinces
- elif map_type == 1: #Across the Rhine from Commanders in Conflict (CiC) - Speed5 Mod
- forest_weight = 46/125 # dividing is actually not necessary
- hills_weight = 18/125
- jungle_weight = 0
- marsh_weight = 2/125
- mountain_weight = 3/125
- plains_weight = 45/125
- urban_weight = 11/125
- elif map_type == 2: #Sonnenblum from Commanders in Conflict (CiC) - Speed5 Mod
- forest_weight = 0
- hills_weight = 27
- jungle_weight = 0
- marsh_weight = 0
- mountain_weight = 17
- plains_weight = 57
- urban_weight = 4
- elif map_type == 3: #Custom
- forest_weight = 1
- hills_weight = 0
- jungle_weight = 0
- marsh_weight = 0
- mountain_weight = 0
- plains_weight = 1
- urban_weight = 0
- elif map_type == 4: #No Weights
- forest_weight = 1
- hills_weight = 1
- jungle_weight = 1
- marsh_weight = 1
- mountain_weight = 1
- plains_weight = 1
- urban_weight = 1
- # Weights are from fabricensis, remember that forest & jungle and plains & desert are combined when changing the weights
- # These could probably be set up a lot smarter:
- terrain_weight_list = [forest_weight, hills_weight, jungle_weight, marsh_weight, mountain_weight, plains_weight, urban_weight]
- terrain_list = [forest_base, hills_base, jungle_base, marsh_base, mountain_base, plains_base, urban_base]
- terrain_increase_list = [forest_increase, hills_increase, jungle_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
- total_weight = 0
- 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
- # terrain weight variable
- current_terrain_weight = terrain_weight_list[terrain]
- if current_terrain_weight > 0:
- for flanking_directions in range(len(direction_weight_list)): # 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
- # 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
- #modifier_penalty += (current_width/battle_width) * ((-1.5*(current_width/battle_width)+2.5)**2) # attempting to replicate fabricensis's calculation
- elif current_width < battle_width:
- modifier_penalty += (battle_width-current_width)*0.01 #adds the unused width as modifier penalty
- # 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
- # actual calculation for adding the modifier for this cycle into the average
- # one is commented out because of their different methods of calculating the average
- # first method:
- #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
- # second method:
- # i currently prefer this method since its more straight forward than trying to add the average along the way
- # dont change unless you know what you are doing
- current_modifier += (1-modifier_penalty)*current_weight # adjusts the current modifier to add 1 - modifier penalties, will later divide by total to make average
- total_weight += current_weight
- return current_modifier/total_weight
- # 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)*100)
- ### Plot Customization
- fig, ax = plt.subplots()
- ax.plot(np.arange(6,51), y_markers)
- plt.rcParams['figure.dpi'] = 300
- # Grid types and colors
- ax.grid(color="black", which="major", linestyle="solid", linewidth = "1.1")
- ax.grid(color="slategray", which="minor", linestyle="solid", linewidth = "0.2")
- # Ticks
- ax.xaxis.set_major_locator(ticker.MultipleLocator(5))
- ax.xaxis.set_minor_locator(ticker.MultipleLocator(1))
- ax.yaxis.set_major_locator(ticker.MultipleLocator(5))
- ax.yaxis.set_minor_locator(ticker.MultipleLocator(1))
- # Limt
- ax.set_xlim(6, 50)
- ax.set_ylim(75, 100)
- plt.xlabel("Combat Width")
- plt.ylabel("Average Effectiveness")
- plt.gca().yaxis.set_major_formatter(ticker.FormatStrFormatter('%.2f %%'))
- plt.savefig('cw_plot.png')
- # Title
- if map_type != 4:
- plt.title("Width Modifier with Terrain Weights")
- else:
- plt.title("Width Modifier without Terrain Weights")
- plt.show()
- # Manual width checking
- print("Input combat width to check exact value. This will disappear after 3 uses.")
- for i in range(3):
- print(3-i, "use(s) left")
- test_width = float(input(""))
- print(round(width_modifier(test_width),5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement