sashite-ggn 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/Rakefile
ADDED
data/VERSION.semver
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/sashite-ggn.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'sashite/ggn'
|
data/lib/sashite/ggn.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'subject'
|
2
|
+
require_relative 'verb'
|
3
|
+
require_relative 'object'
|
4
|
+
|
5
|
+
module Sashite
|
6
|
+
module GGN
|
7
|
+
class Ability
|
8
|
+
PATTERN = /#{Subject::PATTERN}\^#{Verb::PATTERN}=#{Object::PATTERN}/
|
9
|
+
|
10
|
+
def self.valid? str
|
11
|
+
!!str.match("^#{PATTERN}$")
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :subject, :verb, :object
|
15
|
+
|
16
|
+
def initialize str
|
17
|
+
raise ArgumentError unless self.class.valid? str
|
18
|
+
|
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
|
+
{
|
26
|
+
subject: @subject.as_json,
|
27
|
+
verb: @verb.as_json,
|
28
|
+
object: @object.as_json
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
"#{@subject}^#{@verb}=#{@object}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'gameplay_into_base64'
|
2
|
+
require_relative 'self'
|
3
|
+
|
4
|
+
module Sashite
|
5
|
+
module GGN
|
6
|
+
class Actor
|
7
|
+
PATTERN = /(#{Self::PATTERN}|#{GameplayIntoBase64::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 = (Self.valid?(str) ? Self.instance : GameplayIntoBase64.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,28 @@
|
|
1
|
+
require_relative 'boolean'
|
2
|
+
require_relative 'null'
|
3
|
+
|
4
|
+
module Sashite
|
5
|
+
module GGN
|
6
|
+
class Ally
|
7
|
+
PATTERN = /(#{Boolean::PATTERN}|#{Null::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 : Boolean.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,25 @@
|
|
1
|
+
module Sashite
|
2
|
+
module GGN
|
3
|
+
class Area
|
4
|
+
PATTERN = /(all|furthest_rank|palace|furthest_one-third|nearest_two-thirds)/
|
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,28 @@
|
|
1
|
+
require_relative 'boolean'
|
2
|
+
require_relative 'null'
|
3
|
+
|
4
|
+
module Sashite
|
5
|
+
module GGN
|
6
|
+
class Attacked
|
7
|
+
PATTERN = /(#{Boolean::PATTERN}|#{Null::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 : Boolean.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,25 @@
|
|
1
|
+
module Sashite
|
2
|
+
module GGN
|
3
|
+
class Boolean
|
4
|
+
PATTERN = /[ft]/
|
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 == :t
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
@value.to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'digit_excluding_zero'
|
2
|
+
require_relative 'zero'
|
3
|
+
|
4
|
+
module Sashite
|
5
|
+
module GGN
|
6
|
+
class Digit
|
7
|
+
PATTERN = /(#{Zero::PATTERN}|#{DigitExcludingZero::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 : DigitExcludingZero.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,25 @@
|
|
1
|
+
module Sashite
|
2
|
+
module GGN
|
3
|
+
class DigitExcludingZero
|
4
|
+
PATTERN = /[1-9]/
|
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_i
|
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 'integer'
|
2
|
+
|
3
|
+
module Sashite
|
4
|
+
module GGN
|
5
|
+
class Direction
|
6
|
+
PATTERN = /(#{Integer::PATTERN},)*#{Integer::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
|
+
@integers = str.split(',').map { |i| Integer.new(i) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def as_json
|
19
|
+
@integers.map &:as_json
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
@integers.join ','
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'sashite-cgh'
|
2
|
+
require_relative 'pattern'
|
3
|
+
|
4
|
+
module Sashite
|
5
|
+
module GGN
|
6
|
+
class Gameplay
|
7
|
+
PATTERN = /#{Pattern::PATTERN}(\. #{Pattern::PATTERN})*\./
|
8
|
+
|
9
|
+
def self.valid? str
|
10
|
+
!!str.match("^#{PATTERN}$") && str.split('. ').sort.join('. ') == str
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :patterns
|
14
|
+
|
15
|
+
def initialize str
|
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
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require_relative 'gameplay'
|
3
|
+
|
4
|
+
module Sashite
|
5
|
+
module GGN
|
6
|
+
class GameplayIntoBase64
|
7
|
+
PATTERN = /(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?/
|
8
|
+
|
9
|
+
def self.valid? str
|
10
|
+
!!str.match("^#{PATTERN}$") && Gameplay.valid?(Base64.strict_decode64(str))
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize str
|
14
|
+
raise ArgumentError unless self.class.valid? str
|
15
|
+
|
16
|
+
@value = Gameplay.new Base64.strict_decode64(str)
|
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
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'negative_integer'
|
2
|
+
require_relative 'unsigned_integer'
|
3
|
+
|
4
|
+
module Sashite
|
5
|
+
module GGN
|
6
|
+
class Integer
|
7
|
+
PATTERN = /(#{NegativeInteger::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 = (NegativeInteger.valid?(str) ? NegativeInteger.new(str) : 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,28 @@
|
|
1
|
+
require_relative 'boolean'
|
2
|
+
require_relative 'null'
|
3
|
+
|
4
|
+
module Sashite
|
5
|
+
module GGN
|
6
|
+
class LastMovedActor
|
7
|
+
PATTERN = /(#{Boolean::PATTERN}|#{Null::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 : Boolean.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,28 @@
|
|
1
|
+
require_relative 'null'
|
2
|
+
require_relative 'unsigned_integer_excluding_zero'
|
3
|
+
|
4
|
+
module Sashite
|
5
|
+
module GGN
|
6
|
+
class MaximumMagnitude
|
7
|
+
PATTERN = /(#{Null::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 = (Null.valid?(str) ? Null.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
|