forked from swhetzel/risk_game_simulation
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patharmy.py
33 lines (26 loc) · 1.14 KB
/
army.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# class definition for army
# object oriented approach
# lpa2a@virginia.edu
import numpy as np
import logging
class Army():
def lose_division(self):
''' this function inflicts a casualty on an army'''
self.divisions -= 1
def roll(self):
''' this functions makes the rolls for an army, assumes the maximum number of dice are rolled, returns an array'''
# determine number to roll
if self.attacker:
if self.divisions >=4: n = 3
elif self.divisions >=3: n = 2
elif self.divisions >=2: n = 1
else: logging.critical("rolling attacker dice when battle is over")
else:
if self.divisions >=2: n=2
elif self.divisions >=1: n=1
else: logging.critical("rolling defender dice when battle is over")
return(np.random.randint(7,size=n))
def __init__(self,attacker=True,divisions=10):
''' initialization of army, sets attacker status and initial number of divisions'''
self.divisions = divisions # number of divisions in the army
self.attacker = attacker # True for attacker, False for defender