gobgems 0.0.1 → 0.0.2

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: bb29086c782595aa8c66939dfcbfdc7f80bb2402
4
- data.tar.gz: 18f24cb731be7c545d68176fbcc6a7aae99d47b7
3
+ metadata.gz: 38dc483246de3b289186d9341b762dce713d92d2
4
+ data.tar.gz: 20897b5b070ec488b7ba5307badfb6e279fc1f41
5
5
  SHA512:
6
- metadata.gz: 1625669f34c466ae8c9cd721c3327f3da77d3a0e99537a2ff371ef1e5437dab1b02c8b59ea46dc1fe2d485eac27ac7cf442f9d414135bb90662355470b9af59a
7
- data.tar.gz: 1d51527eca9d0819f69c7a8597d881eacb6b3291c0b29e2d60cd7f77388346aafe2dcf398891edc0052c5b368bdcc1fb41090534af76a06b1e7afe9cd7627be7
6
+ metadata.gz: bfb5ffdf7a27e13bb6746a95a5de74185f2e3f8c1236d1bc6b7c6a6347da155e43f894fc11602f0ef132e9ff65a9bb3589d710df8a297fd47d82db40902eea8e
7
+ data.tar.gz: 668e8ca386c57d1824156e29074b4811e0c27866a91800ecbd1deafa6b135077bf025e529b69289a01006c1bdc1b7a5d74601c57ff3b3a7fafdde33149e8a447
data/bin/gobgems ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ARGV.size != 3
4
+ puts 'Not enough arguments. Must pass program file, input board file and output board file'
5
+ exit 1
6
+ end
7
+
8
+ program = File.read ARGV[0]
9
+ input_gbb = File.read ARGV[1]
10
+ output_gbb_file = ARGV[2]
11
+
12
+ require 'gobgems'
13
+
14
+ Main = Class.new
15
+ Main.class_eval do
16
+ include Gobgems::Program
17
+ eval program
18
+ end
19
+
20
+ context = Gobgems::ExecutionContext.new
21
+ context.board = Gobgems::Gbb.read input_gbb
22
+ context.run Main
23
+ File.write output_gbb_file, Gobgems::Gbb.write(context.board)
@@ -1,4 +1,4 @@
1
- require_relative '../extensions/array.rb'
1
+ require_relative '../../extensions/array.rb'
2
2
 
3
3
 
4
4
  class MatchData
@@ -8,7 +8,7 @@ class MatchData
8
8
  end
9
9
 
10
10
  module Gobgems
11
- class GbbParser
11
+ class GbbReader
12
12
  COLORS = {'Azul' => :blue, 'Negro' => :black, 'Rojo' => :red, 'Verde' => :green}
13
13
 
14
14
  def from_string(gbb_string)
@@ -0,0 +1,33 @@
1
+ module Gobgems
2
+ module GbbWriter
3
+ def self.write(board)
4
+ "GBB/1.0\n" +
5
+ "size #{board.size[0]} #{board.size[1]}\n" +
6
+ "#{write_cells board.cells}" +
7
+ "head #{board.head_position[0]} #{board.head_position[1]}"
8
+ end
9
+
10
+ private
11
+
12
+ def self.write_cells(cells)
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
20
+ end
21
+ cells_gbb
22
+ end
23
+
24
+ def self.to_gbb_color(color)
25
+ case color
26
+ when :red then 'Rojo'
27
+ when :green then 'Verde'
28
+ when :black then 'Negro'
29
+ when :blue then 'Azul'
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ require_relative './gbb/gbb_reader'
2
+ require_relative './gbb/gbb_writer'
3
+
4
+ module Gobgems
5
+ module Gbb
6
+ def self.read(gbb)
7
+ GbbReader.new.from_string(gbb)
8
+ end
9
+
10
+ def self.write(board)
11
+ GbbWriter.write(board)
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Gobgems
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/gobgems.rb CHANGED
@@ -6,5 +6,5 @@ require_relative 'gobgems/color'
6
6
  require_relative 'gobgems/board'
7
7
  require_relative 'gobgems/execution_context'
8
8
  require_relative 'gobgems/program'
9
- require_relative 'gobgems/gbb_parser'
9
+ require_relative 'gobgems/gbb'
10
10
  require_relative 'gobgems/version'
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Aloi
@@ -71,17 +71,21 @@ description: Write Gobstones program within Ruby
71
71
  email:
72
72
  - federico.aloi@gmail.com
73
73
  - flbulgarelli@yahoo.com.ar
74
- executables: []
74
+ executables:
75
+ - gobgems
75
76
  extensions: []
76
77
  extra_rdoc_files: []
77
78
  files:
79
+ - bin/gobgems
78
80
  - lib/extensions/array.rb
79
81
  - lib/gobgems.rb
80
82
  - lib/gobgems/board.rb
81
83
  - lib/gobgems/color.rb
82
84
  - lib/gobgems/direction.rb
83
85
  - lib/gobgems/execution_context.rb
84
- - lib/gobgems/gbb_parser.rb
86
+ - lib/gobgems/gbb.rb
87
+ - lib/gobgems/gbb/gbb_reader.rb
88
+ - lib/gobgems/gbb/gbb_writer.rb
85
89
  - lib/gobgems/program.rb
86
90
  - lib/gobgems/version.rb
87
91
  homepage: https://github.com/flbulgarelli/gobgems