sashite-pin 1.0.0 → 1.1.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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -24
  3. data/lib/sashite/pin/piece.rb +4 -18
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a65bc46335f587c689efc712bc26efc23c236ecf4aeaf26ab6fe2a47fc6420a6
4
- data.tar.gz: 5c1cde47d08f270ab0594917001b0427792d5b931a7de60327e59fc6764f53d8
3
+ metadata.gz: 6affbdb49961967a41cadbd94ced4b32f27279d2fbd7fcc06f74fe58e400184b
4
+ data.tar.gz: 5d3ea8362f3d4329cf748f36713d89456e624cc2de0dc238fb784421811e5e81
5
5
  SHA512:
6
- metadata.gz: 0c115d775f83ad50597f66478139720d9b6d1dfe970384d615ea1c25e96427b803dde10581a4349de1c0707064974d6f138ede38de175ed7168c5982482be9ea
7
- data.tar.gz: ed8959e794d0d62ec73697b95a0ed18b19e150f9493e0db57d78c17d7bce1b122723847ef92470f528606eedec10900f3fce32a75360732e628b156da771f0ad
6
+ metadata.gz: 71ef6fc371601e9845b667085eed4222f3bd2e03bcac2d076a653632dd535bd2eb139ca59d3e3e257a9fdb33ba6d1ce7435ea2dafe34efe7423cdbefef5d5ede
7
+ data.tar.gz: 70684742e2d2406f35a6259d34788ad3545880feb5ba407e993544c78da98f4930dbaccd7a1943579061cf8ab26e0737e8e5eb5dad03b55c7b422a314bc19c8c
data/README.md CHANGED
@@ -29,7 +29,7 @@ gem install sashite-pin
29
29
  ## Usage
30
30
 
31
31
  ```ruby
32
- require "sashite-pin"
32
+ require "sashite/pin"
33
33
 
34
34
  # Parse PIN strings into piece objects
35
35
  piece = Sashite::Pin.parse("K") # => #<Pin::Piece letter="K" type="K" player=first>
@@ -45,31 +45,31 @@ Sashite::Pin.valid?("invalid") # => false
45
45
 
46
46
  # State manipulation (returns new immutable instances)
47
47
  enhanced = piece.enhance # => #<Pin::Piece letter="K" type="K" player=first enhanced=true>
48
- enhanced.to_s # => "+K"
48
+ enhanced.to_s # => "+K"
49
49
  diminished = piece.diminish # => #<Pin::Piece letter="K" type="K" player=first diminished=true>
50
- diminished.to_s # => "-K"
50
+ diminished.to_s # => "-K"
51
51
 
52
52
  # Player manipulation
53
53
  flipped = piece.flip # => #<Pin::Piece letter="k" type="K" player=second>
54
- flipped.to_s # => "k"
54
+ flipped.to_s # => "k"
55
55
 
56
56
  # State queries
57
- piece.normal? # => true
58
- enhanced.enhanced? # => true
59
- diminished.diminished? # => true
57
+ piece.normal? # => true
58
+ enhanced.enhanced? # => true
59
+ diminished.diminished? # => true
60
60
 
61
61
  # Type and player comparison
62
62
  king1 = Sashite::Pin.parse("K")
63
63
  king2 = Sashite::Pin.parse("k")
64
64
  queen = Sashite::Pin.parse("Q")
65
65
 
66
- king1.same_type?(king2) # => true (both kings)
67
- king1.same_player?(queen) # => true (both first player)
68
- king1.same_type?(queen) # => false (different types)
66
+ king1.same_type?(king2) # => true (both kings)
67
+ king1.same_player?(queen) # => true (both first player)
68
+ king1.same_type?(queen) # => false (different types)
69
69
 
70
70
  # Functional transformations can be chained
71
71
  pawn = Sashite::Pin.parse("P")
72
- enemy_promoted = pawn.flip.enhance # => "+p" (black promoted pawn)
72
+ enemy_promoted = pawn.flip.enhance # => "+p" (black promoted pawn)
73
73
  ```
74
74
 
75
75
  ## Format Specification
@@ -107,18 +107,18 @@ enemy_promoted = pawn.flip.enhance # => "+p" (black promoted pawn)
107
107
  # Standard pieces
108
108
  king = Sashite::Pin.parse("K") # => white king
109
109
  king.first_player? # => true
110
- king.type # => "K"
110
+ king.type # => "K"
111
111
 
112
112
  # State modifiers for special conditions
113
113
  castling_king = king.enhance # => castling-eligible king
114
- castling_king.to_s # => "+K"
114
+ castling_king.to_s # => "+K"
115
115
 
116
116
  vulnerable_pawn = Sashite::Pin.parse("P").diminish # => en passant vulnerable
117
- vulnerable_pawn.to_s # => "-P"
117
+ vulnerable_pawn.to_s # => "-P"
118
118
 
119
119
  # All piece types
120
120
  pieces = %w[K Q R B N P].map { |type| Sashite::Pin.parse(type) }
121
- black_pieces = pieces.map(&:flip) # Convert to black pieces
121
+ black_pieces = pieces.map(&:flip) # Convert to black pieces
122
122
  ```
123
123
 
124
124
  ### Japanese Chess (Shōgi)
@@ -129,15 +129,15 @@ bishop = Sashite::Pin.parse("B") # => white bishop
129
129
 
130
130
  # Promoted pieces (enhanced state)
131
131
  dragon_king = rook.enhance # => promoted rook (Dragon King)
132
- dragon_king.to_s # => "+R"
132
+ dragon_king.to_s # => "+R"
133
133
 
134
134
  dragon_horse = bishop.enhance # => promoted bishop (Dragon Horse)
135
- dragon_horse.to_s # => "+B"
135
+ dragon_horse.to_s # => "+B"
136
136
 
137
137
  # Promoted pawn
138
138
  pawn = Sashite::Pin.parse("P")
139
139
  tokin = pawn.enhance # => promoted pawn (Tokin)
140
- tokin.to_s # => "+P"
140
+ tokin.to_s # => "+P"
141
141
 
142
142
  # All promotable pieces can use the same pattern
143
143
  promotable = %w[R B S N L P].map { |type| Sashite::Pin.parse(type) }
@@ -152,7 +152,7 @@ pawn = Sashite::Pin.parse("P") # => white Bia (pawn)
152
152
 
153
153
  # Promoted pawns
154
154
  bia_kaew = pawn.enhance # => promoted pawn (Bia Kaew)
155
- bia_kaew.to_s # => "+P"
155
+ bia_kaew.to_s # => "+P"
156
156
 
157
157
  # Makruk pieces
158
158
  makruk_pieces = %w[K M R B N P].map { |type| Sashite::Pin.parse(type) }
@@ -163,12 +163,12 @@ makruk_pieces = %w[K M R B N P].map { |type| Sashite::Pin.parse(type) }
163
163
  # Pieces with positional states
164
164
  general = Sashite::Pin.parse("G") # => red general
165
165
  flying_general = general.enhance # => flying general (special state)
166
- flying_general.to_s # => "+G"
166
+ flying_general.to_s # => "+G"
167
167
 
168
168
  # Soldiers that crossed the river
169
169
  soldier = Sashite::Pin.parse("P")
170
170
  crossed_soldier = soldier.enhance # => soldier with enhanced movement
171
- crossed_soldier.to_s # => "+P"
171
+ crossed_soldier.to_s # => "+P"
172
172
  ```
173
173
 
174
174
  ## API Reference
@@ -298,7 +298,7 @@ end
298
298
  pins = %w[K Q +R B N P k q r +b n -p]
299
299
  analysis = analyze_pieces(pins)
300
300
  puts analysis[:by_player][:first].size # => 6
301
- puts analysis[:promoted] # => 2
301
+ puts analysis[:promoted] # => 2
302
302
  ```
303
303
 
304
304
  ### Move Validation Example
@@ -318,10 +318,10 @@ def can_promote?(piece, target_rank)
318
318
  end
319
319
 
320
320
  pawn = Sashite::Pin.parse("P")
321
- puts can_promote?(pawn, 8) # => true
321
+ puts can_promote?(pawn, 8) # => true
322
322
 
323
323
  promoted_pawn = pawn.enhance
324
- puts can_promote?(promoted_pawn, 8) # => false (already promoted)
324
+ puts can_promote?(promoted_pawn, 8) # => false (already promoted)
325
325
  ```
326
326
 
327
327
  ## Protocol Mapping
@@ -84,7 +84,6 @@ module Sashite
84
84
  else
85
85
  (@diminished ? DIMINISHED_PREFIX : "")
86
86
  end
87
-
88
87
  "#{prefix}#{letter}"
89
88
  end
90
89
 
@@ -231,7 +230,6 @@ module Sashite
231
230
  def state
232
231
  return :enhanced if enhanced?
233
232
  return :diminished if diminished?
234
-
235
233
  :normal
236
234
  end
237
235
 
@@ -243,7 +241,6 @@ module Sashite
243
241
  # king1.same_type?(king2) # K and k => true, K and Q => false
244
242
  def same_type?(other)
245
243
  return false unless other.is_a?(self.class)
246
-
247
244
  type == other.type
248
245
  end
249
246
 
@@ -253,7 +250,6 @@ module Sashite
253
250
  # @return [Boolean] true if same player
254
251
  def same_player?(other)
255
252
  return false unless other.is_a?(self.class)
256
-
257
253
  side == other.side
258
254
  end
259
255
 
@@ -269,24 +265,14 @@ module Sashite
269
265
  diminished? == other.diminished?
270
266
  end
271
267
 
268
+ # Alias for == to ensure Set functionality works correctly
269
+ alias eql? ==
270
+
272
271
  # Custom hash implementation for use in collections
273
272
  #
274
273
  # @return [Integer] hash value
275
274
  def hash
276
- [letter, @enhanced, @diminished].hash
277
- end
278
-
279
- # Custom inspection for debugging
280
- #
281
- # @return [String] detailed string representation
282
- def inspect
283
- modifiers = []
284
- modifiers << "enhanced=true" if enhanced?
285
- modifiers << "diminished=true" if diminished?
286
-
287
- modifier_str = modifiers.empty? ? "" : " #{modifiers.join(' ')}"
288
- player = first_player? ? "first" : "second"
289
- "#<#{self.class.name}:0x#{object_id.to_s(16)} letter='#{letter}' type='#{type}' player=#{player}#{modifier_str}>"
275
+ [self.class, @letter, @enhanced, @diminished].hash
290
276
  end
291
277
 
292
278
  # Validate that the letter is a single ASCII letter
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashite-pin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato