SHARE
TWEET

Untitled

a guest Jun 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #module imports
  2. import random
  3. from scipy.stats import rankdata
  4. from scipy import stats
  5. import numpy as np
  6. import pandas as pd
  7. import matplotlib.pyplot as plt
  8. from pandas import ExcelWriter
  9. #enter starting armies here
  10. a_army = 40
  11. d_army = 40
  12. #creating lists for array later
  13. attack_log = [a_army]
  14. def_log = [d_army]
  15. attack_dice_log = [0]
  16. def_dice_log = [0]
  17.  
  18. #creating a while statement to loop until one of the armies runs out
  19. while a_army >1 or d_army >0:
  20.    
  21.     #die roll
  22.     a_die_1 = random.randint(1,6)
  23.     a_die_2 = random.randint(1,6)
  24.     a_die_3 = random.randint(1,6)
  25.     d_die_1 = random.randint(1,6)
  26.     d_die_2 = random.randint(1,6)
  27.  
  28.     #combining all sets of dice  
  29.     full_a = [a_die_1, a_die_2, a_die_3]
  30.     full_a.sort(reverse=True)
  31.     mid_a = [a_die_1,a_die_2]
  32.     mid_a.sort(reverse=True)
  33.     min_a = [a_die_1]
  34.     full_d = [d_die_1, d_die_2]
  35.     full_d.sort(reverse=True)
  36.     min_d = [d_die_1]
  37.    
  38.     #attacker 3 and defender 2
  39.     if a_army > 3 and d_army >= 2:
  40.         if full_a[0]>full_d[0] and full_a[1]>full_d[1] :
  41.             d_army -= 2
  42.             attack_dice_log.append(full_a)
  43.             def_dice_log.append(full_d)
  44.             def_log.append(d_army)
  45.             attack_log.append(a_army)
  46.         elif full_a[0]<=full_d[0] and full_a[1]<=full_d[1]:
  47.             a_army -= 2
  48.             attack_dice_log.append(full_a)
  49.             def_dice_log.append(full_d)
  50.             def_log.append(d_army)
  51.             attack_log.append(a_army)
  52.         elif full_a[0]>full_d[0] and full_a[1]<=full_d[1]:
  53.             a_army -= 1
  54.             d_army -= 1
  55.             attack_dice_log.append(full_a)
  56.             def_dice_log.append(full_d)
  57.             def_log.append(d_army)
  58.             attack_log.append(a_army)
  59.         elif full_a[0]<=full_d[0] and full_a[1]>full_d[1]:
  60.             a_army -= 1
  61.             d_army -= 1
  62.             attack_dice_log.append(full_a)
  63.             def_dice_log.append(full_d)
  64.             def_log.append(d_army)
  65.             attack_log.append(a_army)
  66.  
  67.     #attacker 2 and defender 2
  68.     elif 2<a_army<4 and d_army >= 2:
  69.         if mid_a[0]>full_d[0] and mid_a[1]>full_d[1] :
  70.             d_army -= 2
  71.             attack_dice_log.append(mid_a)
  72.             def_dice_log.append(full_d)
  73.             def_log.append(d_army)
  74.             attack_log.append(a_army)
  75.         elif mid_a[0]<=full_d[0] and mid_a[1]<=full_d[1]:
  76.             a_army -= 2
  77.             attack_dice_log.append(mid_a)
  78.             def_dice_log.append(full_d)
  79.             def_log.append(d_army)
  80.             attack_log.append(a_army)
  81.         elif mid_a[0]>full_d[0] and mid_a[1]<=full_d[1]:
  82.             a_army -= 1
  83.             d_army -= 1
  84.             attack_dice_log.append(mid_a)
  85.             def_dice_log.append(full_d)
  86.             def_log.append(d_army)
  87.             attack_log.append(a_army)
  88.         elif mid_a[0]<=full_d[0] and mid_a[1]>full_d[1]:
  89.             a_army -= 1
  90.             d_army -= 1
  91.             attack_dice_log.append(mid_a)
  92.             def_dice_log.append(full_d)
  93.             def_log.append(d_army)
  94.             attack_log.append(a_army)
  95.  
  96.     #attacker 1 and defender 2
  97.     elif 1<a_army<3 and d_army >= 2:
  98.         if min_a[0]>full_d[0]:
  99.             d_army -= 1
  100.             attack_dice_log.append(min_a)
  101.             def_dice_log.append(full_d)
  102.             def_log.append(d_army)
  103.             attack_log.append(a_army)
  104.         elif min_a[0]<=full_d[0]:
  105.             a_army -= 1
  106.             attack_dice_log.append(min_a)
  107.             def_dice_log.append(full_d)
  108.             def_log.append(d_army)
  109.             attack_log.append(a_army)
  110.  
  111.     #attacker 3 and defender 1
  112.     elif a_army > 3 and 0<d_army<2:
  113.         if full_a[0]>min_d[0]:
  114.             d_army -= 1
  115.             attack_dice_log.append(full_a)
  116.             def_dice_log.append(min_d)
  117.             def_log.append(d_army)
  118.             attack_log.append(a_army)
  119.         elif full_a[0]<=min_d[0]:
  120.             a_army -= 1
  121.             attack_dice_log.append(full_a)
  122.             def_dice_log.append(min_d)
  123.             def_log.append(d_army)
  124.             attack_log.append(a_army)  
  125.        
  126.     #attacker 2 and defender 1
  127.     elif 2<a_army<4 and 0<d_army<2:
  128.         if mid_a[0]>min_d[0]:
  129.             d_army -= 1
  130.             attack_dice_log.append(mid_a)
  131.             def_dice_log.append(min_d)
  132.             def_log.append(d_army)
  133.             attack_log.append(a_army)
  134.         elif mid_a[0]<=min_d[0]:
  135.             a_army -= 1
  136.             attack_dice_log.append(mid_a)
  137.             def_dice_log.append(min_d)
  138.             def_log.append(d_army)
  139.             attack_log.append(a_army)
  140.        
  141.     #attacker 1 and defender 1
  142.     elif 1<a_army<3 and 0<d_army<2:
  143.         if min_a[0]>min_d[0]:
  144.             d_army -= 1
  145.             attack_dice_log.append(min_a)
  146.             def_dice_log.append(min_d)
  147.             def_log.append(d_army)
  148.             attack_log.append(a_army)
  149.         elif min_a[0]<=min_d[0]:
  150.             a_army -= 1
  151.             attack_dice_log.append(min_a)
  152.             def_dice_log.append(min_d)
  153.             def_log.append(d_army)
  154.             attack_log.append(a_army)
  155.  
  156.     else:
  157.         break
  158.  
  159. #turning lists into arrays
  160. attack_log = np.array(attack_log)
  161. def_log = np.array(def_log)
  162. attack_dice_log = np.array(attack_dice_log)
  163. def_dice_log = np.array(def_dice_log)
  164. #making dataframes, combining all the arrays
  165. total_log = pd.DataFrame({ 'Attacking Army': attack_log, 'Defending Army': def_log, 'Attacking Dice': attack_dice_log, 'Defending Dice': def_dice_log})
  166. total_log.insert(0, 'Iterations',range(len(total_log)))
  167. total_log = total_log[['Iterations','Attacking Army', 'Defending Army', 'Attacking Dice', 'Defending Dice']]
  168. attack_def_log = pd.DataFrame({ 'Attacking Army': attack_log, 'Defending Army': def_log})
  169. #creating variables for regression analysis
  170. a = total_log['Iterations']
  171. b = total_log['Attacking Army']
  172. c = total_log['Defending Army']
  173. #showing main dataframe
  174. total_log
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top