hanoi-jane 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd9aa356041dfeb5a0218b3354681ff31572aa331a30703dfac0d4b3ded69baf
4
- data.tar.gz: c27d5aeb46f5ffb14189fcd2db0523ba902a76e35a632063bbb7d6828fda9a15
3
+ metadata.gz: 7e8e76483ae7cdff90a6841f72db34b531a72823c05386db729ab274f46f84c0
4
+ data.tar.gz: 35e0a4f597635d306cb1faec30c08ff2bdb815ec26a7ad04aa3e5ea4fe694f08
5
5
  SHA512:
6
- metadata.gz: 62f7b5ab946ea21be7e958c317117d948cb236585fdcfb0767514bdf60be763ce8f9ac9695328a9bc0c6e0288291b9f818fedef5fe779ae88c1cc36cc90cb41b
7
- data.tar.gz: 76fa2a19ac7428e4ef60b0f2c952e239884359bae68cb5ede79e92e78bdc8783293e9ca26babb3e08faf8c159aae240385d6df373d5809890f6b0175c7ac5319
6
+ metadata.gz: 5c67826d8fa1db349db50d6d7ba5dae429150c007b9a5dd6ec13f5b97d0a911c3ac07475a78763ba674deba71200a538956cd62055daf998ec7135fa3b15765b
7
+ data.tar.gz: bc8431c6b6fed782885a88e19a6e9f7b70f45a1e0aab6bebf3cd1d70acb4f90436b0b0d5c2c21f78bc5c1341e42601d5dfc8866a1ce8ae2bac1e1ef711224369
data/Gemfile CHANGED
@@ -1,4 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ git_source :github do |repo_name|
4
+ "https://github.com/#{repo_name}"
5
+ end
6
+
3
7
  # Specify your gem's dependencies in hanoi-jane.gemspec
4
8
  gemspec
9
+
10
+ gem 'wiper', github: 'pikesley/wiper'
11
+ gem 'gitpaint', github: 'pikesley/gitpaint'
data/README.md CHANGED
@@ -66,3 +66,7 @@ In order to over-engineer this, I've wrapped a [very thin Flask app](https://git
66
66
  to watch this all [play out on the pHAT](https://www.youtube.com/watch?v=LT3HNsVxhM8):
67
67
 
68
68
  [![Screenshot](https://i.imgur.com/yrK3isK.png)](https://www.youtube.com/watch?v=LT3HNsVxhM8)
69
+
70
+ ## Gitpaint
71
+
72
+ Who hasn't, at some time in their life, wanted to play Towers of Hanoi on the Github commit-history graph? I've now built a formatter to generate output suitable for this - see (hanoi-painter)[https://github.com/pikesley/hanoi-painter] for more on how it all works
@@ -30,4 +30,6 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_dependency 'thor', '~> 0.19'
32
32
  spec.add_dependency 'httparty', '~> 0.15'
33
+ spec.add_dependency 'wiper'
34
+ spec.add_dependency 'gitpaint'
33
35
  end
@@ -3,6 +3,8 @@ require 'yaml'
3
3
 
4
4
  require 'thor'
5
5
  require 'httparty'
6
+ require 'wiper'
7
+ require 'gitpaint'
6
8
 
7
9
  require 'hanoi/jane/version'
8
10
 
@@ -23,9 +25,14 @@ require 'hanoi/jane/animation/smoosher'
23
25
 
24
26
  require 'hanoi/jane/formatters/matrix'
25
27
  require 'hanoi/jane/formatters/console'
28
+ require 'hanoi/jane/formatters/github'
26
29
 
27
30
  module Hanoi
28
31
  module Jane
32
+ def self.render_to_github towers
33
+ g = Formatters::Github.new towers
34
+ end
35
+
29
36
  def self.render_to_phat source, interval, phat
30
37
  source.each do |frame|
31
38
  Hanoi::Jane.hit_phat frame.to_dots, phat
@@ -71,5 +78,9 @@ module Hanoi
71
78
  end
72
79
  1
73
80
  end
81
+
82
+ def self.scale size
83
+ (size * 2) + 1
84
+ end
74
85
  end
75
86
  end
@@ -16,10 +16,15 @@ module Hanoi
16
16
  option :interval, type: :numeric, default: 0.1, desc: 'Time between frames (ish)'
17
17
 
18
18
  def phat
19
- smoosher = Hanoi::Jane::Smoosher.new
20
- [:close, :open].each do |direction|
21
- smoosher.direction = direction
22
- Hanoi::Jane.render_to_phat smoosher, options[:interval], options[:phat]
19
+ grid = JSON.parse(HTTParty.get('http://%s/lights' % options[:phat]).body)['matrix']
20
+ squeegee = Wiper::Squeegee.new do |s|
21
+ s.grid = grid unless grid == []
22
+ s.interval = 0.01
23
+ end
24
+
25
+ squeegee.each do |frame|
26
+ Hanoi::Jane.hit_phat frame, options[:phat]
27
+ sleep frame.interval
23
28
  end
24
29
 
25
30
  drop_in = DropIn.new do |d|
@@ -69,6 +74,36 @@ module Hanoi
69
74
  system('exit')
70
75
  end
71
76
  end
77
+
78
+ desc 'github', 'Render data suitable for drawing on the Github contribution graph'
79
+ option :discs, type: :numeric, default: 6, desc: 'Number of discs'
80
+ option :save_path, type: :string, required: true, desc: 'Where to store the state between moves'
81
+
82
+ def github
83
+ begin
84
+ towers = ConstrainedTowers.deserialise options[:save_path]
85
+ rescue Errno::ENOENT => e
86
+ if e.message == "No such file or directory @ rb_sysopen - #{options[:save_path]}"
87
+ towers = ConstrainedTowers.new options[:discs]
88
+ end
89
+ end
90
+
91
+ conf = YAML.load_file "#{ENV['HOME']}/.hanoi-jane/config.yaml"
92
+ Gitpaint.configure do |config|
93
+ config.ssh_key = conf['ssh_key']
94
+ config.username = conf['username']
95
+ config.email = conf['email']
96
+ config.token = conf['token']
97
+ end
98
+
99
+ h = Hanoi::Jane.render_to_github towers
100
+ Gitpaint.paint h, message: towers.ternary
101
+
102
+ unless towers.solved
103
+ towers.move
104
+ towers.serialise options[:save_path]
105
+ end
106
+ end
72
107
  end
73
108
  end
74
109
  end
@@ -40,9 +40,9 @@ module Hanoi
40
40
  end
41
41
 
42
42
  def Console.disc size, width
43
- return [:space] * Console.scale(width) unless size
44
- content = Console.scale size
45
- gap = (Console.scale(width) - content) / 2
43
+ return [:space] * Hanoi::Jane.scale(width) unless size
44
+ content = Hanoi::Jane.scale size
45
+ gap = (Hanoi::Jane.scale(width) - content) / 2
46
46
 
47
47
  output = [:disc] * content
48
48
 
@@ -65,11 +65,7 @@ module Hanoi
65
65
  [d, filler]
66
66
  }.unshift(filler).flatten
67
67
  end
68
-
69
- def Console.scale size
70
- (size * 2) + 1
71
- end
72
-
68
+
73
69
  def Console.rotate stacks
74
70
  stacks.map { |s| s.clone }.transpose.reverse
75
71
  end
@@ -0,0 +1,63 @@
1
+ module Hanoi
2
+ module Jane
3
+ module Formatters
4
+ class Github < Array
5
+ attr_accessor :stacks
6
+
7
+ def initialize towers
8
+ @stacks = towers.stacks
9
+
10
+ populate
11
+ end
12
+
13
+ def draw_disc disc, height = 0, offset = 0
14
+ if disc
15
+ width = Hanoi::Jane.scale disc
16
+ shim = (15 - width) / 2
17
+ (width).times do |i|
18
+ self[6 - height][i + offset + shim] = 8
19
+ end
20
+ end
21
+ end
22
+
23
+ def draw_stack stack, offset = 0
24
+ height = 0
25
+ stack.each do |disc|
26
+ draw_disc disc, height, offset
27
+ height += 1
28
+ end
29
+ end
30
+
31
+ def wipe
32
+ 7.times do |i|
33
+ self[i] = [0] * 52
34
+ end
35
+ end
36
+
37
+ def populate
38
+ wipe
39
+ draw_spindles
40
+ draw_stacks
41
+ end
42
+
43
+ def draw_spindles
44
+ self.map do |row|
45
+ offset = 8
46
+ 3.times do
47
+ row[offset] = 1
48
+ offset += 16
49
+ end
50
+ end
51
+ end
52
+
53
+ def draw_stacks
54
+ offset = 1
55
+ @stacks.each do |stack|
56
+ draw_stack stack, offset
57
+ offset += 16
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -124,6 +124,22 @@ module Hanoi
124
124
 
125
125
  raise SearchException.new '%s not found in stacks' % disc
126
126
  end
127
+
128
+ def serialise path
129
+ File.open path, 'w' do |f|
130
+ f.write Marshal.dump self
131
+ end
132
+ end
133
+
134
+ def RegularTowers.deserialise path
135
+ File.open path do |f|
136
+ Marshal.load f
137
+ end
138
+ end
139
+
140
+ def == other
141
+ self.inspect == other.inspect
142
+ end
127
143
  end
128
144
  end
129
145
  end
@@ -1,5 +1,5 @@
1
1
  module Hanoi
2
2
  module Jane
3
- VERSION = '0.3.4'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanoi-jane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pikesley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-05 00:00:00.000000000 Z
11
+ date: 2018-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,34 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.15'
125
+ - !ruby/object:Gem::Dependency
126
+ name: wiper
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: gitpaint
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  description: Solve the Towers of Hanoi by counting in base 2 or 3
126
154
  email:
127
155
  - sam.pikesley@gmail.com
@@ -158,6 +186,7 @@ files:
158
186
  - lib/hanoi/jane/config.rb
159
187
  - lib/hanoi/jane/exceptions.rb
160
188
  - lib/hanoi/jane/formatters/console.rb
189
+ - lib/hanoi/jane/formatters/github.rb
161
190
  - lib/hanoi/jane/formatters/matrix.rb
162
191
  - lib/hanoi/jane/towers/animated_towers.rb
163
192
  - lib/hanoi/jane/towers/constrained_towers.rb