sashite-ggn 0.0.1

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.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +2 -0
  6. data/LICENSE.md +22 -0
  7. data/README.md +566 -0
  8. data/Rakefile +7 -0
  9. data/VERSION.semver +1 -0
  10. data/lib/sashite-ggn.rb +1 -0
  11. data/lib/sashite/ggn.rb +9 -0
  12. data/lib/sashite/ggn/ability.rb +37 -0
  13. data/lib/sashite/ggn/actor.rb +28 -0
  14. data/lib/sashite/ggn/ally.rb +28 -0
  15. data/lib/sashite/ggn/area.rb +25 -0
  16. data/lib/sashite/ggn/attacked.rb +28 -0
  17. data/lib/sashite/ggn/boolean.rb +25 -0
  18. data/lib/sashite/ggn/digit.rb +28 -0
  19. data/lib/sashite/ggn/digit_excluding_zero.rb +25 -0
  20. data/lib/sashite/ggn/direction.rb +27 -0
  21. data/lib/sashite/ggn/gameplay.rb +40 -0
  22. data/lib/sashite/ggn/gameplay_into_base64.rb +28 -0
  23. data/lib/sashite/ggn/integer.rb +28 -0
  24. data/lib/sashite/ggn/last_moved_actor.rb +28 -0
  25. data/lib/sashite/ggn/maximum_magnitude.rb +28 -0
  26. data/lib/sashite/ggn/name.rb +25 -0
  27. data/lib/sashite/ggn/negative_integer.rb +27 -0
  28. data/lib/sashite/ggn/null.rb +23 -0
  29. data/lib/sashite/ggn/object.rb +36 -0
  30. data/lib/sashite/ggn/occupied.rb +37 -0
  31. data/lib/sashite/ggn/pattern.rb +29 -0
  32. data/lib/sashite/ggn/previous_moves_counter.rb +28 -0
  33. data/lib/sashite/ggn/promotable_into_actors.rb +32 -0
  34. data/lib/sashite/ggn/required.rb +27 -0
  35. data/lib/sashite/ggn/self.rb +23 -0
  36. data/lib/sashite/ggn/square.rb +37 -0
  37. data/lib/sashite/ggn/state.rb +34 -0
  38. data/lib/sashite/ggn/subject.rb +37 -0
  39. data/lib/sashite/ggn/unsigned_integer.rb +28 -0
  40. data/lib/sashite/ggn/unsigned_integer_excluding_zero.rb +28 -0
  41. data/lib/sashite/ggn/verb.rb +42 -0
  42. data/lib/sashite/ggn/zero.rb +23 -0
  43. data/sashite-ggn.gemspec +21 -0
  44. data/test/_test_helper.rb +2 -0
  45. data/test/test_ggn.rb +546 -0
  46. data/test/test_ggn_ability.rb +51 -0
  47. data/test/test_ggn_actor.rb +591 -0
  48. data/test/test_ggn_ally.rb +51 -0
  49. data/test/test_ggn_area.rb +79 -0
  50. data/test/test_ggn_attacked.rb +51 -0
  51. data/test/test_ggn_boolean.rb +37 -0
  52. data/test/test_ggn_digit.rb +21 -0
  53. data/test/test_ggn_digit_excluding_zero.rb +22 -0
  54. data/test/test_ggn_direction.rb +21 -0
  55. data/test/test_ggn_gameplay.rb +573 -0
  56. data/test/test_ggn_gameplay_into_base64.rb +545 -0
  57. data/test/test_ggn_integer.rb +41 -0
  58. data/test/test_ggn_last_moved_actor.rb +51 -0
  59. data/test/test_ggn_maximum_magnitude.rb +37 -0
  60. data/test/test_ggn_name.rb +51 -0
  61. data/test/test_ggn_negative_integer.rb +21 -0
  62. data/test/test_ggn_null.rb +21 -0
  63. data/test/test_ggn_object.rb +35 -0
  64. data/test/test_ggn_occupied.rb +102 -0
  65. data/test/test_ggn_pattern.rb +82 -0
  66. data/test/test_ggn_previous_moves_counter.rb +41 -0
  67. data/test/test_ggn_promotable_into_actors.rb +598 -0
  68. data/test/test_ggn_required.rb +37 -0
  69. data/test/test_ggn_self.rb +21 -0
  70. data/test/test_ggn_square.rb +27 -0
  71. data/test/test_ggn_state.rb +28 -0
  72. data/test/test_ggn_subject.rb +30 -0
  73. data/test/test_ggn_unsigned_integer.rb +21 -0
  74. data/test/test_ggn_unsigned_integer_excluding_zero.rb +21 -0
  75. data/test/test_ggn_verb.rb +26 -0
  76. data/test/test_ggn_zero.rb +21 -0
  77. metadata +208 -0
@@ -0,0 +1,25 @@
1
+ module Sashite
2
+ module GGN
3
+ class Name
4
+ PATTERN = /(capture|remove|shift)/
5
+
6
+ def self.valid? str
7
+ !!str.match("^#{PATTERN}$")
8
+ end
9
+
10
+ def initialize str
11
+ raise ArgumentError unless self.class.valid? str
12
+
13
+ @value = str.to_sym
14
+ end
15
+
16
+ def as_json
17
+ @value
18
+ end
19
+
20
+ def to_s
21
+ @value.to_s
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'unsigned_integer_excluding_zero'
2
+
3
+ module Sashite
4
+ module GGN
5
+ class NegativeInteger
6
+ PATTERN = /-#{UnsignedIntegerExcludingZero::PATTERN}/
7
+
8
+ def self.valid? str
9
+ !!str.match("^#{PATTERN}$")
10
+ end
11
+
12
+ def initialize str
13
+ raise ArgumentError unless self.class.valid? str
14
+
15
+ @value = str.to_i
16
+ end
17
+
18
+ def as_json
19
+ @value
20
+ end
21
+
22
+ def to_s
23
+ @value.to_s
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ require 'singleton'
2
+
3
+ module Sashite
4
+ module GGN
5
+ class Null
6
+ include Singleton
7
+
8
+ PATTERN = /_/
9
+
10
+ def self.valid? str
11
+ !!str.match("^#{PATTERN}$")
12
+ end
13
+
14
+ def as_json
15
+ nil
16
+ end
17
+
18
+ def to_s
19
+ '_'
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'square'
2
+ require_relative 'promotable_into_actors'
3
+
4
+ module Sashite
5
+ module GGN
6
+ class Object
7
+ PATTERN = /#{Square::PATTERN}~#{Square::PATTERN}%#{PromotableIntoActors::PATTERN}/
8
+
9
+ def self.valid? str
10
+ !!str.match("^#{PATTERN}$")
11
+ end
12
+
13
+ attr_reader :src_square, :dst_square, :promotable_into_actors
14
+
15
+ def initialize str
16
+ raise ArgumentError unless self.class.valid? str
17
+
18
+ @src_square = Square.new str.split('~').fetch 0
19
+ @dst_square = Square.new str.split('~').fetch(1).split('%').fetch 0
20
+ @promotable_into_actors = PromotableIntoActors.new str.split('%').fetch 1
21
+ end
22
+
23
+ def as_json
24
+ {
25
+ src_square: @src_square.as_json,
26
+ dst_square: @dst_square.as_json,
27
+ promotable_into_actors: @promotable_into_actors.as_json
28
+ }
29
+ end
30
+
31
+ def to_s
32
+ "#{@src_square}~#{@dst_square}%#{@promotable_into_actors}"
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'boolean'
2
+ require_relative 'null'
3
+ require_relative 'subject'
4
+
5
+ module Sashite
6
+ module GGN
7
+ class Occupied
8
+ PATTERN = /(#{Null::PATTERN}|#{Boolean::PATTERN}|#{Subject::PATTERN}|an_ally_actor|an_enemy_actor)/
9
+
10
+ def self.valid? str
11
+ !!str.match("^#{PATTERN}$")
12
+ end
13
+
14
+ def initialize str
15
+ raise ArgumentError unless self.class.valid? str
16
+
17
+ @value = if Null.valid? str
18
+ Null.instance
19
+ elsif Boolean.valid? str
20
+ Boolean.new str
21
+ elsif Subject.valid? str
22
+ Subject.new str
23
+ else
24
+ str.to_sym
25
+ end
26
+ end
27
+
28
+ def as_json
29
+ @value.is_a?(Symbol) ? @value : @value.as_json
30
+ end
31
+
32
+ def to_s
33
+ @value.to_s
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'ability'
2
+
3
+ module Sashite
4
+ module GGN
5
+ class Pattern
6
+ PATTERN = /#{Ability::PATTERN}(; #{Ability::PATTERN})*/
7
+
8
+ def self.valid? str
9
+ !!str.match("^#{PATTERN}$")
10
+ end
11
+
12
+ attr_reader :abilities
13
+
14
+ def initialize str
15
+ raise ArgumentError unless self.class.valid? str
16
+
17
+ @abilities = str.split('; ').map { |ability| Ability.new ability }
18
+ end
19
+
20
+ def as_json
21
+ @abilities.map &:as_json
22
+ end
23
+
24
+ def to_s
25
+ @abilities.map(&:to_s).join '; '
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'null'
2
+ require_relative 'unsigned_integer'
3
+
4
+ module Sashite
5
+ module GGN
6
+ class PreviousMovesCounter
7
+ PATTERN = /(#{Null::PATTERN}|#{UnsignedInteger::PATTERN})/
8
+
9
+ def self.valid? str
10
+ !!str.match("^#{PATTERN}$")
11
+ end
12
+
13
+ def initialize str
14
+ raise ArgumentError unless self.class.valid? str
15
+
16
+ @value = (Null.valid?(str) ? Null.instance : UnsignedInteger.new(str))
17
+ end
18
+
19
+ def as_json
20
+ @value.as_json
21
+ end
22
+
23
+ def to_s
24
+ @value.to_s
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'actor'
2
+ require_relative 'gameplay_into_base64'
3
+
4
+ module Sashite
5
+ module GGN
6
+ class PromotableIntoActors
7
+ PATTERN = /(#{GameplayIntoBase64::PATTERN},)*#{Actor::PATTERN}/
8
+
9
+ def self.valid? str
10
+ !!str.match("^#{PATTERN}$")
11
+ end
12
+
13
+ attr_reader :values
14
+
15
+ def initialize str
16
+ raise ArgumentError unless self.class.valid? str
17
+
18
+ @values = str.split(',').map do |value|
19
+ Actor.valid?(value) ? Actor.new(value) : GameplayIntoBase64.new(value)
20
+ end
21
+ end
22
+
23
+ def as_json
24
+ @values.map &:as_json
25
+ end
26
+
27
+ def to_s
28
+ @values.map(&:to_s).join ','
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'boolean'
2
+
3
+ module Sashite
4
+ module GGN
5
+ class Required
6
+ PATTERN = /#{Boolean::PATTERN}/
7
+
8
+ def self.valid? str
9
+ !!str.match("^#{PATTERN}$")
10
+ end
11
+
12
+ def initialize str
13
+ raise ArgumentError unless self.class.valid? str
14
+
15
+ @value = Boolean.new(str)
16
+ end
17
+
18
+ def as_json
19
+ @value.as_json
20
+ end
21
+
22
+ def to_s
23
+ @value.to_s
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ require 'singleton'
2
+
3
+ module Sashite
4
+ module GGN
5
+ class Self
6
+ include Singleton
7
+
8
+ PATTERN = /self/
9
+
10
+ def self.valid? str
11
+ !!str.match("^#{PATTERN}$")
12
+ end
13
+
14
+ def as_json
15
+ :self
16
+ end
17
+
18
+ def to_s
19
+ 'self'
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'attacked'
2
+ require_relative 'occupied'
3
+ require_relative 'area'
4
+
5
+ module Sashite
6
+ module GGN
7
+ class Square
8
+ PATTERN = /#{Attacked::PATTERN}@#{Occupied::PATTERN}\+#{Area::PATTERN}/
9
+
10
+ def self.valid? str
11
+ !!str.match("^#{PATTERN}$")
12
+ end
13
+
14
+ attr_reader :attacked, :occupied, :area
15
+
16
+ def initialize str
17
+ raise ArgumentError unless self.class.valid? str
18
+
19
+ @attacked = Attacked.new str.split('@').fetch(0)
20
+ @occupied = Occupied.new str.split('@').fetch(1).split('+').fetch(0)
21
+ @area = Area.new str.split('+').fetch(1)
22
+ end
23
+
24
+ def as_json
25
+ {
26
+ :"...attacked?" => @attacked.as_json,
27
+ :"...occupied!" => @occupied.as_json,
28
+ :"area" => @area.as_json
29
+ }
30
+ end
31
+
32
+ def to_s
33
+ "#{@attacked}@#{@occupied}+#{@area}"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ require_relative 'last_moved_actor'
2
+ require_relative 'previous_moves_counter'
3
+
4
+ module Sashite
5
+ module GGN
6
+ class State
7
+ PATTERN = /#{LastMovedActor::PATTERN}&#{PreviousMovesCounter::PATTERN}/
8
+
9
+ def self.valid? str
10
+ !!str.match("^#{PATTERN}$")
11
+ end
12
+
13
+ attr_reader :previous_moves_counter, :last_moved_actor
14
+
15
+ def initialize str
16
+ raise ArgumentError unless self.class.valid? str
17
+
18
+ @last_moved_actor = LastMovedActor.new str.split('&').fetch(0)
19
+ @previous_moves_counter = PreviousMovesCounter.new str.split('&').fetch(1)
20
+ end
21
+
22
+ def as_json
23
+ {
24
+ :"...last_moved_actor?" => @last_moved_actor.as_json,
25
+ :"...previous_moves_counter" => @previous_moves_counter.as_json
26
+ }
27
+ end
28
+
29
+ def to_s
30
+ "#{@last_moved_actor}&#{@previous_moves_counter}"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'ally'
2
+ require_relative 'actor'
3
+ require_relative 'state'
4
+
5
+ module Sashite
6
+ module GGN
7
+ class Subject
8
+ PATTERN = /#{Ally::PATTERN}<#{Actor::PATTERN}>#{State::PATTERN}/
9
+
10
+ def self.valid? str
11
+ !!str.match("^#{PATTERN}$")
12
+ end
13
+
14
+ attr_reader :ally, :actor, :state
15
+
16
+ def initialize str
17
+ raise ArgumentError unless self.class.valid? str
18
+
19
+ @ally = Ally.new str.split('<').fetch(0)
20
+ @actor = Actor.new str.split('<').fetch(1).split('>').fetch(0)
21
+ @state = State.new str.split('>').fetch(1)
22
+ end
23
+
24
+ def as_json
25
+ {
26
+ :"...ally?" => @ally.as_json,
27
+ actor: @actor.as_json,
28
+ state: @state.as_json
29
+ }
30
+ end
31
+
32
+ def to_s
33
+ "#{@ally}<#{@actor}>#{@state}"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'unsigned_integer_excluding_zero'
2
+ require_relative 'zero'
3
+
4
+ module Sashite
5
+ module GGN
6
+ class UnsignedInteger
7
+ PATTERN = /(#{Zero::PATTERN}|#{UnsignedIntegerExcludingZero::PATTERN})/
8
+
9
+ def self.valid? str
10
+ !!str.match("^#{PATTERN}$")
11
+ end
12
+
13
+ def initialize str
14
+ raise ArgumentError unless self.class.valid? str
15
+
16
+ @value = (Zero.valid?(str) ? Zero.instance : UnsignedIntegerExcludingZero.new(str))
17
+ end
18
+
19
+ def as_json
20
+ @value.as_json
21
+ end
22
+
23
+ def to_s
24
+ @value.to_s
25
+ end
26
+ end
27
+ end
28
+ end