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.
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
- # result = engine.evaluate(board_state, {}, "CHESS")
37
+ # transitions = engine.where(board_state, "CHESS")
34
38
  #
35
- # if result
39
+ # if transitions.any?
40
+ # transition = transitions.first
36
41
  # puts "Move is valid!"
37
- # puts "Board changes: #{result.diff}"
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 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.select("SHOGI:P").from("*").to("5e")
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
- # # Current board state (5th file is clear of unpromoted pawns)
53
+ # # Board with pawn ready to promote
54
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
55
+ # "e7" => "CHESS:P", # White pawn on 7th rank
56
+ # "e8" => nil # Empty promotion square
58
57
  # }
59
58
  #
60
- # result = engine.evaluate(board_state, captures, "SHOGI")
59
+ # transitions = engine.where(board_state, "CHESS")
61
60
  #
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"
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 Captures with piece promotion
69
- # # A chess pawn capturing and promoting to queen
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:P").from("g7").to("h8")
70
+ # engine = piece_data.select("CHESS:K").from("e1").to("g1")
72
71
  #
73
- # # Board with enemy piece on h8
72
+ # # Board state allowing kingside castling
74
73
  # board_state = {
75
- # "g7" => "CHESS:P", # Our pawn ready to promote
76
- # "h8" => "chess:r" # Enemy rook (lowercase = opponent)
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
- # result = engine.evaluate(board_state, {}, "CHESS")
80
+ # transitions = engine.where(board_state, "CHESS")
80
81
  #
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_)
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.5.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 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.
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) parser and validator for Ruby
75
+ summary: General Gameplay Notation (GGN) library for board-to-board game transformations
75
76
  test_files: []