sashite-ggn 0.7.0 → 0.9.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.
@@ -1,171 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sashite
4
- module Ggn
5
- # JSON Schema for General Gameplay Notation (GGN) validation.
6
- #
7
- # This schema defines the structure and constraints for GGN documents,
8
- # which describe pseudo-legal moves in abstract strategy board games.
9
- # GGN is rule-agnostic and focuses exclusively on board-to-board transformations:
10
- # pieces moving, capturing, or transforming on the game board.
11
- #
12
- # The schema has been updated to reflect GGN's focus on board transformations only.
13
- # Hand management, piece drops, and captures-to-hand are outside the scope of GGN.
14
- #
15
- # @example Basic GGN document structure
16
- # {
17
- # "CHESS:K": {
18
- # "e1": {
19
- # "e2": [
20
- # {
21
- # "require": { "e2": "empty" },
22
- # "perform": { "e1": null, "e2": "CHESS:K" }
23
- # }
24
- # ]
25
- # }
26
- # }
27
- # }
28
- #
29
- # @example Complex move with multiple conditions
30
- # {
31
- # "CHESS:P": {
32
- # "d5": {
33
- # "e6": [
34
- # {
35
- # "require": { "e5": "chess:p", "e6": "empty" },
36
- # "perform": { "d5": null, "e5": null, "e6": "CHESS:P" }
37
- # }
38
- # ]
39
- # }
40
- # }
41
- # }
42
- #
43
- # @example Multi-square move (castling)
44
- # {
45
- # "CHESS:K": {
46
- # "e1": {
47
- # "g1": [
48
- # {
49
- # "require": { "f1": "empty", "g1": "empty", "h1": "CHESS:R" },
50
- # "perform": { "e1": null, "f1": "CHESS:R", "g1": "CHESS:K", "h1": null }
51
- # }
52
- # ]
53
- # }
54
- # }
55
- # }
56
- #
57
- # @see https://sashite.dev/documents/ggn/1.0.0/ GGN Specification
58
- # @see https://sashite.dev/schemas/ggn/1.0.0/schema.json JSON Schema URL
59
- Schema = {
60
- # JSON Schema meta-information
61
- "$schema": "https://json-schema.org/draft/2020-12/schema",
62
- "$id": "https://sashite.dev/schemas/ggn/1.0.0/schema.json",
63
- "title": "General Gameplay Notation (GGN)",
64
- "description": "JSON Schema for pseudo-legal moves in abstract board games using the GGN format. GGN focuses exclusively on board-to-board transformations.",
65
- "type": "object",
66
-
67
- # Optional schema reference property
68
- "properties": {
69
- # Allows documents to self-reference the schema
70
- "$schema": {
71
- "type": "string",
72
- "format": "uri"
73
- }
74
- },
75
-
76
- # Pattern-based validation for GAN (General Actor Notation) identifiers
77
- # Matches format: GAME:piece_char (e.g., "CHESS:K'", "shogi:+p", "XIANGQI:E")
78
- "patternProperties": {
79
- # GAN pattern: game identifier (with casing) + colon + piece identifier
80
- # Supports prefixes (-/+), suffixes ('), and both uppercase/lowercase games
81
- "^([A-Z]+:[-+]?[A-Z][']?|[a-z]+:[-+]?[a-z][']?)$": {
82
- "type": "object",
83
- "minProperties": 1,
84
-
85
- # Source squares: where the piece starts (regular board squares only)
86
- "patternProperties": {
87
- ".+": {
88
- "type": "object",
89
- "minProperties": 1,
90
-
91
- # Destination squares: where the piece can move to (regular board squares only)
92
- "patternProperties": {
93
- ".+": {
94
- "type": "array",
95
- "minItems": 1,
96
-
97
- # Array of conditional transitions for this source->destination pair
98
- "items": {
99
- "type": "object",
100
- "properties": {
101
- # Conditions that MUST be satisfied before the move (logical AND)
102
- "require": {
103
- "type": "object",
104
- "minProperties": 1,
105
- "patternProperties": {
106
- ".+": {
107
- "type": "string",
108
- # Occupation states: "empty", "enemy", or exact GAN identifier
109
- "pattern": "^(empty|enemy|[A-Z]+:[-+]?[A-Z][']?|[a-z]+:[-+]?[a-z][']?)$"
110
- }
111
- },
112
- "additionalProperties": false
113
- },
114
-
115
- # Conditions that MUST NOT be satisfied before the move (logical OR)
116
- "prevent": {
117
- "type": "object",
118
- "minProperties": 1,
119
- "patternProperties": {
120
- ".+": {
121
- "type": "string",
122
- # Same occupation states as require
123
- "pattern": "^(empty|enemy|[A-Z]+:[-+]?[A-Z][']?|[a-z]+:[-+]?[a-z][']?)$"
124
- }
125
- },
126
- "additionalProperties": false
127
- },
128
-
129
- # Board state changes after the move (REQUIRED field)
130
- # This is the core of GGN: describing board transformations
131
- "perform": {
132
- "type": "object",
133
- "minProperties": 1,
134
- "patternProperties": {
135
- ".+": {
136
- "anyOf": [
137
- {
138
- # Square contains a piece (GAN identifier)
139
- "type": "string",
140
- "pattern": "^([A-Z]+:[-+]?[A-Z][']?|[a-z]+:[-+]?[a-z][']?)$"
141
- },
142
- {
143
- # Square becomes empty (null)
144
- "type": "null"
145
- }
146
- ]
147
- }
148
- },
149
- "additionalProperties": false
150
- }
151
- },
152
-
153
- # Only "perform" is mandatory; "require" and "prevent" are optional
154
- # NOTE: "gain" and "drop" fields are no longer supported in GGN
155
- "required": ["perform"],
156
- "additionalProperties": false
157
- }
158
- }
159
- },
160
- "additionalProperties": false
161
- }
162
- },
163
- "additionalProperties": false
164
- }
165
- },
166
-
167
- # No additional properties allowed at root level (strict validation)
168
- "additionalProperties": false
169
- }.freeze
170
- end
171
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sashite
4
- module Ggn
5
- # Custom exception class for GGN validation and processing errors.
6
- #
7
- # This exception is raised when GGN documents fail validation against
8
- # the JSON Schema, contain malformed data, or encounter processing errors
9
- # during parsing and evaluation of pseudo-legal moves.
10
- #
11
- # Since GGN focuses exclusively on board-to-board transformations, validation
12
- # errors typically relate to:
13
- # - Invalid board position representations
14
- # - Malformed GAN identifiers or square labels
15
- # - Logical contradictions in require/prevent conditions
16
- # - Missing or invalid perform actions
17
- #
18
- # Common scenarios that raise ValidationError:
19
- # - Invalid JSON syntax in GGN files
20
- # - Schema validation failures (missing required fields, invalid patterns)
21
- # - File system errors (file not found, permission denied)
22
- # - Malformed GAN identifiers or square labels
23
- # - Logical contradictions in require/prevent conditions
24
- # - Invalid board transformation specifications
25
- #
26
- # @example Handling validation errors during file loading
27
- # begin
28
- # piece_data = Sashite::Ggn.load_file('invalid_moves.json')
29
- # rescue Sashite::Ggn::ValidationError => e
30
- # puts "GGN validation failed: #{e.message}"
31
- # # Handle the error appropriately
32
- # end
33
- #
34
- # @example Handling validation errors during move evaluation
35
- # begin
36
- # transitions = engine.where(board_state, 'CHESS')
37
- # rescue Sashite::Ggn::ValidationError => e
38
- # puts "Move evaluation failed: #{e.message}"
39
- # # Handle invalid board state or parameters
40
- # end
41
- #
42
- # @example Handling schema validation errors
43
- # begin
44
- # Sashite::Ggn.validate!(ggn_data)
45
- # rescue Sashite::Ggn::ValidationError => e
46
- # puts "Schema validation failed: #{e.message}"
47
- # # The data doesn't conform to GGN specification
48
- # end
49
- #
50
- # @see Sashite::Ggn.load_file Main method that can raise this exception
51
- # @see Sashite::Ggn.validate! Schema validation method
52
- # @see Sashite::Ggn::Schema JSON Schema used for validation
53
- class ValidationError < ::StandardError
54
- end
55
- end
56
- end