-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pikesley
committed
Jan 26, 2018
1 parent
dba8e8e
commit 3bc13e5
Showing
26 changed files
with
643 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Hanoi | ||
module Jane | ||
class DropIn | ||
include Enumerable | ||
|
||
attr_accessor :height, :discs | ||
attr_reader :stacks, :disc, :animtype | ||
|
||
def initialize | ||
@height = 7 | ||
@discs = 3 | ||
@animtype = :tween | ||
yield self if block_given? | ||
|
||
@stacks = PaddedStacks.new [[], [], []], @height | ||
@disc = discs - 1 | ||
@dropper = Dropper.new @stacks[0], @disc, true | ||
end | ||
|
||
def value | ||
'0' * (@discs - @disc) | ||
end | ||
|
||
def each | ||
while @disc >= 0 | ||
@dropper = Dropper.new @stacks[0], @disc, (@disc == 0 ? false : true) | ||
@dropper.each do |state| | ||
@stacks[0] = state.to_a | ||
yield self | ||
end | ||
@disc -= 1 | ||
end | ||
end | ||
|
||
def to_dots | ||
Formatters::Matrix.new do |m| | ||
m.stacks = @stacks | ||
m.digits = '0' * (@discs - @disc) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Hanoi | ||
module Jane | ||
class Frame | ||
attr_reader :stacks, :animtype, :value | ||
|
||
def initialize stacks, value, type | ||
@stacks = stacks | ||
@value = value | ||
@animtype = type | ||
end | ||
|
||
def to_dots | ||
Formatters::Matrix.new do |m| | ||
m.stacks = @stacks | ||
m.digits = @value | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Hanoi | ||
module Jane | ||
class Smoosher < Array | ||
include Enumerable | ||
|
||
attr_accessor :direction | ||
attr_reader :animtype | ||
|
||
def initialize | ||
@direction = :close | ||
@step = 0.05 | ||
@animtype = :tween | ||
|
||
yield self if block_given? | ||
end | ||
|
||
def each | ||
@range = (0..1).step(0.05).to_a | ||
@range.reverse! if @direction == :open | ||
@range.each do |weight| | ||
populate weight | ||
yield self | ||
end | ||
end | ||
|
||
def populate weight | ||
7.times do |i| | ||
self[i] = Smoosher.row weight | ||
end | ||
end | ||
|
||
def to_dots | ||
self | ||
end | ||
|
||
def Smoosher.row weight = 0 | ||
a = [] | ||
45.times do | ||
a.push (weight > Random.rand) ? 1 : 0 | ||
end | ||
a | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Hanoi | ||
module Jane | ||
class HanoiException < Exception | ||
attr_reader :text | ||
|
||
def initialize text | ||
@text = text | ||
end | ||
end | ||
|
||
class SearchException < HanoiException | ||
attr_reader :text | ||
|
||
def initialize text | ||
@text = text | ||
end | ||
end | ||
|
||
class MatrixException < HanoiException | ||
attr_reader :text | ||
|
||
def initialize text | ||
@text = text | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.