forked from eriktaubeneck/hacker_risk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
81 lines (63 loc) · 2.16 KB
/
models.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import hashlib
import random
class Country(object):
def __init__(self, name):
self.border_countries = set()
self.name = name
self.owner = None
self.troops = 0
def attack(self, country, attacking_troops):
assert country in self.border_countries
assert country.owner is not None
assert country.owner is not self.country.owner
assert self.troops - attacking_troops >= 1
if country.troops >= 2:
defending_die = 2
elif country.troop == 1:
defending_die = 1
else:
raise NameError('defending country has no troops')
if attacking_troops >= 3:
attacking_die = 3
elif attacking_troops == 2:
attacking_die = 2
elif attacking_troops == 1:
attacking_die = 1
else:
raise NameError('attacking country has no troops')
defending_die = sorted([random.randint(1,6) for i in xrange(defending_die)])
attacking_die = sorted([random.randint(1,6) for i in xrange(attacking_die)])
def __hash__(self):
return hash(self.name)
def __eq__(self, other):
return isinstance(other, Country) and self.name == other.name
class Continent(object):
def __init__(self, name, bonus):
self.name = name
self.countries = set()
self.bonus = bonus
def __hash__(self):
return hash(self.name)
def __eq__(self,other):
return isinstance(other, Continent) and self.name == other.name
class Map(object):
def __init__(self):
self.continents = set()
self.countries = set()
def add_continent(self,continent):
self.continents.add(continent)
self.countries.union(continent.countries)
class Card(object):
def __init__(self):
pass
class Player(object):
def __init__(self, base_url):
self.base_url = base_url
self.key = hashlib.md5().hexdigest()
self.errors = 0
self.cards = set()
self.is_neutral = False
class World(object):
def __init__(self, _map, players):
self._map = map
self.players = random.shuffle(players)