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 +4 -4
- data/bin/gobgems +23 -0
- data/lib/gobgems/{gbb_parser.rb → gbb/gbb_reader.rb} +2 -2
- data/lib/gobgems/gbb/gbb_writer.rb +33 -0
- data/lib/gobgems/gbb.rb +14 -0
- data/lib/gobgems/version.rb +1 -1
- data/lib/gobgems.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38dc483246de3b289186d9341b762dce713d92d2
|
4
|
+
data.tar.gz: 20897b5b070ec488b7ba5307badfb6e279fc1f41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 '
|
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
|
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
|
data/lib/gobgems/gbb.rb
ADDED
data/lib/gobgems/version.rb
CHANGED
data/lib/gobgems.rb
CHANGED
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.
|
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/
|
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
|