def to_result(self) -> DiceResult: dice = int(to_value(self._dice)) face = int(to_value(self._face)) highest = int(to_value( self._highest)) if self._highest is not None else None lowest = int(to_value( self._lowest)) if self._lowest is not None else None self._validate(dice, face, highest, lowest) dices = [self._generator(face) for _ in range(dice)] return DiceResult(dice, face, dices, highest=highest, lowest=lowest)
def _calc(self): self._validate() oper = self._operator res_a = self._a.to_result() res_b = self._b.to_result() if len(res_a) == len(res_b): value_a = to_value(res_a) value_b = to_value(res_b) return DiceletCalculationResult( res_a, oper, res_b, (to_value(ConstCalculation(i, oper, j)) for i, j in zip(value_a, value_b))) elif len(res_a) == 1: value_a = to_value(res_a)[0] value_b = to_value(res_b) return DiceletCalculationResult( res_a, oper, res_b, (to_value(ConstCalculation(value_a, oper, i)) for i in value_b)) elif len(res_b) == 1: value_a = to_value(res_a) value_b = to_value(res_b)[0] return DiceletCalculationResult( res_a, oper, res_b, (to_value(ConstCalculation(i, oper, value_b)) for i in value_a)) else: raise error.DiceletSizeMismatchError(len(res_a), len(res_b))
def to_result(self): if self._times < 1: raise error.EmptyDiceletError() if self._times > MAX_DICELET_SIZE: raise error.DiceletOverSizeError(self._times) return DiceletRepeatResult( str(self), [to_value(self._expr) for _ in range(self._times)])
def to_result(self) -> ConstResult: res_a = to_result(self._a) res_b = to_result(self._b) value_a = to_value(res_a) value_b = to_value(res_b) oper = self._operator if oper == '+': value = value_a + value_b elif oper == '-': value = value_a - value_b elif oper in ('*', 'x', 'X'): value = value_a * value_b elif oper == '/': value = value_a / value_b else: raise error.InvalidOperatorError return ConstCalculationResult(res_a, self._operator, res_b, value)
def __init__(self, args: Iterable[Union[Result, Number]], values: Iterable[Number] = None): self._items = list(args) if values: self._value = values else: self._value = self._flatten([to_value(i) for i in self._items])
def to_result(self) -> ConstResult: result = to_result(self._origin) value = -to_value(result) return ConstNegResult(result, value)
def __init__(self, times, expr): super().__init__() self._times = int(to_value(times)) self._expr = expr
def to_result(self): results = self._origin.to_result() values = [-value for value in to_value(results)] return DiceletNegResult(results, values)
def __init__(self, r: Result): super(ConstBracketResult, self).__init__(to_value(r)) self._origin = r