Class: MinerMover::Miner
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#partial_reward ⇒ Object
Returns the value of attribute partial_reward.
Attributes inherited from Worker
Instance Method Summary collapse
-
#initialize(depth: 10, partial_reward: true, variance: 0, logging: false, timer: nil) ⇒ Miner
constructor
A new instance of Miner.
- #mine_ore(depth = @depth) ⇒ Object
- #state ⇒ Object
Methods inherited from Worker
Constructor Details
#initialize(depth: 10, partial_reward: true, variance: 0, logging: false, timer: nil) ⇒ Miner
Returns a new instance of Miner.
71 72 73 74 75 76 77 78 79 |
# File 'lib/miner_mover/worker.rb', line 71 def initialize(depth: 10, partial_reward: true, variance: 0, logging: false, timer: nil) @partial_reward = partial_reward @depth = depth super(variance: variance, logging: logging, timer: timer) end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
69 70 71 |
# File 'lib/miner_mover/worker.rb', line 69 def depth @depth end |
#partial_reward ⇒ Object
Returns the value of attribute partial_reward.
69 70 71 |
# File 'lib/miner_mover/worker.rb', line 69 def partial_reward @partial_reward end |
Instance Method Details
#mine_ore(depth = @depth) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/miner_mover/worker.rb', line 85 def mine_ore(depth = @depth) log format("MINE Depth %i", depth) ores, elapsed = CompSci::Timer.elapsed { # every new depth is a new mining operation Array.new(depth) { |d| # mine ore by calculating fibonacci for that depth mined = CompSci::Fibonacci.classic(self.varied(d).round) @partial_reward ? rand(1 + mined) : mined } } total = ores.sum log format("MIND %s %s (%.2f s)", Ore.display(total), ores.inspect, elapsed) total end |
#state ⇒ Object
81 82 83 |
# File 'lib/miner_mover/worker.rb', line 81 def state super.merge(depth: @depth, partial_reward: @partial_reward) end |