gobgems 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 239ff963fa7c0bd9fa484a94b351b83248bac407
4
- data.tar.gz: a158c751e9a4230b472b44c9b3a84a00815e65bc
3
+ metadata.gz: aa8b7e1bf0da89f0fb59d75de162aa6185550563
4
+ data.tar.gz: 85c431e14f757b91f148fb9b84e4b6dae1518037
5
5
  SHA512:
6
- metadata.gz: 2d078d15dc86ab72359f817fe704247515576ae656d2c0211fe5e223f4b26b4a37aaed0ed28128a8ef7b3c7ef441619fe9777287c291ef4df282883941b4576e
7
- data.tar.gz: 9b653a1a342f2e61a4634b1f57ff7454b7bceb85c36186ce1a924a4e64470e851695f8f358660970181f9a4582bdc7fa02e19e2706034fb2300da14762ac3068
6
+ metadata.gz: 58c125024e2fb5520ca817ab816520bc1e92f58c1a11e7e58f78383e9fcb98b67c8ac263d19451103f460ff7dd11dce4dcb577b262264e1cdb0cf59a4945d7bb
7
+ data.tar.gz: 349d70a9b7beb9ce084936c1fda68ac2955037cd993b5da8a15fa813df3a9ead5e087abfe735d75c5470da1778914e7a29fe28bc178d396be0a8544bfe5d7071
@@ -89,6 +89,13 @@ module Gobgems
89
89
  cells[-(position[1]+1)][position[0]]
90
90
  end
91
91
 
92
+ def __each_cell__
93
+ (0..(size[0]-1)).each do |x|
94
+ (0..(size[1]-1)).each do |y|
95
+ yield __cell_at__([x, y]), x, y
96
+ end
97
+ end
98
+ end
92
99
  private
93
100
 
94
101
  def within_bounds?(position)
@@ -3,24 +3,28 @@ module Gobgems
3
3
  def self.write(board)
4
4
  "GBB/1.0\n" +
5
5
  "size #{board.size[0]} #{board.size[1]}\n" +
6
- "#{write_cells board.cells}" +
6
+ "#{write_cells board}" +
7
7
  "head #{board.head_position[0]} #{board.head_position[1]}"
8
8
  end
9
9
 
10
10
  private
11
11
 
12
- def self.write_cells(cells)
12
+ def self.write_cells(board)
13
13
  cells_gbb = ''
14
- cells.each_with_index do |row, x|
15
- row.each_with_index do |cell, y|
16
- cell.select {|color, count| count > 0}.each do |color, count|
17
- cells_gbb << "cell #{x} #{y} #{to_gbb_color color} #{count}\n"
18
- end
19
- end
14
+
15
+ board.__each_cell__ do |cell, x, y|
16
+ cell = cell.select { |color, count| count > 0 }
17
+ next if cell.empty?
18
+ cells_gbb << "cell #{x} #{y} #{write_colors cell}\n"
20
19
  end
20
+
21
21
  cells_gbb
22
22
  end
23
23
 
24
+ def self.write_colors(cell)
25
+ cell.map { |color, count| "#{to_gbb_color color} #{count}" }.join(' ')
26
+ end
27
+
24
28
  def self.to_gbb_color(color)
25
29
  case color
26
30
  when :red then 'Rojo'
@@ -1,3 +1,3 @@
1
1
  module Gobgems
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gobgems
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Aloi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-27 00:00:00.000000000 Z
12
+ date: 2015-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler