Add a command line election simulator + other misc

Add a command line-based election simulator version and a command line-
based game.log validator, implement campaign decision loc from kuzunoha
and Lucy, and hopefully fix campaign decision bugs
This commit is contained in:
Uncountably Infinite
2020-06-28 19:49:22 -04:00
parent 5d55a5a9a1
commit 21a86b7e57
5 changed files with 1321 additions and 26 deletions
@@ -400,7 +400,8 @@ USA_politics_elections_category = {
original_tag = USA
OR = {
has_country_flag = USA_presidential_elections
has_country_flag = USA_senate_elections
has_country_flag = USA_senate_conclusion
has_country_flag = USA_presidential_conclusion
}
}
}
+21 -21
View File
@@ -890,50 +890,50 @@ USA_Fallen_Domino_tooltip:0 "§YWays to contact and influence§! the §GNorwegia
USA_politics_senate_election_category_desc:0 "It's Election Season again![ROOT.GetSenateElections]"
USA_view_results:0 "View Election Results"
USA_campaign_in_new_england:0 "Campaign in New England"
USA_campaign_in_new_england_desc:0 "Connecticut, Maine, Massachusetts, New Hampshire, Rhode Island, Vermont"
USA_campaign_in_new_england_desc:0 "Focus our campaign funds and volunteer staff in New England - from the forests of Acadia and Vermont to the coastal communities of Massachusetts and Rhode Island."
USA_campaign_in_east_coast:0 "Campaign in the Central East Coast"
USA_campaign_in_east_coast_desc:0 "Delaware, Maryland, Pennsylvania, New York, New Jersey, West Virginia"
USA_campaign_in_east_coast_desc:0 "Request that our campaign pay special attention to the Central East Coast - ranging from the metropolises and suburbs of New York, Philadelphia, and Baltimore, to the rural communities of Appalachia and West Virginia."
USA_campaign_in_south:0 "Campaign in the Deep South"
USA_campaign_in_south_desc:0 "Alabama, Arkansas, Florida, Georgia, Louisiana, Mississippi, South Carolina"
USA_campaign_in_south_desc:0 "Rally our campaign in the Deep South, across the deep bayou of Louisiana, the orchards of Georgia, and the coastal retreats of Florida."
USA_campaign_in_upper_south:0 "Campaign in the Upper South"
USA_campaign_in_upper_south_desc:0 "Kentucky, North Carolina, Tennessee, Virginia"
USA_campaign_in_upper_south_desc:0 "Our campaign will barnstorm the Upper South, from the suburbs of Virginia to the Tennessee Valley, bringing the word of our party and candidate to the people's doors."
USA_campaign_in_southwest:0 "Campaign in the Southwest"
USA_campaign_in_southwest_desc:0 "New Mexico, Texas, Oklahoma, Arizona"
USA_campaign_in_southwest_desc:0 "Spread our campaign gospel throughout the Southwest - the desert basins of Texas, to the mesas and canyons of Arizona and New Mexico."
USA_campaign_in_midwest:0 "Campaign in the Great Lakes"
USA_campaign_in_midwest_desc:0 "Illinois, Indiana, Michigan, Ohio, Wisconsin"
USA_campaign_in_midwest_desc:0 "Knock on doors throughout the Great Lakes states, whether they be the industrial heartlands of Detroit and Chicago to the dairy farms of Wisconsin."
USA_campaign_in_eastern_flyover_states:0 "Campaign in the Great Plains"
USA_campaign_in_eastern_flyover_states_desc:0 "Minnesota, Iowa, Kansas, Missouri, Nebraska, North Dakota, South Dakota"
USA_campaign_in_eastern_flyover_states_desc:0 "Hit the road across the Great Plains states, tasking our campaign staff to drive across the forests of Minnesota, the grasslands of the Dakotas, and through the scattered towns and cities of Iowa, Kansas, and Nebraska."
USA_campaign_in_western_flyover_states:0 "Campaign in the Rockies"
USA_campaign_in_western_flyover_states_desc:0 "Colorado, Montana, Utah, Wyoming, Idaho, Nevada"
USA_campaign_in_western_flyover_states_desc:0 "Have our campaign blaze a trail through the Rocky Mountain states, from the rugged interior of Montana and Idaho, the plateaus of Colorado, and the deserts of Nevada and Utah."
USA_campaign_in_west_coast:0 "Campaign in the West Coast"
USA_campaign_in_west_coast_desc:0 "California, Oregon, Washington, Alaska, Hawaii"
USA_campaign_in_west_coast_desc:0 "Expand the reach of our campaign to the West Coast, from the cities of San Francisco, Los Angeles, and Seattle, to the arid flatlands and sequoia woodlands of California, and the coastal woodlands of Oregon and Washington."
USA_campaign_in_new_england_senate:0 "Campaign in New England"
USA_campaign_in_new_england_senate_desc:0 "Connecticut, Maine, Massachusetts, New Hampshire, Rhode Island, Vermont"
USA_campaign_in_new_england_senate_desc:0 "Focus our campaign funds and volunteer staff in New England - from the forests of Acadia and Vermont to the coastal communities of Massachusetts and Rhode Island."
USA_campaign_in_east_coast_senate:0 "Campaign in the Central East Coast"
USA_campaign_in_east_coast_senate_desc:0 "Delaware, Maryland, Pennsylvania, New York, New Jersey, West Virginia"
USA_campaign_in_east_coast_senate_desc:0 "Request that our campaign pay special attention to the Central East Coast - ranging from the metropolises and suburbs of New York, Philadelphia, and Baltimore, to the rural communities of Appalachia and West Virginia."
USA_campaign_in_south_senate:0 "Campaign in the Deep South"
USA_campaign_in_south_senate_desc:0 "Alabama, Arkansas, Florida, Georgia, Louisiana, Mississippi, South Carolina"
USA_campaign_in_south_senate_desc:0 "Rally our campaign in the Deep South, across the deep bayou of Louisiana, the orchards of Georgia, and the coastal retreats of Florida."
USA_campaign_in_upper_south_senate:0 "Campaign in the Upper South"
USA_campaign_in_upper_south_senate_desc:0 "Kentucky, North Carolina, Tennessee, Virginia"
USA_campaign_in_upper_south_senate_desc:0 "Our campaign will barnstorm the Upper South, from the suburbs of Virginia to the Tennessee Valley, bringing the word of our party and candidate to the people's doors."
USA_campaign_in_southwest_senate:0 "Campaign in the Southwest"
USA_campaign_in_southwest_senate_desc:0 "New Mexico, Texas, Oklahoma, Arizona"
USA_campaign_in_southwest_senate_desc:0 "Spread our campaign gospel throughout the Southwest - the desert basins of Texas, to the mesas and canyons of Arizona and New Mexico."
USA_campaign_in_midwest_senate:0 "Campaign in the Great Lakes"
USA_campaign_in_midwest_senate_desc:0 "Illinois, Indiana, Michigan, Ohio, Wisconsin"
USA_campaign_in_midwest_senate_desc:0 "Knock on doors throughout the Great Lakes states, whether they be the industrial heartlands of Detroit and Chicago to the dairy farms of Wisconsin."
USA_campaign_in_eastern_flyover_states_senate:0 "Campaign in the Great Plains"
USA_campaign_in_eastern_flyover_states_senate_desc:0 "Minnesota, Iowa, Kansas, Missouri, Nebraska, North Dakota, South Dakota"
USA_campaign_in_eastern_flyover_states_senate_desc:0 "Hit the road across the Great Plains states, tasking our campaign staff to drive across the forests of Minnesota, the grasslands of the Dakotas, and through the scattered towns and cities of Iowa, Kansas, and Nebraska."
USA_campaign_in_western_flyover_states_senate:0 "Campaign in the Rockies"
USA_campaign_in_western_flyover_states_senate_desc:0 "Colorado, Montana, Utah, Wyoming, Idaho, Nevada"
USA_campaign_in_western_flyover_states_senate_desc:0 "Have our campaign blaze a trail through the Rocky Mountain states, from the rugged interior of Montana and Idaho, the plateaus of Colorado, and the deserts of Nevada and Utah."
USA_campaign_in_west_coast_senate:0 "Campaign in the West Coast"
USA_campaign_in_west_coast_senate_desc:0 "California, Oregon, Washington, Alaska, Hawaii"
USA_campaign_in_west_coast_senate_desc:0 "Expand the reach of our campaign to the West Coast, from the cities of San Francisco, Los Angeles, and Seattle, to the arid flatlands and sequoia woodlands of California, and the coastal woodlands of Oregon and Washington."
USA_senate_conclusion:0 "Elections for the Senate have concluded"
USA_presidential_conclusion:0 "Elections for the Presidency have concluded"
USA_campaign_opposition_senate:0 "The Opposition's Campaign"
USA_campaign_opposition_senate_desc:0 "The [GetOppositionCampaignParty] currently campaigning in [GetOppositionCampaignRegion]."
USA_campaign_opposition_senate_desc:0 "Throughout the campaign season, its vital that we also stay on top of our opponents strategy. After all, in American politics, their success is our failure. According to journalists, party insiders, and our people on the ground, the [GetOppositionCampaignParty] currently campaigning in [GetOppositionCampaignRegion]."
USA_campaign_opposition_president:0 "The Opposition's Campaign"
USA_campaign_opposition_president_desc:0 "The [GetOppositionCampaignParty] currently campaigning in [GetOppositionCampaignRegion]."
USA_campaign_opposition_president:0 "The Opposition's Campaign"
USA_campaign_opposition_president_desc:0 "Throughout the campaign season, its vital that we also stay on top of our opponents strategy. After all, in American politics, their success is our failure. According to journalists, party insiders, and our people on the ground, the [GetOppositionCampaignParty] currently campaigning in [GetOppositionCampaignRegion]."
USA_new_england_campaign_region:0 "New England"
USA_chesapeake_campaign_region:0 "the central East Coast"
@@ -0,0 +1,45 @@
import csv
import os
import sys
this_path = os.path.realpath(__file__)
last_backslash_ind = this_path.rfind("\\")
this_path_folder = this_path[:last_backslash_ind]
gamelog_file = "NONE"
output_dir = sys.argv[1]
def detect_errors():
is_fine = 0
gamelog_file_path = os.path.realpath(gamelog_file)
gamelog_file_path_folder = gamelog_file_path[:gamelog_file_path.rfind("\\")]
file = open(gamelog_file, "r", errors="ignore")
lines = file.readlines()
dates = move_data_and_make_dates(gamelog_file_path_folder)
for date in dates:
if dates[date] != 100 and dates[date] != 102:
print(f"Error detected at date {date[1:]}; has {dates[date]} instances")
is_fine = 1
return is_fine
def move_data_and_make_dates(path):
file = open(gamelog_file, "r", errors="ignore")
lines = file.readlines()
data_moved = open(path+"\data_moved.csv", "a", errors="ignore")
dates = {}
for line in lines:
if "THIS_IS_USEL_DATA" in line:
data_moved.write("\""+line[line.rfind("[effectbase.cpp:2243]:") + 44:])
with open(path+"\data_moved.csv", "r") as datafile2:
data = csv.reader(datafile2, delimiter=",")
for row in data:
if row[0] not in dates:
dates[row[0]] = 0
dates[row[0]] += 1
data_moved.close()
os.remove(path+"\data_moved.csv")
return dates
if __name__ == "__main__":
gamelog_file = output_dir + "/game.log"
is_fine = detect_errors()
exit(is_fine)
File diff suppressed because it is too large Load Diff
@@ -55,6 +55,8 @@ BONUS_POPULARITY_PRES_MULTIPLIER = 0.3
PRESIDENT_INCUMBENCY_BONUS_POPULARITY = 0.05
MAX_UNITY = 30
SAME_FACTION_UNITY = True
CLAMP_MIN = 0.001
CLAMP_MAX = 1000
data = []
statelist = ["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]
@@ -285,19 +287,19 @@ def extract_and_sort():
if date in line:
if "THIS_IS_USEL_DATA_3" in line:
quot = "\""
line2 = quot + line[87:]
line2 = quot + line[line.rfind("[effectbase.cpp:2243]:") + 44:]
data_combined.write(line2)
for line in lines:
if date in line:
if "THIS_IS_USEL_DATA_1" in line:
quot = "\""
line2 = quot + line[87:]
line2 = quot + line[line.rfind("[effectbase.cpp:2243]:") + 44:]
data_combined.write(line2)
for line in lines:
if date in line:
if "THIS_IS_USEL_DATA_2" in line:
quot = "\""
line2 = quot + line[87:]
line2 = quot + line[line.rfind("[effectbase.cpp:2243]:") + 44:]
data_combined.write(line2)
end_time = timeit.default_timer()
elapsed_time = round(1000*(end_time-start_time))
@@ -311,7 +313,7 @@ def move_data_and_make_dates(path):
dates = []
for line in lines:
if "THIS_IS_USEL_DATA" in line:
data_moved.write("\""+line[87:])
data_moved.write("\""+line[line.rfind("[effectbase.cpp:2243]:") + 44:])
with open(path+"\data_moved.csv", "r") as datafile2:
data = csv.reader(datafile2, delimiter=",")
for row in data:
@@ -330,6 +332,15 @@ def convert_csv_to_data_array(dataall_file):
def sim_election(RD,NPP,RD_R_bonus,RD_D_bonus,NPP_L_bonus,NPP_C_bonus,NPP_R_bonus,NPP_FR_bonus,RD_R_pie,RD_D_pie,NPP_L_pie,NPP_C_pie,NPP_R_pie,NPP_FR_pie,RD_cand,NPP_cand,RD_unity,NPP_unity,pres_party,senator1,senator2,print_flag):
result = StateResults()
RD = CLAMP_MIN if RD < CLAMP_MIN else CLAMP_MAX if RD > CLAMP_MAX else RD
NPP = CLAMP_MIN if NPP < CLAMP_MIN else CLAMP_MAX if NPP > CLAMP_MAX else NPP
RD_R_bonus = CLAMP_MIN if RD_R_bonus < CLAMP_MIN else CLAMP_MAX if RD_R_bonus > CLAMP_MAX else RD_R_bonus
RD_D_bonus = CLAMP_MIN if RD_D_bonus < CLAMP_MIN else CLAMP_MAX if RD_D_bonus > CLAMP_MAX else RD_D_bonus
NPP_L_bonus = CLAMP_MIN if NPP_L_bonus < CLAMP_MIN else CLAMP_MAX if NPP_L_bonus > CLAMP_MAX else NPP_L_bonus
NPP_C_bonus = CLAMP_MIN if NPP_C_bonus < CLAMP_MIN else CLAMP_MAX if NPP_C_bonus > CLAMP_MAX else NPP_C_bonus
NPP_R_bonus = CLAMP_MIN if NPP_R_bonus < CLAMP_MIN else CLAMP_MAX if NPP_R_bonus > CLAMP_MAX else NPP_R_bonus
NPP_FR_bonus = CLAMP_MIN if NPP_FR_bonus < CLAMP_MIN else CLAMP_MAX if NPP_FR_bonus > CLAMP_MAX else NPP_FR_bonus
total_pop = RD + NPP
RD_percent = RD / total_pop
NPP_percent = NPP / total_pop #step 1