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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/LICENSE.md +22 -0
- data/README.md +566 -0
- data/Rakefile +7 -0
- data/VERSION.semver +1 -0
- data/lib/sashite-ggn.rb +1 -0
- data/lib/sashite/ggn.rb +9 -0
- data/lib/sashite/ggn/ability.rb +37 -0
- data/lib/sashite/ggn/actor.rb +28 -0
- data/lib/sashite/ggn/ally.rb +28 -0
- data/lib/sashite/ggn/area.rb +25 -0
- data/lib/sashite/ggn/attacked.rb +28 -0
- data/lib/sashite/ggn/boolean.rb +25 -0
- data/lib/sashite/ggn/digit.rb +28 -0
- data/lib/sashite/ggn/digit_excluding_zero.rb +25 -0
- data/lib/sashite/ggn/direction.rb +27 -0
- data/lib/sashite/ggn/gameplay.rb +40 -0
- data/lib/sashite/ggn/gameplay_into_base64.rb +28 -0
- data/lib/sashite/ggn/integer.rb +28 -0
- data/lib/sashite/ggn/last_moved_actor.rb +28 -0
- data/lib/sashite/ggn/maximum_magnitude.rb +28 -0
- data/lib/sashite/ggn/name.rb +25 -0
- data/lib/sashite/ggn/negative_integer.rb +27 -0
- data/lib/sashite/ggn/null.rb +23 -0
- data/lib/sashite/ggn/object.rb +36 -0
- data/lib/sashite/ggn/occupied.rb +37 -0
- data/lib/sashite/ggn/pattern.rb +29 -0
- data/lib/sashite/ggn/previous_moves_counter.rb +28 -0
- data/lib/sashite/ggn/promotable_into_actors.rb +32 -0
- data/lib/sashite/ggn/required.rb +27 -0
- data/lib/sashite/ggn/self.rb +23 -0
- data/lib/sashite/ggn/square.rb +37 -0
- data/lib/sashite/ggn/state.rb +34 -0
- data/lib/sashite/ggn/subject.rb +37 -0
- data/lib/sashite/ggn/unsigned_integer.rb +28 -0
- data/lib/sashite/ggn/unsigned_integer_excluding_zero.rb +28 -0
- data/lib/sashite/ggn/verb.rb +42 -0
- data/lib/sashite/ggn/zero.rb +23 -0
- data/sashite-ggn.gemspec +21 -0
- data/test/_test_helper.rb +2 -0
- data/test/test_ggn.rb +546 -0
- data/test/test_ggn_ability.rb +51 -0
- data/test/test_ggn_actor.rb +591 -0
- data/test/test_ggn_ally.rb +51 -0
- data/test/test_ggn_area.rb +79 -0
- data/test/test_ggn_attacked.rb +51 -0
- data/test/test_ggn_boolean.rb +37 -0
- data/test/test_ggn_digit.rb +21 -0
- data/test/test_ggn_digit_excluding_zero.rb +22 -0
- data/test/test_ggn_direction.rb +21 -0
- data/test/test_ggn_gameplay.rb +573 -0
- data/test/test_ggn_gameplay_into_base64.rb +545 -0
- data/test/test_ggn_integer.rb +41 -0
- data/test/test_ggn_last_moved_actor.rb +51 -0
- data/test/test_ggn_maximum_magnitude.rb +37 -0
- data/test/test_ggn_name.rb +51 -0
- data/test/test_ggn_negative_integer.rb +21 -0
- data/test/test_ggn_null.rb +21 -0
- data/test/test_ggn_object.rb +35 -0
- data/test/test_ggn_occupied.rb +102 -0
- data/test/test_ggn_pattern.rb +82 -0
- data/test/test_ggn_previous_moves_counter.rb +41 -0
- data/test/test_ggn_promotable_into_actors.rb +598 -0
- data/test/test_ggn_required.rb +37 -0
- data/test/test_ggn_self.rb +21 -0
- data/test/test_ggn_square.rb +27 -0
- data/test/test_ggn_state.rb +28 -0
- data/test/test_ggn_subject.rb +30 -0
- data/test/test_ggn_unsigned_integer.rb +21 -0
- data/test/test_ggn_unsigned_integer_excluding_zero.rb +21 -0
- data/test/test_ggn_verb.rb +26 -0
- data/test/test_ggn_zero.rb +21 -0
- 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
|