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
data/VERSION.semver
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/sashite/ggn.rb
CHANGED
data/lib/sashite/ggn/ability.rb
CHANGED
@@ -4,34 +4,26 @@ require_relative 'object'
|
|
4
4
|
|
5
5
|
module Sashite
|
6
6
|
module GGN
|
7
|
-
|
7
|
+
module Ability
|
8
8
|
PATTERN = /#{Subject::PATTERN}\^#{Verb::PATTERN}=#{Object::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
|
+
subject = Subject.load io.split('^').fetch 0
|
18
|
+
verb = Verb.load io.split('^').fetch(1).split('=').fetch 0
|
19
|
+
object = Object.load io.split('=').fetch 1
|
18
20
|
|
19
|
-
@subject = Subject.new str.split('^').fetch 0
|
20
|
-
@verb = Verb.new str.split('^').fetch(1).split('=').fetch 0
|
21
|
-
@object = Object.new str.split('=').fetch 1
|
22
|
-
end
|
23
|
-
|
24
|
-
def as_json
|
25
21
|
{
|
26
|
-
subject:
|
27
|
-
verb:
|
28
|
-
object:
|
22
|
+
subject: subject,
|
23
|
+
verb: verb,
|
24
|
+
object: object
|
29
25
|
}
|
30
26
|
end
|
31
|
-
|
32
|
-
def to_s
|
33
|
-
"#{@subject}^#{@verb}=#{@object}"
|
34
|
-
end
|
35
27
|
end
|
36
28
|
end
|
37
29
|
end
|
data/lib/sashite/ggn/actor.rb
CHANGED
@@ -6,22 +6,14 @@ module Sashite
|
|
6
6
|
class Actor
|
7
7
|
PATTERN = /(#{Self::PATTERN}|#{GameplayIntoBase64::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
|
+
Self.valid?(io) ? Self.load : GameplayIntoBase64.load(io)
|
25
17
|
end
|
26
18
|
end
|
27
19
|
end
|
data/lib/sashite/ggn/ally.rb
CHANGED
@@ -3,25 +3,17 @@ require_relative 'null'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module Ally
|
7
7
|
PATTERN = /(#{Boolean::PATTERN}|#{Null::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 : Boolean.load(io)
|
25
17
|
end
|
26
18
|
end
|
27
19
|
end
|
data/lib/sashite/ggn/area.rb
CHANGED
@@ -1,24 +1,16 @@
|
|
1
1
|
module Sashite
|
2
2
|
module GGN
|
3
|
-
|
3
|
+
module Area
|
4
4
|
PATTERN = /(all|furthest_rank|palace|furthest_one-third|nearest_two-thirds)/
|
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
|
data/lib/sashite/ggn/attacked.rb
CHANGED
@@ -3,25 +3,17 @@ require_relative 'null'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module Attacked
|
7
7
|
PATTERN = /(#{Boolean::PATTERN}|#{Null::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 : Boolean.load(io)
|
25
17
|
end
|
26
18
|
end
|
27
19
|
end
|
data/lib/sashite/ggn/boolean.rb
CHANGED
@@ -1,24 +1,16 @@
|
|
1
1
|
module Sashite
|
2
2
|
module GGN
|
3
|
-
|
3
|
+
module Boolean
|
4
4
|
PATTERN = /[ft]/
|
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 == :t
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_s
|
21
|
-
@value.to_s
|
13
|
+
io.to_sym == :t
|
22
14
|
end
|
23
15
|
end
|
24
16
|
end
|
data/lib/sashite/ggn/digit.rb
CHANGED
@@ -3,25 +3,17 @@ require_relative 'zero'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module Digit
|
7
7
|
PATTERN = /(#{Zero::PATTERN}|#{DigitExcludingZero::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
|
+
Zero.valid?(io) ? Zero.load : DigitExcludingZero.load(io)
|
25
17
|
end
|
26
18
|
end
|
27
19
|
end
|
@@ -1,24 +1,16 @@
|
|
1
1
|
module Sashite
|
2
2
|
module GGN
|
3
|
-
|
3
|
+
module DigitExcludingZero
|
4
4
|
PATTERN = /[1-9]/
|
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_i
|
22
14
|
end
|
23
15
|
end
|
24
16
|
end
|
@@ -2,25 +2,17 @@ require_relative 'integer'
|
|
2
2
|
|
3
3
|
module Sashite
|
4
4
|
module GGN
|
5
|
-
|
5
|
+
module Direction
|
6
6
|
PATTERN = /(#{Integer::PATTERN},)*#{Integer::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
|
-
@integers.map &:as_json
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_s
|
23
|
-
@integers.join ','
|
15
|
+
io.split(',').map { |s| Integer.load s }
|
24
16
|
end
|
25
17
|
end
|
26
18
|
end
|
data/lib/sashite/ggn/gameplay.rb
CHANGED
@@ -1,39 +1,19 @@
|
|
1
|
-
require 'sashite-cgh'
|
2
1
|
require_relative 'pattern'
|
3
2
|
|
4
3
|
module Sashite
|
5
4
|
module GGN
|
6
|
-
|
5
|
+
module Gameplay
|
7
6
|
PATTERN = /#{Pattern::PATTERN}(\. #{Pattern::PATTERN})*\./
|
8
7
|
|
9
|
-
def self.valid?
|
10
|
-
|
8
|
+
def self.valid? io
|
9
|
+
io.match("^#{PATTERN}$") &&
|
10
|
+
io.split('. ').sort.join('. ') == io &&
|
11
|
+
io[0..-2].split('. ').uniq.join('. ').concat('.') == io
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
raise ArgumentError unless self.class.valid? str
|
17
|
-
|
18
|
-
@patterns = str[0..-2].split('. ').map { |pattern| Pattern.new pattern }
|
19
|
-
end
|
20
|
-
|
21
|
-
def as_json
|
22
|
-
@patterns.map &:as_json
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_s
|
26
|
-
@patterns.map(&:to_s).join('. ') + '.'
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_cgh
|
30
|
-
Sashite::CGH.parse to_s
|
31
|
-
end
|
32
|
-
|
33
|
-
def dimensions
|
34
|
-
first_pattern = @patterns.fetch 0
|
35
|
-
first_ability = first_pattern.abilities.fetch 0
|
36
|
-
first_ability.verb.dimensions
|
14
|
+
def self.load io
|
15
|
+
raise ArgumentError unless valid? io
|
16
|
+
io[0..-2].split('. ').map { |s| Pattern.load s }
|
37
17
|
end
|
38
18
|
end
|
39
19
|
end
|
@@ -3,25 +3,18 @@ require_relative 'gameplay'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module GameplayIntoBase64
|
7
7
|
PATTERN = /(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?/
|
8
8
|
|
9
|
-
def self.valid?
|
10
|
-
|
9
|
+
def self.valid? io
|
10
|
+
io.match("^#{PATTERN}$") &&
|
11
|
+
Gameplay.valid?(Base64.strict_decode64(io))
|
11
12
|
end
|
12
13
|
|
13
|
-
def
|
14
|
-
raise ArgumentError unless
|
14
|
+
def self.load io
|
15
|
+
raise ArgumentError unless valid? io
|
15
16
|
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def as_json
|
20
|
-
@value.as_json
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_s
|
24
|
-
Base64.strict_encode64 @value.to_s
|
17
|
+
Gameplay.load Base64.strict_decode64(io)
|
25
18
|
end
|
26
19
|
end
|
27
20
|
end
|
data/lib/sashite/ggn/integer.rb
CHANGED
@@ -3,25 +3,17 @@ require_relative 'unsigned_integer'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module Integer
|
7
7
|
PATTERN = /(#{NegativeInteger::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
|
+
NegativeInteger.valid?(io) ? NegativeInteger.load(io) : UnsignedInteger.load(io)
|
25
17
|
end
|
26
18
|
end
|
27
19
|
end
|
@@ -3,25 +3,17 @@ require_relative 'null'
|
|
3
3
|
|
4
4
|
module Sashite
|
5
5
|
module GGN
|
6
|
-
|
6
|
+
module LastMovedActor
|
7
7
|
PATTERN = /(#{Boolean::PATTERN}|#{Null::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 : Boolean.load(io)
|
25
17
|
end
|
26
18
|
end
|
27
19
|
end
|