sashite-ggn 0.5.0 → 0.6.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.
- checksums.yaml +4 -4
- data/README.md +31 -14
- data/lib/sashite/ggn/move_validator.rb +97 -69
- data/lib/sashite/ggn/ruleset/source/destination/engine/transition.rb +41 -50
- data/lib/sashite/ggn/ruleset/source/destination/engine.rb +92 -172
- data/lib/sashite/ggn/ruleset/source/destination.rb +53 -7
- data/lib/sashite/ggn/ruleset/source.rb +42 -14
- data/lib/sashite/ggn/ruleset.rb +45 -105
- data/lib/sashite/ggn/schema.rb +96 -77
- data/lib/sashite/ggn/validation_error.rb +26 -1
- data/lib/sashite/ggn.rb +12 -11
- data/lib/sashite-ggn.rb +47 -33
- metadata +7 -6
data/lib/sashite-ggn.rb
CHANGED
@@ -6,6 +6,10 @@
|
|
6
6
|
# specification, which is a rule-agnostic, JSON-based format for describing pseudo-legal
|
7
7
|
# moves in abstract strategy board games.
|
8
8
|
#
|
9
|
+
# GGN focuses exclusively on board-to-board transformations: pieces moving, capturing,
|
10
|
+
# or transforming on the game board. Hand management, drops, and captures-to-hand are
|
11
|
+
# outside the scope of this specification.
|
12
|
+
#
|
9
13
|
# GGN works alongside other Sashité specifications:
|
10
14
|
# - GAN (General Actor Notation): Unique piece identifiers
|
11
15
|
# - FEEN (Forsyth-Edwards Enhanced Notation): Board position representation
|
@@ -30,59 +34,56 @@
|
|
30
34
|
# "e4" => nil # Empty square
|
31
35
|
# }
|
32
36
|
#
|
33
|
-
#
|
37
|
+
# transitions = engine.where(board_state, "CHESS")
|
34
38
|
#
|
35
|
-
# if
|
39
|
+
# if transitions.any?
|
40
|
+
# transition = transitions.first
|
36
41
|
# puts "Move is valid!"
|
37
|
-
# puts "Board changes: #{
|
42
|
+
# puts "Board changes: #{transition.diff}"
|
38
43
|
# # => { "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
44
|
# else
|
42
45
|
# puts "Move is not valid under current conditions"
|
43
46
|
# end
|
44
47
|
#
|
45
|
-
# @example Piece
|
46
|
-
# #
|
47
|
-
# piece_data = Sashite::Ggn.load_file("
|
48
|
-
# engine = piece_data.select("
|
49
|
-
#
|
50
|
-
# # Player has captured pawns available
|
51
|
-
# captures = { "SHOGI:P" => 2 }
|
48
|
+
# @example Piece promotion with multiple variants
|
49
|
+
# # Chess pawn promotion offers multiple choices
|
50
|
+
# piece_data = Sashite::Ggn.load_file("chess_moves.json")
|
51
|
+
# engine = piece_data.select("CHESS:P").from("e7").to("e8")
|
52
52
|
#
|
53
|
-
# #
|
53
|
+
# # Board with pawn ready to promote
|
54
54
|
# board_state = {
|
55
|
-
# "
|
56
|
-
# "
|
57
|
-
# "5f" => nil, "5g" => nil, "5h" => nil, "5i" => nil
|
55
|
+
# "e7" => "CHESS:P", # White pawn on 7th rank
|
56
|
+
# "e8" => nil # Empty promotion square
|
58
57
|
# }
|
59
58
|
#
|
60
|
-
#
|
59
|
+
# transitions = engine.where(board_state, "CHESS")
|
61
60
|
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
# puts "
|
65
|
-
# puts "Piece dropped from hand: #{result.drop}" # => "SHOGI:P"
|
61
|
+
# transitions.each_with_index do |transition, i|
|
62
|
+
# promoted_piece = transition.diff["e8"]
|
63
|
+
# puts "Promotion choice #{i + 1}: #{promoted_piece}"
|
66
64
|
# end
|
65
|
+
# # Output: CHESS:Q, CHESS:R, CHESS:B, CHESS:N
|
67
66
|
#
|
68
|
-
# @example
|
69
|
-
# #
|
67
|
+
# @example Complex multi-square moves like castling
|
68
|
+
# # Castling involves both king and rook movement
|
70
69
|
# piece_data = Sashite::Ggn.load_file("chess_moves.json")
|
71
|
-
# engine = piece_data.select("CHESS:
|
70
|
+
# engine = piece_data.select("CHESS:K").from("e1").to("g1")
|
72
71
|
#
|
73
|
-
# # Board
|
72
|
+
# # Board state allowing kingside castling
|
74
73
|
# board_state = {
|
75
|
-
# "
|
76
|
-
# "
|
74
|
+
# "e1" => "CHESS:K", # King on starting square
|
75
|
+
# "f1" => nil, # Empty square
|
76
|
+
# "g1" => nil, # Empty destination
|
77
|
+
# "h1" => "CHESS:R" # Rook on starting square
|
77
78
|
# }
|
78
79
|
#
|
79
|
-
#
|
80
|
+
# transitions = engine.where(board_state, "CHESS")
|
80
81
|
#
|
81
|
-
# if
|
82
|
-
#
|
83
|
-
# puts "
|
84
|
-
#
|
85
|
-
#
|
82
|
+
# if transitions.any?
|
83
|
+
# transition = transitions.first
|
84
|
+
# puts "Castling is possible!"
|
85
|
+
# puts "Final position: #{transition.diff}"
|
86
|
+
# # => { "e1" => nil, "f1" => "CHESS:R", "g1" => "CHESS:K", "h1" => nil }
|
86
87
|
# end
|
87
88
|
#
|
88
89
|
# @example Loading GGN data from different sources
|
@@ -96,6 +97,19 @@
|
|
96
97
|
# # From Hash
|
97
98
|
# ggn_hash = { "CHESS:K" => { "e1" => { "e2" => [{ "perform" => { "e1" => nil, "e2" => "CHESS:K" } }] } } }
|
98
99
|
# piece_data = Sashite::Ggn.load_hash(ggn_hash)
|
100
|
+
#
|
101
|
+
# @example Generating all possible moves
|
102
|
+
# # Get all pseudo-legal moves for the current position
|
103
|
+
# board_state = {
|
104
|
+
# "e1" => "CHESS:K", "d1" => "CHESS:Q", "a1" => "CHESS:R",
|
105
|
+
# "e2" => "CHESS:P", "d2" => "CHESS:P"
|
106
|
+
# }
|
107
|
+
#
|
108
|
+
# all_moves = piece_data.pseudo_legal_transitions(board_state, "CHESS")
|
109
|
+
#
|
110
|
+
# all_moves.each do |actor, origin, target, transitions|
|
111
|
+
# puts "#{actor}: #{origin} → #{target} (#{transitions.size} variants)"
|
112
|
+
# end
|
99
113
|
module Sashite
|
100
114
|
# Base namespace for all Sashité notation libraries.
|
101
115
|
#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sashite-ggn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
@@ -24,10 +24,11 @@ dependencies:
|
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: 2.4.0
|
26
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
|
28
|
-
strategy board games. This library provides parsing,
|
29
|
-
capabilities for GGN documents,
|
30
|
-
|
27
|
+
GGN is a rule-agnostic, JSON-based format for describing pseudo-legal board-to-board
|
28
|
+
transformations in abstract strategy board games. This library provides parsing,
|
29
|
+
validation, and evaluation capabilities for GGN documents, focusing exclusively
|
30
|
+
on piece movements, captures, and transformations on the game board. Supports Chess,
|
31
|
+
Shogi, Xiangqi, and custom variants without hand management or piece drops.
|
31
32
|
email: contact@cyril.email
|
32
33
|
executables: []
|
33
34
|
extensions: []
|
@@ -71,5 +72,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
72
|
requirements: []
|
72
73
|
rubygems_version: 3.6.9
|
73
74
|
specification_version: 4
|
74
|
-
summary: General Gameplay Notation (GGN)
|
75
|
+
summary: General Gameplay Notation (GGN) library for board-to-board game transformations
|
75
76
|
test_files: []
|