comparison orpg/dieroller/sr4.py @ 71:449a8900f9ac ornery-dev

Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author sirebral
date Thu, 20 Aug 2009 03:00:39 -0500
parents 4385a7d0efd1
children bf799efe7a8a
comparison
equal deleted inserted replaced
70:52a5fa913008 71:449a8900f9ac
66 66
67 MIN_TARGET_NUMBER = 5 67 MIN_TARGET_NUMBER = 5
68 GLITCH_NUMBER = 1 68 GLITCH_NUMBER = 1
69 69
70 class sr4(std): 70 class sr4(std):
71
71 def __init__(self,source=[]): 72 def __init__(self,source=[]):
72 std.__init__(self,source) 73 std.__init__(self,source)
73 self.threshold = None 74 self.threshold = None
74 self.init_attrib = None 75 self.init_attrib = None
75 76
77
76 def vs(self,threshold=0): 78 def vs(self,threshold=0):
77 return sr4vs(self, threshold) 79 return sr4vs(self, threshold)
78 80
81
79 def edge(self,threshold=0): 82 def edge(self,threshold=0):
80 return sr4vs(self, threshold, 1) 83 return sr4vs(self, threshold, 1)
81 84
85
82 def init(self,init_attrib=0): 86 def init(self,init_attrib=0):
83 return sr4init(self, init_attrib) 87 return sr4init(self, init_attrib)
84 88
89
85 def initedge(self,init_attrib=0): 90 def initedge(self,init_attrib=0):
86 return sr4init(self, init_attrib, 1) 91 return sr4init(self, init_attrib, 1)
92
87 def edgeinit(self,init_attrib=0): 93 def edgeinit(self,init_attrib=0):
88 return sr4init(self, init_attrib, 1) 94 return sr4init(self, init_attrib, 1)
89 95
96
90 def countEdge(self,num): 97 def countEdge(self,num):
91 if num <= 1: 98 if num <= 1:
92 self 99 self
93 done = 1 100 done = 1
94 for i in range(len(self.data)): 101 for i in range(len(self.data)):
104 if done: 111 if done:
105 return self 112 return self
106 else: 113 else:
107 return self.countEdge(num) 114 return self.countEdge(num)
108 115
116
109 def countHits(self,num): 117 def countHits(self,num):
110 for i in range(len(self.data)): 118 for i in range(len(self.data)):
111 if (self.data[i].lastroll() >= MIN_TARGET_NUMBER): 119 if (self.data[i].lastroll() >= MIN_TARGET_NUMBER):
112 # (Rule of Six taken into account in countEdge(), not here) 120 # (Rule of Six taken into account in countEdge(), not here)
113 self.hits += 1 121 self.hits += 1
114 elif (self.data[i].lastroll() <= GLITCH_NUMBER): 122 elif (self.data[i].lastroll() <= GLITCH_NUMBER):
115 self.ones += 1 123 self.ones += 1
116 self.total += 1 124 self.total += 1
117 125
126
118 def __str__(self): 127 def __str__(self):
119 if len(self.data) > 0: 128 if len(self.data) > 0:
120 self.hits = 0 129 self.hits = 0
121 self.ones = 0 130 self.ones = 0
122 self.total = 0 131 self.total = 0
143 else: 152 else:
144 myStr = "[] = (0)" 153 myStr = "[] = (0)"
145 return myStr 154 return myStr
146 155
147 class sr4init(sr4): 156 class sr4init(sr4):
157
148 def __init__(self,source=[],init_attrib=1,edge=0): 158 def __init__(self,source=[],init_attrib=1,edge=0):
149 std.__init__(self,source) 159 std.__init__(self,source)
150 if init_attrib < 2: 160 if init_attrib < 2:
151 self.init_attrib = 2 161 self.init_attrib = 2
152 else: 162 else:
157 self.total = 0 167 self.total = 0
158 if edge: 168 if edge:
159 self.countEdge(self.dicesides) 169 self.countEdge(self.dicesides)
160 self.countHits(self.dicesides) 170 self.countHits(self.dicesides)
161 171
172
162 def __str__(self): 173 def __str__(self):
163 if len(self.data) > 0: 174 if len(self.data) > 0:
164 firstpass = 0 175 firstpass = 0
165 myStr = "[" 176 myStr = "["
166 for a in self.data[0:]: 177 for a in self.data[0:]:
180 else: 191 else:
181 myStr = "[] = (0)" 192 myStr = "[] = (0)"
182 return myStr 193 return myStr
183 194
184 class sr4vs(sr4): 195 class sr4vs(sr4):
196
185 def __init__(self,source=[], threshold=1, edge=0): 197 def __init__(self,source=[], threshold=1, edge=0):
186 std.__init__(self, source) 198 std.__init__(self, source)
187 if threshold < 0: 199 if threshold < 0:
188 self.threshold = 0 200 self.threshold = 0
189 else: 201 else:
194 self.total = 0 206 self.total = 0
195 if edge: 207 if edge:
196 self.countEdge(self.dicesides) 208 self.countEdge(self.dicesides)
197 self.countHits(self.dicesides) 209 self.countHits(self.dicesides)
198 210
211
199 def __str__(self): 212 def __str__(self):
200 if len(self.data) > 0: 213 if len(self.data) > 0:
201 firstpass = 0 214 firstpass = 0
202 myStr = "[" 215 myStr = "["
203 for a in self.data[0:]: 216 for a in self.data[0:]:
220 myStr += "Hits: (" + str(self.hits) + ")" 233 myStr += "Hits: (" + str(self.hits) + ")"
221 else: 234 else:
222 myStr = "[] = (0)" 235 myStr = "[] = (0)"
223 return myStr 236 return myStr
224 237
238
225 def CheckIfGlitch(ones, hits, total_dice): 239 def CheckIfGlitch(ones, hits, total_dice):
226 if (ones * 2) >= total_dice: 240 if (ones * 2) >= total_dice:
227 if hits >= 1: 241 if hits >= 1:
228 return "*GLITCH* " 242 return "*GLITCH* "
229 else: 243 else: