Class: FifthedSim::GreaterNode

Inherits:
DiceExpression show all
Defined in:
lib/fifthed_sim/nodes/greater_node.rb

Instance Method Summary collapse

Methods inherited from DiceExpression

#*, #+, #-, #/, #average, #difference_from_average, #or_greater, #or_least, #percentile, #range, #test_then, #to_dice_expression, #to_f, #to_i

Constructor Details

#initialize(lhs, rhs) ⇒ GreaterNode

Returns a new instance of GreaterNode.



7
8
9
# File 'lib/fifthed_sim/nodes/greater_node.rb', line 7

def initialize(lhs, rhs)
  @lhs, @rhs = lhs, rhs
end

Instance Method Details

#distributionObject



15
16
17
# File 'lib/fifthed_sim/nodes/greater_node.rb', line 15

def distribution
  @lhs.distribution.convolve_greater(@rhs.distribution)
end

#expression_equationObject



37
38
39
# File 'lib/fifthed_sim/nodes/greater_node.rb', line 37

def expression_equation
  "max(#{lhs.expression_equation}, #{rhs.expression_equation})"
end

#maxObject



27
28
29
# File 'lib/fifthed_sim/nodes/greater_node.rb', line 27

def max
  [@lhs.max, @rhs.max].max
end

#minObject



23
24
25
# File 'lib/fifthed_sim/nodes/greater_node.rb', line 23

def min
  [@lhs.min, @rhs.min].max
end

#rerollObject



19
20
21
# File 'lib/fifthed_sim/nodes/greater_node.rb', line 19

def reroll
  self.class.new(@lhs.reroll, @rhs.reroll)
end

#valueObject



11
12
13
# File 'lib/fifthed_sim/nodes/greater_node.rb', line 11

def value
  [@lhs.value, @rhs.value].max
end

#value_equation(terminal: false) ⇒ Object



31
32
33
34
35
# File 'lib/fifthed_sim/nodes/greater_node.rb', line 31

def value_equation(terminal: false)
  lhs = @lhs.value_equation(terminal: terminal)
  rhs = @rhs.value_equation(terminal: terminal)
  "max(#{lhs}, #{rhs}"
end