Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #module imports
- import random
- from scipy.stats import rankdata
- from scipy import stats
- import numpy as np
- import pandas as pd
- import matplotlib.pyplot as plt
- from pandas import ExcelWriter
- #enter starting armies here
- a_army = 40
- d_army = 40
- #creating lists for array later
- attack_log = [a_army]
- def_log = [d_army]
- attack_dice_log = [0]
- def_dice_log = [0]
- #creating a while statement to loop until one of the armies runs out
- while a_army >1 or d_army >0:
- #die roll
- a_die_1 = random.randint(1,6)
- a_die_2 = random.randint(1,6)
- a_die_3 = random.randint(1,6)
- d_die_1 = random.randint(1,6)
- d_die_2 = random.randint(1,6)
- #combining all sets of dice
- full_a = [a_die_1, a_die_2, a_die_3]
- full_a.sort(reverse=True)
- mid_a = [a_die_1,a_die_2]
- mid_a.sort(reverse=True)
- min_a = [a_die_1]
- full_d = [d_die_1, d_die_2]
- full_d.sort(reverse=True)
- min_d = [d_die_1]
- #attacker 3 and defender 2
- if a_army > 3 and d_army >= 2:
- if full_a[0]>full_d[0] and full_a[1]>full_d[1] :
- d_army -= 2
- attack_dice_log.append(full_a)
- def_dice_log.append(full_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- elif full_a[0]<=full_d[0] and full_a[1]<=full_d[1]:
- a_army -= 2
- attack_dice_log.append(full_a)
- def_dice_log.append(full_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- elif full_a[0]>full_d[0] and full_a[1]<=full_d[1]:
- a_army -= 1
- d_army -= 1
- attack_dice_log.append(full_a)
- def_dice_log.append(full_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- elif full_a[0]<=full_d[0] and full_a[1]>full_d[1]:
- a_army -= 1
- d_army -= 1
- attack_dice_log.append(full_a)
- def_dice_log.append(full_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- #attacker 2 and defender 2
- elif 2<a_army<4 and d_army >= 2:
- if mid_a[0]>full_d[0] and mid_a[1]>full_d[1] :
- d_army -= 2
- attack_dice_log.append(mid_a)
- def_dice_log.append(full_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- elif mid_a[0]<=full_d[0] and mid_a[1]<=full_d[1]:
- a_army -= 2
- attack_dice_log.append(mid_a)
- def_dice_log.append(full_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- elif mid_a[0]>full_d[0] and mid_a[1]<=full_d[1]:
- a_army -= 1
- d_army -= 1
- attack_dice_log.append(mid_a)
- def_dice_log.append(full_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- elif mid_a[0]<=full_d[0] and mid_a[1]>full_d[1]:
- a_army -= 1
- d_army -= 1
- attack_dice_log.append(mid_a)
- def_dice_log.append(full_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- #attacker 1 and defender 2
- elif 1<a_army<3 and d_army >= 2:
- if min_a[0]>full_d[0]:
- d_army -= 1
- attack_dice_log.append(min_a)
- def_dice_log.append(full_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- elif min_a[0]<=full_d[0]:
- a_army -= 1
- attack_dice_log.append(min_a)
- def_dice_log.append(full_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- #attacker 3 and defender 1
- elif a_army > 3 and 0<d_army<2:
- if full_a[0]>min_d[0]:
- d_army -= 1
- attack_dice_log.append(full_a)
- def_dice_log.append(min_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- elif full_a[0]<=min_d[0]:
- a_army -= 1
- attack_dice_log.append(full_a)
- def_dice_log.append(min_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- #attacker 2 and defender 1
- elif 2<a_army<4 and 0<d_army<2:
- if mid_a[0]>min_d[0]:
- d_army -= 1
- attack_dice_log.append(mid_a)
- def_dice_log.append(min_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- elif mid_a[0]<=min_d[0]:
- a_army -= 1
- attack_dice_log.append(mid_a)
- def_dice_log.append(min_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- #attacker 1 and defender 1
- elif 1<a_army<3 and 0<d_army<2:
- if min_a[0]>min_d[0]:
- d_army -= 1
- attack_dice_log.append(min_a)
- def_dice_log.append(min_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- elif min_a[0]<=min_d[0]:
- a_army -= 1
- attack_dice_log.append(min_a)
- def_dice_log.append(min_d)
- def_log.append(d_army)
- attack_log.append(a_army)
- else:
- break
- #turning lists into arrays
- attack_log = np.array(attack_log)
- def_log = np.array(def_log)
- attack_dice_log = np.array(attack_dice_log)
- def_dice_log = np.array(def_dice_log)
- #making dataframes, combining all the arrays
- total_log = pd.DataFrame({ 'Attacking Army': attack_log, 'Defending Army': def_log, 'Attacking Dice': attack_dice_log, 'Defending Dice': def_dice_log})
- total_log.insert(0, 'Iterations',range(len(total_log)))
- total_log = total_log[['Iterations','Attacking Army', 'Defending Army', 'Attacking Dice', 'Defending Dice']]
- attack_def_log = pd.DataFrame({ 'Attacking Army': attack_log, 'Defending Army': def_log})
- #creating variables for regression analysis
- a = total_log['Iterations']
- b = total_log['Attacking Army']
- c = total_log['Defending Army']
- #showing main dataframe
- total_log
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement