sashite-ggn 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +523 -521
- data/VERSION.semver +1 -1
- data/lib/sashite/ggn.rb +3 -2
- data/lib/sashite/ggn/ability.rb +11 -19
- data/lib/sashite/ggn/actor.rb +5 -13
- data/lib/sashite/ggn/ally.rb +6 -14
- data/lib/sashite/ggn/area.rb +6 -14
- data/lib/sashite/ggn/attacked.rb +6 -14
- data/lib/sashite/ggn/boolean.rb +6 -14
- data/lib/sashite/ggn/digit.rb +6 -14
- data/lib/sashite/ggn/digit_excluding_zero.rb +6 -14
- data/lib/sashite/ggn/direction.rb +6 -14
- data/lib/sashite/ggn/gameplay.rb +8 -28
- data/lib/sashite/ggn/gameplay_into_base64.rb +7 -14
- data/lib/sashite/ggn/integer.rb +6 -14
- data/lib/sashite/ggn/last_moved_actor.rb +6 -14
- data/lib/sashite/ggn/maximum_magnitude.rb +6 -14
- data/lib/sashite/ggn/name.rb +6 -14
- data/lib/sashite/ggn/negative_integer.rb +6 -14
- data/lib/sashite/ggn/null.rb +7 -9
- data/lib/sashite/ggn/object.rb +11 -19
- data/lib/sashite/ggn/occupied.rb +12 -20
- data/lib/sashite/ggn/pattern.rb +7 -16
- data/lib/sashite/ggn/previous_moves_counter.rb +6 -14
- data/lib/sashite/ggn/promotable_into_actors.rb +8 -17
- data/lib/sashite/ggn/required.rb +6 -14
- data/lib/sashite/ggn/self.rb +7 -9
- data/lib/sashite/ggn/square.rb +11 -19
- data/lib/sashite/ggn/state.rb +9 -17
- data/lib/sashite/ggn/subject.rb +11 -19
- data/lib/sashite/ggn/unsigned_integer.rb +6 -14
- data/lib/sashite/ggn/unsigned_integer_excluding_zero.rb +5 -13
- data/lib/sashite/ggn/verb.rb +15 -24
- data/lib/sashite/ggn/zero.rb +7 -9
- data/sashite-ggn.gemspec +2 -4
- data/test/test_ggn.rb +501 -495
- data/test/test_ggn_ability.rb +10 -10
- data/test/test_ggn_actor.rb +516 -536
- data/test/test_ggn_ally.rb +13 -29
- data/test/test_ggn_area.rb +9 -67
- data/test/test_ggn_attacked.rb +13 -29
- data/test/test_ggn_boolean.rb +10 -26
- data/test/test_ggn_digit.rb +10 -10
- data/test/test_ggn_digit_excluding_zero.rb +10 -11
- data/test/test_ggn_direction.rb +10 -10
- data/test/test_ggn_gameplay.rb +22 -38
- data/test/test_ggn_gameplay_into_base64.rb +511 -501
- data/test/test_ggn_integer.rb +19 -21
- data/test/test_ggn_last_moved_actor.rb +13 -29
- data/test/test_ggn_maximum_magnitude.rb +18 -16
- data/test/test_ggn_name.rb +9 -39
- data/test/test_ggn_negative_integer.rb +10 -10
- data/test/test_ggn_null.rb +10 -10
- data/test/test_ggn_object.rb +22 -24
- data/test/test_ggn_occupied.rb +40 -64
- data/test/test_ggn_pattern.rb +12 -10
- data/test/test_ggn_previous_moves_counter.rb +18 -20
- data/test/test_ggn_promotable_into_actors.rb +529 -549
- data/test/test_ggn_required.rb +10 -26
- data/test/test_ggn_self.rb +10 -10
- data/test/test_ggn_square.rb +14 -16
- data/test/test_ggn_state.rb +15 -19
- data/test/test_ggn_subject.rb +17 -19
- data/test/test_ggn_unsigned_integer.rb +30 -12
- data/test/test_ggn_unsigned_integer_excluding_zero.rb +14 -10
- data/test/test_ggn_verb.rb +16 -15
- data/test/test_ggn_zero.rb +10 -10
- metadata +4 -18
@@ -3,25 +3,17 @@ require_relative 'unsigned_integer_excluding_zero'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module MaximumMagnitude
|
7
7
|
PATTERN = /(#{Null::PATTERN}|#{UnsignedIntegerExcludingZero::PATTERN})/
|
8
8
|
|
9
|
-
def self.valid?
|
10
|
-
!!
|
9
|
+
def self.valid? io
|
10
|
+
!!io.match("^#{PATTERN}$")
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
raise ArgumentError unless
|
13
|
+
def self.load io
|
14
|
+
raise ArgumentError unless valid? io
|
15
15
|
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def as_json
|
20
|
-
@value.as_json
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_s
|
24
|
-
@value.to_s
|
16
|
+
Null.valid?(io) ? Null.load : UnsignedIntegerExcludingZero.load(io)
|
25
17
|
end
|
26
18
|
end
|
27
19
|
end
|
data/lib/sashite/ggn/name.rb
CHANGED
@@ -1,24 +1,16 @@
|
|
1
1
|
module Sashite
|
2
2
|
module GGN
|
3
|
-
|
3
|
+
module Name
|
4
4
|
PATTERN = /(capture|remove|shift)/
|
5
5
|
|
6
|
-
def self.valid?
|
7
|
-
!!
|
6
|
+
def self.valid? io
|
7
|
+
!!io.match("^#{PATTERN}$")
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
raise ArgumentError unless
|
10
|
+
def self.load io
|
11
|
+
raise ArgumentError unless valid? io
|
12
12
|
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def as_json
|
17
|
-
@value
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_s
|
21
|
-
@value.to_s
|
13
|
+
io.to_sym
|
22
14
|
end
|
23
15
|
end
|
24
16
|
end
|
@@ -2,25 +2,17 @@ require_relative 'unsigned_integer_excluding_zero'
|
|
2
2
|
|
3
3
|
module Sashite
|
4
4
|
module GGN
|
5
|
-
|
5
|
+
module NegativeInteger
|
6
6
|
PATTERN = /-#{UnsignedIntegerExcludingZero::PATTERN}/
|
7
7
|
|
8
|
-
def self.valid?
|
9
|
-
!!
|
8
|
+
def self.valid? io
|
9
|
+
!!io.match("^#{PATTERN}$")
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
raise ArgumentError unless
|
12
|
+
def self.load io
|
13
|
+
raise ArgumentError unless valid? io
|
14
14
|
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def as_json
|
19
|
-
@value
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_s
|
23
|
-
@value.to_s
|
15
|
+
io.to_i
|
24
16
|
end
|
25
17
|
end
|
26
18
|
end
|
data/lib/sashite/ggn/null.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
1
|
module Sashite
|
4
2
|
module GGN
|
5
|
-
|
6
|
-
include Singleton
|
7
|
-
|
3
|
+
module Null
|
8
4
|
PATTERN = /_/
|
9
5
|
|
10
|
-
def self.valid?
|
11
|
-
!!
|
6
|
+
def self.valid? io
|
7
|
+
!!io.match("^#{PATTERN}$")
|
12
8
|
end
|
13
9
|
|
14
|
-
def
|
10
|
+
def self.load io = nil
|
11
|
+
raise ArgumentError if io && !valid?(io)
|
12
|
+
|
15
13
|
nil
|
16
14
|
end
|
17
15
|
|
18
|
-
def
|
16
|
+
def self.dump
|
19
17
|
'_'
|
20
18
|
end
|
21
19
|
end
|
data/lib/sashite/ggn/object.rb
CHANGED
@@ -3,34 +3,26 @@ require_relative 'promotable_into_actors'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module Object
|
7
7
|
PATTERN = /#{Square::PATTERN}~#{Square::PATTERN}%#{PromotableIntoActors::PATTERN}/
|
8
8
|
|
9
|
-
def self.valid?
|
10
|
-
!!
|
9
|
+
def self.valid? io
|
10
|
+
!!io.match("^#{PATTERN}$")
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
def self.load io
|
14
|
+
raise ArgumentError unless valid? io
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
src_square = Square.load io.split('~').fetch 0
|
17
|
+
dst_square = Square.load io.split('~').fetch(1).split('%').fetch 0
|
18
|
+
promotable_into_actors = PromotableIntoActors.load io.split('%').fetch 1
|
17
19
|
|
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
20
|
{
|
25
|
-
src_square:
|
26
|
-
dst_square:
|
27
|
-
promotable_into_actors:
|
21
|
+
src_square: src_square,
|
22
|
+
dst_square: dst_square,
|
23
|
+
promotable_into_actors: promotable_into_actors
|
28
24
|
}
|
29
25
|
end
|
30
|
-
|
31
|
-
def to_s
|
32
|
-
"#{@src_square}~#{@dst_square}%#{@promotable_into_actors}"
|
33
|
-
end
|
34
26
|
end
|
35
27
|
end
|
36
28
|
end
|
data/lib/sashite/ggn/occupied.rb
CHANGED
@@ -4,34 +4,26 @@ require_relative 'subject'
|
|
4
4
|
|
5
5
|
module Sashite
|
6
6
|
module GGN
|
7
|
-
|
7
|
+
module Occupied
|
8
8
|
PATTERN = /(#{Null::PATTERN}|#{Boolean::PATTERN}|#{Subject::PATTERN}|an_ally_actor|an_enemy_actor)/
|
9
9
|
|
10
|
-
def self.valid?
|
11
|
-
!!
|
10
|
+
def self.valid? io
|
11
|
+
!!io.match("^#{PATTERN}$")
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
raise ArgumentError unless
|
14
|
+
def self.load io
|
15
|
+
raise ArgumentError unless valid? io
|
16
16
|
|
17
|
-
|
18
|
-
Null.
|
19
|
-
elsif Boolean.valid?
|
20
|
-
Boolean.
|
21
|
-
elsif Subject.valid?
|
22
|
-
Subject.
|
17
|
+
if Null.valid? io
|
18
|
+
Null.load
|
19
|
+
elsif Boolean.valid? io
|
20
|
+
Boolean.load io
|
21
|
+
elsif Subject.valid? io
|
22
|
+
Subject.load io
|
23
23
|
else
|
24
|
-
|
24
|
+
io.to_sym
|
25
25
|
end
|
26
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
27
|
end
|
36
28
|
end
|
37
29
|
end
|
data/lib/sashite/ggn/pattern.rb
CHANGED
@@ -2,27 +2,18 @@ require_relative 'ability'
|
|
2
2
|
|
3
3
|
module Sashite
|
4
4
|
module GGN
|
5
|
-
|
5
|
+
module Pattern
|
6
6
|
PATTERN = /#{Ability::PATTERN}(; #{Ability::PATTERN})*/
|
7
7
|
|
8
|
-
def self.valid?
|
9
|
-
|
8
|
+
def self.valid? io
|
9
|
+
io.match("^#{PATTERN}$") &&
|
10
|
+
io.split('; ').uniq.join('; ') == io
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
def self.load io
|
14
|
+
raise ArgumentError unless valid? io
|
13
15
|
|
14
|
-
|
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 '; '
|
16
|
+
io.split('; ').map { |ability| Ability.load ability }
|
26
17
|
end
|
27
18
|
end
|
28
19
|
end
|
@@ -3,25 +3,17 @@ require_relative 'unsigned_integer'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module PreviousMovesCounter
|
7
7
|
PATTERN = /(#{Null::PATTERN}|#{UnsignedInteger::PATTERN})/
|
8
8
|
|
9
|
-
def self.valid?
|
10
|
-
!!
|
9
|
+
def self.valid? io
|
10
|
+
!!io.match("^#{PATTERN}$")
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
raise ArgumentError unless
|
13
|
+
def self.load io
|
14
|
+
raise ArgumentError unless valid? io
|
15
15
|
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def as_json
|
20
|
-
@value.as_json
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_s
|
24
|
-
@value.to_s
|
16
|
+
Null.valid?(io) ? Null.load : UnsignedInteger.load(io)
|
25
17
|
end
|
26
18
|
end
|
27
19
|
end
|
@@ -3,30 +3,21 @@ require_relative 'gameplay_into_base64'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module PromotableIntoActors
|
7
7
|
PATTERN = /(#{GameplayIntoBase64::PATTERN},)*#{Actor::PATTERN}/
|
8
8
|
|
9
|
-
def self.valid?
|
10
|
-
|
9
|
+
def self.valid? io
|
10
|
+
io.match("^#{PATTERN}$") &&
|
11
|
+
io.split(',').uniq.join(',') == io
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
+
def self.load io
|
15
|
+
raise ArgumentError unless valid? io
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@values = str.split(',').map do |value|
|
19
|
-
Actor.valid?(value) ? Actor.new(value) : GameplayIntoBase64.new(value)
|
17
|
+
io.split(',').map do |value|
|
18
|
+
Actor.valid?(value) ? Actor.load(value) : GameplayIntoBase64.load(value)
|
20
19
|
end
|
21
20
|
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
21
|
end
|
31
22
|
end
|
32
23
|
end
|
data/lib/sashite/ggn/required.rb
CHANGED
@@ -2,25 +2,17 @@ require_relative 'boolean'
|
|
2
2
|
|
3
3
|
module Sashite
|
4
4
|
module GGN
|
5
|
-
|
5
|
+
module Required
|
6
6
|
PATTERN = /#{Boolean::PATTERN}/
|
7
7
|
|
8
|
-
def self.valid?
|
9
|
-
!!
|
8
|
+
def self.valid? io
|
9
|
+
!!io.match("^#{PATTERN}$")
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
raise ArgumentError unless
|
12
|
+
def self.load io
|
13
|
+
raise ArgumentError unless valid? io
|
14
14
|
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def as_json
|
19
|
-
@value.as_json
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_s
|
23
|
-
@value.to_s
|
15
|
+
Boolean.load io
|
24
16
|
end
|
25
17
|
end
|
26
18
|
end
|
data/lib/sashite/ggn/self.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
1
|
module Sashite
|
4
2
|
module GGN
|
5
|
-
|
6
|
-
include Singleton
|
7
|
-
|
3
|
+
module Self
|
8
4
|
PATTERN = /self/
|
9
5
|
|
10
|
-
def self.valid?
|
11
|
-
!!
|
6
|
+
def self.valid? io
|
7
|
+
!!io.match("^#{PATTERN}$")
|
12
8
|
end
|
13
9
|
|
14
|
-
def
|
10
|
+
def self.load io = nil
|
11
|
+
raise ArgumentError if io && !valid?(io)
|
12
|
+
|
15
13
|
:self
|
16
14
|
end
|
17
15
|
|
18
|
-
def
|
16
|
+
def self.dump
|
19
17
|
'self'
|
20
18
|
end
|
21
19
|
end
|
data/lib/sashite/ggn/square.rb
CHANGED
@@ -4,34 +4,26 @@ require_relative 'area'
|
|
4
4
|
|
5
5
|
module Sashite
|
6
6
|
module GGN
|
7
|
-
|
7
|
+
module Square
|
8
8
|
PATTERN = /#{Attacked::PATTERN}@#{Occupied::PATTERN}\+#{Area::PATTERN}/
|
9
9
|
|
10
|
-
def self.valid?
|
11
|
-
!!
|
10
|
+
def self.valid? io
|
11
|
+
!!io.match("^#{PATTERN}$")
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
def self.load io
|
15
|
+
raise ArgumentError unless valid? io
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
attacked = Attacked.load io.split('@').fetch(0)
|
18
|
+
occupied = Occupied.load io.split('@').fetch(1).split('+').fetch(0)
|
19
|
+
area = Area.load io.split('+').fetch(1)
|
18
20
|
|
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
21
|
{
|
26
|
-
:"...attacked?" =>
|
27
|
-
:"...occupied!" =>
|
28
|
-
:"area" =>
|
22
|
+
:"...attacked?" => attacked,
|
23
|
+
:"...occupied!" => occupied,
|
24
|
+
:"area" => area
|
29
25
|
}
|
30
26
|
end
|
31
|
-
|
32
|
-
def to_s
|
33
|
-
"#{@attacked}@#{@occupied}+#{@area}"
|
34
|
-
end
|
35
27
|
end
|
36
28
|
end
|
37
29
|
end
|
data/lib/sashite/ggn/state.rb
CHANGED
@@ -3,32 +3,24 @@ require_relative 'previous_moves_counter'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module State
|
7
7
|
PATTERN = /#{LastMovedActor::PATTERN}&#{PreviousMovesCounter::PATTERN}/
|
8
8
|
|
9
|
-
def self.valid?
|
10
|
-
!!
|
9
|
+
def self.valid? io
|
10
|
+
!!io.match("^#{PATTERN}$")
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
def self.load io
|
14
|
+
raise ArgumentError unless valid? io
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
last_moved_actor = LastMovedActor.load io.split('&').fetch(0)
|
17
|
+
previous_moves_counter = PreviousMovesCounter.load io.split('&').fetch(1)
|
17
18
|
|
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
19
|
{
|
24
|
-
:"...last_moved_actor?" =>
|
25
|
-
:"...previous_moves_counter" =>
|
20
|
+
:"...last_moved_actor?" => last_moved_actor,
|
21
|
+
:"...previous_moves_counter" => previous_moves_counter
|
26
22
|
}
|
27
23
|
end
|
28
|
-
|
29
|
-
def to_s
|
30
|
-
"#{@last_moved_actor}&#{@previous_moves_counter}"
|
31
|
-
end
|
32
24
|
end
|
33
25
|
end
|
34
26
|
end
|