comparison pytouhou/game/eclrunner.py @ 63:8527fe640844

Implement simple arithmetic instructions.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 24 Aug 2011 17:14:05 -0700
parents 1f591adcea04
children d469012368b3
comparison
equal deleted inserted replaced
62:1f591adcea04 63:8527fe640844
204 self._setval(variable_id, self._getval(value)) 204 self._setval(variable_id, self._getval(value))
205 205
206 206
207 @instruction(6) 207 @instruction(6)
208 def set_random_int(self, variable_id, maxval): 208 def set_random_int(self, variable_id, maxval):
209 """Set the specified variable to a random int in the [[0, maxval)) range. 209 """Set the specified variable to a random int in the [0, maxval) range.
210 """ 210 """
211 self._setval(variable_id, int(self._getval(maxval) * self._game_state.prng.rand_double())) 211 self._setval(variable_id, int(self._getval(maxval) * self._game_state.prng.rand_double()))
212 212
213 213
214 @instruction(8) 214 @instruction(8)
221 @instruction(9) 221 @instruction(9)
222 def set_random_float2(self, variable_id, minval, amp): 222 def set_random_float2(self, variable_id, minval, amp):
223 self._setval(variable_id, self._getval(minval) + self._getval(amp) * self._game_state.prng.rand_double()) 223 self._setval(variable_id, self._getval(minval) + self._getval(amp) * self._game_state.prng.rand_double())
224 224
225 225
226 @instruction(13)
227 def set_random_int2(self, variable_id, minval, amp):
228 self._setval(variable_id, int(self._getval(minval)) + int(self._getval(amp)) * self._game_state.prng.rand_double())
229
230
231 @instruction(14)
232 def substract_int(self, variable_id, a, b):
233 self._setval(variable_id, int(self._getval(a)) - int(self._getval(b)))
234
235
236 @instruction(15)
237 def multiply_int(self, variable_id, a, b):
238 self._setval(variable_id, int(self._getval(a)) * int(self._getval(b)))
239
240
241 @instruction(16)
242 def divide_int(self, variable_id, a, b):
243 self._setval(variable_id, int(self._getval(a)) / int(self._getval(b)))
244
245
246 @instruction(17)
247 def modulo(self, variable_id, a, b):
248 self._setval(variable_id, int(self._getval(a)) % int(self._getval(b)))
249
250
226 @instruction(20) 251 @instruction(20)
227 def add(self, variable_id, a, b): 252 def add_float(self, variable_id, a, b):
228 #TODO: int vs float thing 253 #TODO: int vs float thing
229 self._setval(variable_id, self._getval(a) + self._getval(b)) 254 self._setval(variable_id, self._getval(a) + self._getval(b))
230 255
231 256
232 @instruction(21) 257 @instruction(21)
233 def substract(self, variable_id, a, b): 258 def substract_float(self, variable_id, a, b):
234 #TODO: int vs float thing 259 #TODO: int vs float thing
235 self._setval(variable_id, self._getval(a) - self._getval(b)) 260 self._setval(variable_id, self._getval(a) - self._getval(b))
236 261
237 262
263 @instruction(23)
264 def divide_float(self, variable_id, a, b):
265 #TODO: int vs float thing
266 self._setval(variable_id, self._getval(a) / self._getval(b))
267
268
238 @instruction(27) 269 @instruction(27)
239 def compare_ints(self, a, b): 270 def compare_ints(self, a, b):
271 a, b = int(self._getval(a)), int(self._getval(b))
272 if a < b:
273 self.comparison_reg = -1
274 elif a == b:
275 self.comparison_reg = 0
276 else:
277 self.comparison_reg = 1
278
279
280 @instruction(28)
281 def compare_floats(self, a, b):
240 a, b = self._getval(a), self._getval(b) 282 a, b = self._getval(a), self._getval(b)
241 if a < b: 283 if a < b:
242 self.comparison_reg = -1 284 self.comparison_reg = -1
243 elif a == b: 285 elif a == b:
244 self.comparison_reg = 0 286 self.comparison_reg = 0