sashite-ggn 0.1.0 → 0.3.0

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 (84) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.md +17 -18
  3. data/README.md +356 -506
  4. data/lib/sashite/ggn/piece/source/destination/engine/transition.rb +90 -0
  5. data/lib/sashite/ggn/piece/source/destination/engine.rb +407 -0
  6. data/lib/sashite/ggn/piece/source/destination.rb +65 -0
  7. data/lib/sashite/ggn/piece/source.rb +71 -0
  8. data/lib/sashite/ggn/piece.rb +77 -0
  9. data/lib/sashite/ggn/schema.rb +152 -0
  10. data/lib/sashite/ggn/validation_error.rb +31 -0
  11. data/lib/sashite/ggn.rb +317 -5
  12. data/lib/sashite-ggn.rb +112 -1
  13. metadata +31 -151
  14. data/.gitignore +0 -22
  15. data/.ruby-version +0 -1
  16. data/.travis.yml +0 -3
  17. data/Gemfile +0 -2
  18. data/Rakefile +0 -7
  19. data/VERSION.semver +0 -1
  20. data/lib/sashite/ggn/ability.rb +0 -29
  21. data/lib/sashite/ggn/actor.rb +0 -20
  22. data/lib/sashite/ggn/ally.rb +0 -20
  23. data/lib/sashite/ggn/area.rb +0 -17
  24. data/lib/sashite/ggn/attacked.rb +0 -20
  25. data/lib/sashite/ggn/boolean.rb +0 -17
  26. data/lib/sashite/ggn/digit.rb +0 -20
  27. data/lib/sashite/ggn/digit_excluding_zero.rb +0 -17
  28. data/lib/sashite/ggn/direction.rb +0 -19
  29. data/lib/sashite/ggn/gameplay.rb +0 -20
  30. data/lib/sashite/ggn/gameplay_into_base64.rb +0 -21
  31. data/lib/sashite/ggn/integer.rb +0 -20
  32. data/lib/sashite/ggn/last_moved_actor.rb +0 -20
  33. data/lib/sashite/ggn/maximum_magnitude.rb +0 -20
  34. data/lib/sashite/ggn/name.rb +0 -17
  35. data/lib/sashite/ggn/negative_integer.rb +0 -19
  36. data/lib/sashite/ggn/null.rb +0 -21
  37. data/lib/sashite/ggn/object.rb +0 -28
  38. data/lib/sashite/ggn/occupied.rb +0 -29
  39. data/lib/sashite/ggn/pattern.rb +0 -20
  40. data/lib/sashite/ggn/previous_moves_counter.rb +0 -20
  41. data/lib/sashite/ggn/promotable_into_actors.rb +0 -23
  42. data/lib/sashite/ggn/required.rb +0 -19
  43. data/lib/sashite/ggn/self.rb +0 -21
  44. data/lib/sashite/ggn/square.rb +0 -29
  45. data/lib/sashite/ggn/state.rb +0 -26
  46. data/lib/sashite/ggn/subject.rb +0 -29
  47. data/lib/sashite/ggn/unsigned_integer.rb +0 -20
  48. data/lib/sashite/ggn/unsigned_integer_excluding_zero.rb +0 -20
  49. data/lib/sashite/ggn/verb.rb +0 -33
  50. data/lib/sashite/ggn/zero.rb +0 -21
  51. data/sashite-ggn.gemspec +0 -19
  52. data/test/_test_helper.rb +0 -2
  53. data/test/test_ggn.rb +0 -552
  54. data/test/test_ggn_ability.rb +0 -51
  55. data/test/test_ggn_actor.rb +0 -571
  56. data/test/test_ggn_ally.rb +0 -35
  57. data/test/test_ggn_area.rb +0 -21
  58. data/test/test_ggn_attacked.rb +0 -35
  59. data/test/test_ggn_boolean.rb +0 -21
  60. data/test/test_ggn_digit.rb +0 -21
  61. data/test/test_ggn_digit_excluding_zero.rb +0 -21
  62. data/test/test_ggn_direction.rb +0 -21
  63. data/test/test_ggn_gameplay.rb +0 -557
  64. data/test/test_ggn_gameplay_into_base64.rb +0 -555
  65. data/test/test_ggn_integer.rb +0 -39
  66. data/test/test_ggn_last_moved_actor.rb +0 -35
  67. data/test/test_ggn_maximum_magnitude.rb +0 -39
  68. data/test/test_ggn_name.rb +0 -21
  69. data/test/test_ggn_negative_integer.rb +0 -21
  70. data/test/test_ggn_null.rb +0 -21
  71. data/test/test_ggn_object.rb +0 -33
  72. data/test/test_ggn_occupied.rb +0 -78
  73. data/test/test_ggn_pattern.rb +0 -84
  74. data/test/test_ggn_previous_moves_counter.rb +0 -39
  75. data/test/test_ggn_promotable_into_actors.rb +0 -578
  76. data/test/test_ggn_required.rb +0 -21
  77. data/test/test_ggn_self.rb +0 -21
  78. data/test/test_ggn_square.rb +0 -25
  79. data/test/test_ggn_state.rb +0 -24
  80. data/test/test_ggn_subject.rb +0 -28
  81. data/test/test_ggn_unsigned_integer.rb +0 -39
  82. data/test/test_ggn_unsigned_integer_excluding_zero.rb +0 -25
  83. data/test/test_ggn_verb.rb +0 -27
  84. data/test/test_ggn_zero.rb +0 -21
data/lib/sashite-ggn.rb CHANGED
@@ -1 +1,112 @@
1
- require 'sashite/ggn'
1
+ # frozen_string_literal: true
2
+
3
+ # Sashité - Abstract Strategy Board Games Notation Library
4
+ #
5
+ # This library provides a comprehensive implementation of the General Gameplay Notation (GGN)
6
+ # specification, which is a rule-agnostic, JSON-based format for describing pseudo-legal
7
+ # moves in abstract strategy board games.
8
+ #
9
+ # GGN works alongside other Sashité specifications:
10
+ # - GAN (General Actor Notation): Unique piece identifiers
11
+ # - FEEN (Forsyth-Edwards Enhanced Notation): Board position representation
12
+ # - PMN (Portable Move Notation): Move sequence representation
13
+ #
14
+ # @author Sashité <https://sashite.com/>
15
+ # @version 1.0.0
16
+ # @see https://sashite.dev/documents/ggn/1.0.0/ GGN Specification
17
+ # @see https://github.com/sashite/ggn.rb Official Ruby implementation
18
+ #
19
+ # @example Basic usage with a chess pawn double move
20
+ # # Load GGN data from file
21
+ # require "sashite/ggn"
22
+ #
23
+ # piece_data = Sashite::Ggn.load_file("chess_moves.json")
24
+ # engine = piece_data.fetch("CHESS:P").fetch("e2").fetch("e4")
25
+ #
26
+ # # Check if the move is valid given current board state
27
+ # board_state = {
28
+ # "e2" => "CHESS:P", # White pawn on e2
29
+ # "e3" => nil, # Empty square
30
+ # "e4" => nil # Empty square
31
+ # }
32
+ #
33
+ # result = engine.evaluate(board_state, {}, "CHESS")
34
+ #
35
+ # if result
36
+ # puts "Move is valid!"
37
+ # puts "Board changes: #{result.diff}"
38
+ # # => { "e2" => nil, "e4" => "CHESS:P" }
39
+ # puts "Piece gained: #{result.gain}" # => nil (no capture)
40
+ # puts "Piece dropped: #{result.drop}" # => nil (not a drop move)
41
+ # else
42
+ # puts "Move is not valid under current conditions"
43
+ # end
44
+ #
45
+ # @example Piece drops in Shogi
46
+ # # Shogi allows captured pieces to be dropped back onto the board
47
+ # piece_data = Sashite::Ggn.load_file("shogi_moves.json")
48
+ # engine = piece_data.fetch("SHOGI:P").fetch("*").fetch("5e")
49
+ #
50
+ # # Player has captured pawns available
51
+ # captures = { "SHOGI:P" => 2 }
52
+ #
53
+ # # Current board state (5th file is clear of unpromoted pawns)
54
+ # board_state = {
55
+ # "5e" => nil, # Target square is empty
56
+ # "5a" => nil, "5b" => nil, "5c" => nil, "5d" => nil,
57
+ # "5f" => nil, "5g" => nil, "5h" => nil, "5i" => nil
58
+ # }
59
+ #
60
+ # result = engine.evaluate(board_state, captures, "SHOGI")
61
+ #
62
+ # if result
63
+ # puts "Pawn drop is valid!"
64
+ # puts "Board changes: #{result.diff}" # => { "5e" => "SHOGI:P" }
65
+ # puts "Piece dropped from hand: #{result.drop}" # => "SHOGI:P"
66
+ # end
67
+ #
68
+ # @example Captures with piece promotion
69
+ # # A chess pawn capturing and promoting to queen
70
+ # piece_data = Sashite::Ggn.load_file("chess_moves.json")
71
+ # engine = piece_data.fetch("CHESS:P").fetch("g7").fetch("h8")
72
+ #
73
+ # # Board with enemy piece on h8
74
+ # board_state = {
75
+ # "g7" => "CHESS:P", # Our pawn ready to promote
76
+ # "h8" => "chess:r" # Enemy rook (lowercase = opponent)
77
+ # }
78
+ #
79
+ # result = engine.evaluate(board_state, {}, "CHESS")
80
+ #
81
+ # if result
82
+ # puts "Pawn promotes and captures!"
83
+ # puts "Final position: #{result.diff}"
84
+ # # => { "g7" => nil, "h8" => "CHESS:Q" }
85
+ # puts "Captured piece: #{result.gain}" # => nil (no capture _in hand_)
86
+ # end
87
+ #
88
+ # @example Loading GGN data from different sources
89
+ # # From file
90
+ # piece_data = Sashite::Ggn.load_file("moves.json")
91
+ #
92
+ # # From JSON string
93
+ # json_string = '{"CHESS:K": {"e1": {"e2": [{"perform": {"e1": null, "e2": "CHESS:K"}}]}}}'
94
+ # piece_data = Sashite::Ggn.load_string(json_string)
95
+ #
96
+ # # From Hash
97
+ # ggn_hash = { "CHESS:K" => { "e1" => { "e2" => [{ "perform" => { "e1" => nil, "e2" => "CHESS:K" } }] } } }
98
+ # piece_data = Sashite::Ggn.load_hash(ggn_hash)
99
+ module Sashite
100
+ # Base namespace for all Sashité notation libraries.
101
+ #
102
+ # Sashité provides a comprehensive suite of specifications and implementations
103
+ # for representing abstract strategy board games in a rule-agnostic manner.
104
+ # This allows for unified game engines, cross-game analysis, and hybrid
105
+ # game variants.
106
+ #
107
+ # @see https://sashite.com/ Official Sashité website
108
+ # @see https://sashite.dev/ Developer documentation and specifications
109
+ end
110
+
111
+ # Load the main GGN implementation
112
+ require_relative "sashite/ggn"
metadata CHANGED
@@ -1,144 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashite-ggn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Cyril Wack
8
- autorequire:
7
+ - Cyril Kato
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2014-06-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: bundler
13
+ name: json_schemer
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :development
18
+ version: 2.4.0
19
+ type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '1.6'
27
- - !ruby/object:Gem::Dependency
28
- name: minitest
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '5'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '5'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '10'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '10'
55
- description: A Ruby interface for data serialization in GGN format.
56
- email:
57
- - contact@cyril.io
25
+ version: 2.4.0
26
+ description: A Ruby implementation of the General Gameplay Notation (GGN) specification.
27
+ GGN is a rule-agnostic, JSON-based format for describing pseudo-legal moves in abstract
28
+ strategy board games. This library provides parsing, validation, and evaluation
29
+ capabilities for GGN documents, enabling game engines to work with movement rules
30
+ across different board games including Chess, Shogi, Xiangqi, and custom variants.
31
+ email: contact@cyril.email
58
32
  executables: []
59
33
  extensions: []
60
34
  extra_rdoc_files: []
61
35
  files:
62
- - ".gitignore"
63
- - ".ruby-version"
64
- - ".travis.yml"
65
- - Gemfile
66
36
  - LICENSE.md
67
37
  - README.md
68
- - Rakefile
69
- - VERSION.semver
70
38
  - lib/sashite-ggn.rb
71
39
  - lib/sashite/ggn.rb
72
- - lib/sashite/ggn/ability.rb
73
- - lib/sashite/ggn/actor.rb
74
- - lib/sashite/ggn/ally.rb
75
- - lib/sashite/ggn/area.rb
76
- - lib/sashite/ggn/attacked.rb
77
- - lib/sashite/ggn/boolean.rb
78
- - lib/sashite/ggn/digit.rb
79
- - lib/sashite/ggn/digit_excluding_zero.rb
80
- - lib/sashite/ggn/direction.rb
81
- - lib/sashite/ggn/gameplay.rb
82
- - lib/sashite/ggn/gameplay_into_base64.rb
83
- - lib/sashite/ggn/integer.rb
84
- - lib/sashite/ggn/last_moved_actor.rb
85
- - lib/sashite/ggn/maximum_magnitude.rb
86
- - lib/sashite/ggn/name.rb
87
- - lib/sashite/ggn/negative_integer.rb
88
- - lib/sashite/ggn/null.rb
89
- - lib/sashite/ggn/object.rb
90
- - lib/sashite/ggn/occupied.rb
91
- - lib/sashite/ggn/pattern.rb
92
- - lib/sashite/ggn/previous_moves_counter.rb
93
- - lib/sashite/ggn/promotable_into_actors.rb
94
- - lib/sashite/ggn/required.rb
95
- - lib/sashite/ggn/self.rb
96
- - lib/sashite/ggn/square.rb
97
- - lib/sashite/ggn/state.rb
98
- - lib/sashite/ggn/subject.rb
99
- - lib/sashite/ggn/unsigned_integer.rb
100
- - lib/sashite/ggn/unsigned_integer_excluding_zero.rb
101
- - lib/sashite/ggn/verb.rb
102
- - lib/sashite/ggn/zero.rb
103
- - sashite-ggn.gemspec
104
- - test/_test_helper.rb
105
- - test/test_ggn.rb
106
- - test/test_ggn_ability.rb
107
- - test/test_ggn_actor.rb
108
- - test/test_ggn_ally.rb
109
- - test/test_ggn_area.rb
110
- - test/test_ggn_attacked.rb
111
- - test/test_ggn_boolean.rb
112
- - test/test_ggn_digit.rb
113
- - test/test_ggn_digit_excluding_zero.rb
114
- - test/test_ggn_direction.rb
115
- - test/test_ggn_gameplay.rb
116
- - test/test_ggn_gameplay_into_base64.rb
117
- - test/test_ggn_integer.rb
118
- - test/test_ggn_last_moved_actor.rb
119
- - test/test_ggn_maximum_magnitude.rb
120
- - test/test_ggn_name.rb
121
- - test/test_ggn_negative_integer.rb
122
- - test/test_ggn_null.rb
123
- - test/test_ggn_object.rb
124
- - test/test_ggn_occupied.rb
125
- - test/test_ggn_pattern.rb
126
- - test/test_ggn_previous_moves_counter.rb
127
- - test/test_ggn_promotable_into_actors.rb
128
- - test/test_ggn_required.rb
129
- - test/test_ggn_self.rb
130
- - test/test_ggn_square.rb
131
- - test/test_ggn_state.rb
132
- - test/test_ggn_subject.rb
133
- - test/test_ggn_unsigned_integer.rb
134
- - test/test_ggn_unsigned_integer_excluding_zero.rb
135
- - test/test_ggn_verb.rb
136
- - test/test_ggn_zero.rb
40
+ - lib/sashite/ggn/piece.rb
41
+ - lib/sashite/ggn/piece/source.rb
42
+ - lib/sashite/ggn/piece/source/destination.rb
43
+ - lib/sashite/ggn/piece/source/destination/engine.rb
44
+ - lib/sashite/ggn/piece/source/destination/engine/transition.rb
45
+ - lib/sashite/ggn/schema.rb
46
+ - lib/sashite/ggn/validation_error.rb
137
47
  homepage: https://github.com/sashite/ggn.rb
138
48
  licenses:
139
49
  - MIT
140
- metadata: {}
141
- post_install_message:
50
+ metadata:
51
+ bug_tracker_uri: https://github.com/sashite/ggn.rb/issues
52
+ documentation_uri: https://rubydoc.info/github/sashite/ggn.rb/main
53
+ homepage_uri: https://github.com/sashite/ggn.rb
54
+ source_code_uri: https://github.com/sashite/ggn.rb
55
+ specification_uri: https://sashite.dev/documents/ggn/1.0.0/
56
+ rubygems_mfa_required: 'true'
142
57
  rdoc_options: []
143
58
  require_paths:
144
59
  - lib
@@ -146,49 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
61
  requirements:
147
62
  - - ">="
148
63
  - !ruby/object:Gem::Version
149
- version: '0'
64
+ version: 3.2.0
150
65
  required_rubygems_version: !ruby/object:Gem::Requirement
151
66
  requirements:
152
67
  - - ">="
153
68
  - !ruby/object:Gem::Version
154
69
  version: '0'
155
70
  requirements: []
156
- rubyforge_project:
157
- rubygems_version: 2.2.2
158
- signing_key:
71
+ rubygems_version: 3.6.9
159
72
  specification_version: 4
160
- summary: General Gameplay Notation.
161
- test_files:
162
- - test/_test_helper.rb
163
- - test/test_ggn.rb
164
- - test/test_ggn_ability.rb
165
- - test/test_ggn_actor.rb
166
- - test/test_ggn_ally.rb
167
- - test/test_ggn_area.rb
168
- - test/test_ggn_attacked.rb
169
- - test/test_ggn_boolean.rb
170
- - test/test_ggn_digit.rb
171
- - test/test_ggn_digit_excluding_zero.rb
172
- - test/test_ggn_direction.rb
173
- - test/test_ggn_gameplay.rb
174
- - test/test_ggn_gameplay_into_base64.rb
175
- - test/test_ggn_integer.rb
176
- - test/test_ggn_last_moved_actor.rb
177
- - test/test_ggn_maximum_magnitude.rb
178
- - test/test_ggn_name.rb
179
- - test/test_ggn_negative_integer.rb
180
- - test/test_ggn_null.rb
181
- - test/test_ggn_object.rb
182
- - test/test_ggn_occupied.rb
183
- - test/test_ggn_pattern.rb
184
- - test/test_ggn_previous_moves_counter.rb
185
- - test/test_ggn_promotable_into_actors.rb
186
- - test/test_ggn_required.rb
187
- - test/test_ggn_self.rb
188
- - test/test_ggn_square.rb
189
- - test/test_ggn_state.rb
190
- - test/test_ggn_subject.rb
191
- - test/test_ggn_unsigned_integer.rb
192
- - test/test_ggn_unsigned_integer_excluding_zero.rb
193
- - test/test_ggn_verb.rb
194
- - test/test_ggn_zero.rb
73
+ summary: General Gameplay Notation (GGN) parser and validator for Ruby
74
+ test_files: []
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.2
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.2
data/Gemfile DELETED
@@ -1,2 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new do |t|
5
- end
6
-
7
- task default: :test
data/VERSION.semver DELETED
@@ -1 +0,0 @@
1
- 0.1.0
@@ -1,29 +0,0 @@
1
- require_relative 'subject'
2
- require_relative 'verb'
3
- require_relative 'object'
4
-
5
- module Sashite
6
- module GGN
7
- module Ability
8
- PATTERN = /#{Subject::PATTERN}\^#{Verb::PATTERN}=#{Object::PATTERN}/
9
-
10
- def self.valid? io
11
- !!io.match("^#{PATTERN}$")
12
- end
13
-
14
- def self.load io
15
- raise ArgumentError unless valid? io
16
-
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
20
-
21
- {
22
- subject: subject,
23
- verb: verb,
24
- object: object
25
- }
26
- end
27
- end
28
- end
29
- end
@@ -1,20 +0,0 @@
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? io
10
- !!io.match("^#{PATTERN}$")
11
- end
12
-
13
- def self.load io
14
- raise ArgumentError unless valid? io
15
-
16
- Self.valid?(io) ? Self.load : GameplayIntoBase64.load(io)
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- require_relative 'boolean'
2
- require_relative 'null'
3
-
4
- module Sashite
5
- module GGN
6
- module Ally
7
- PATTERN = /(#{Boolean::PATTERN}|#{Null::PATTERN})/
8
-
9
- def self.valid? io
10
- !!io.match("^#{PATTERN}$")
11
- end
12
-
13
- def self.load io
14
- raise ArgumentError unless valid? io
15
-
16
- Null.valid?(io) ? Null.load : Boolean.load(io)
17
- end
18
- end
19
- end
20
- end
@@ -1,17 +0,0 @@
1
- module Sashite
2
- module GGN
3
- module Area
4
- PATTERN = /(all|furthest_rank|palace|furthest_one-third|nearest_two-thirds)/
5
-
6
- def self.valid? io
7
- !!io.match("^#{PATTERN}$")
8
- end
9
-
10
- def self.load io
11
- raise ArgumentError unless valid? io
12
-
13
- io.to_sym
14
- end
15
- end
16
- end
17
- end
@@ -1,20 +0,0 @@
1
- require_relative 'boolean'
2
- require_relative 'null'
3
-
4
- module Sashite
5
- module GGN
6
- module Attacked
7
- PATTERN = /(#{Boolean::PATTERN}|#{Null::PATTERN})/
8
-
9
- def self.valid? io
10
- !!io.match("^#{PATTERN}$")
11
- end
12
-
13
- def self.load io
14
- raise ArgumentError unless valid? io
15
-
16
- Null.valid?(io) ? Null.load : Boolean.load(io)
17
- end
18
- end
19
- end
20
- end
@@ -1,17 +0,0 @@
1
- module Sashite
2
- module GGN
3
- module Boolean
4
- PATTERN = /[ft]/
5
-
6
- def self.valid? io
7
- !!io.match("^#{PATTERN}$")
8
- end
9
-
10
- def self.load io
11
- raise ArgumentError unless valid? io
12
-
13
- io.to_sym == :t
14
- end
15
- end
16
- end
17
- end
@@ -1,20 +0,0 @@
1
- require_relative 'digit_excluding_zero'
2
- require_relative 'zero'
3
-
4
- module Sashite
5
- module GGN
6
- module Digit
7
- PATTERN = /(#{Zero::PATTERN}|#{DigitExcludingZero::PATTERN})/
8
-
9
- def self.valid? io
10
- !!io.match("^#{PATTERN}$")
11
- end
12
-
13
- def self.load io
14
- raise ArgumentError unless valid? io
15
-
16
- Zero.valid?(io) ? Zero.load : DigitExcludingZero.load(io)
17
- end
18
- end
19
- end
20
- end
@@ -1,17 +0,0 @@
1
- module Sashite
2
- module GGN
3
- module DigitExcludingZero
4
- PATTERN = /[1-9]/
5
-
6
- def self.valid? io
7
- !!io.match("^#{PATTERN}$")
8
- end
9
-
10
- def self.load io
11
- raise ArgumentError unless valid? io
12
-
13
- io.to_i
14
- end
15
- end
16
- end
17
- end
@@ -1,19 +0,0 @@
1
- require_relative 'integer'
2
-
3
- module Sashite
4
- module GGN
5
- module Direction
6
- PATTERN = /(#{Integer::PATTERN},)*#{Integer::PATTERN}/
7
-
8
- def self.valid? io
9
- !!io.match("^#{PATTERN}$")
10
- end
11
-
12
- def self.load io
13
- raise ArgumentError unless valid? io
14
-
15
- io.split(',').map { |s| Integer.load s }
16
- end
17
- end
18
- end
19
- end
@@ -1,20 +0,0 @@
1
- require_relative 'pattern'
2
-
3
- module Sashite
4
- module GGN
5
- module Gameplay
6
- PATTERN = /#{Pattern::PATTERN}(\. #{Pattern::PATTERN})*\./
7
-
8
- def self.valid? io
9
- io.match("^#{PATTERN}$") &&
10
- io.split('. ').sort.join('. ') == io &&
11
- io[0..-2].split('. ').uniq.join('. ').concat('.') == io
12
- end
13
-
14
- def self.load io
15
- raise ArgumentError unless valid? io
16
- io[0..-2].split('. ').map { |s| Pattern.load s }
17
- end
18
- end
19
- end
20
- end
@@ -1,21 +0,0 @@
1
- require 'base64'
2
- require_relative 'gameplay'
3
-
4
- module Sashite
5
- module GGN
6
- module GameplayIntoBase64
7
- PATTERN = /(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?/
8
-
9
- def self.valid? io
10
- io.match("^#{PATTERN}$") &&
11
- Gameplay.valid?(Base64.strict_decode64(io))
12
- end
13
-
14
- def self.load io
15
- raise ArgumentError unless valid? io
16
-
17
- Gameplay.load Base64.strict_decode64(io)
18
- end
19
- end
20
- end
21
- end
@@ -1,20 +0,0 @@
1
- require_relative 'negative_integer'
2
- require_relative 'unsigned_integer'
3
-
4
- module Sashite
5
- module GGN
6
- module Integer
7
- PATTERN = /(#{NegativeInteger::PATTERN}|#{UnsignedInteger::PATTERN})/
8
-
9
- def self.valid? io
10
- !!io.match("^#{PATTERN}$")
11
- end
12
-
13
- def self.load io
14
- raise ArgumentError unless valid? io
15
-
16
- NegativeInteger.valid?(io) ? NegativeInteger.load(io) : UnsignedInteger.load(io)
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- require_relative 'boolean'
2
- require_relative 'null'
3
-
4
- module Sashite
5
- module GGN
6
- module LastMovedActor
7
- PATTERN = /(#{Boolean::PATTERN}|#{Null::PATTERN})/
8
-
9
- def self.valid? io
10
- !!io.match("^#{PATTERN}$")
11
- end
12
-
13
- def self.load io
14
- raise ArgumentError unless valid? io
15
-
16
- Null.valid?(io) ? Null.load : Boolean.load(io)
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- require_relative 'null'
2
- require_relative 'unsigned_integer_excluding_zero'
3
-
4
- module Sashite
5
- module GGN
6
- module MaximumMagnitude
7
- PATTERN = /(#{Null::PATTERN}|#{UnsignedIntegerExcludingZero::PATTERN})/
8
-
9
- def self.valid? io
10
- !!io.match("^#{PATTERN}$")
11
- end
12
-
13
- def self.load io
14
- raise ArgumentError unless valid? io
15
-
16
- Null.valid?(io) ? Null.load : UnsignedIntegerExcludingZero.load(io)
17
- end
18
- end
19
- end
20
- end