sashite-pan 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.
- checksums.yaml +4 -4
- data/README.md +22 -23
- data/lib/sashite/pan/action.rb +10 -0
- data/lib/sashite/pan/dumper.rb +9 -9
- data/lib/sashite/pan/parser.rb +17 -15
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4294266795d470a55b2b4d52b1b07e006791ace8a41491473057f839112a8f7d
|
4
|
+
data.tar.gz: 30063832b6dba93e56ef2c4450581a3a4f24c1e13592b55576b7a391cbfd23fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44ce213800f73cfd3094eb4f0d7f52090dae9a229c533827e2c2840cde605fefd2b515c8839277f85c3e4ee67b4d73245f026aa1810111e55cf739e4689c9ee1
|
7
|
+
data.tar.gz: 8b97bf4eaec6b839ebfb551bce73341033bcfa3702d6b6c01945355aab3d1857d661e48c5a4ea3783fac8540f4537189e0eb4dfb029812373314a473066275c0
|
data/README.md
CHANGED
@@ -20,52 +20,51 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
Working with
|
23
|
+
Working with PAN can be very simple, for example:
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
require 'sashite/pan'
|
27
|
-
```
|
28
27
|
|
29
|
-
|
28
|
+
# Emit a PAN string
|
29
|
+
|
30
|
+
actions = [
|
31
|
+
[52, 36, '♙', nil]
|
32
|
+
]
|
33
|
+
|
34
|
+
Sashite::PAN.dump(*actions) # => '52,36,♙'
|
35
|
+
|
36
|
+
# Parse a PAN string
|
30
37
|
|
31
|
-
```ruby
|
32
38
|
Sashite::PAN.parse('52,36,♙') # => [[52, 36, '♙', nil]]
|
33
|
-
Sashite::PAN.dump([52, 36, '♙', nil]) # => '52,36,♙'
|
34
39
|
```
|
35
40
|
|
36
|
-
|
41
|
+
## Examples
|
37
42
|
|
38
43
|
```ruby
|
39
|
-
|
44
|
+
# Black castles on king-side
|
45
|
+
|
40
46
|
Sashite::PAN.dump([60, 62, '♔', nil], [63, 61, '♖', nil]) # => '60,62,♔;63,61,♖'
|
41
|
-
|
47
|
+
Sashite::PAN.parse('60,62,♔;63,61,♖') # => [[60, 62, '♔', nil], [63, 61, '♖', nil]]
|
42
48
|
|
43
|
-
|
49
|
+
# Promoting a chess pawn into a knight
|
44
50
|
|
45
|
-
```ruby
|
46
|
-
Sashite::PAN.parse('12,4,♘') # => [[12, 4, '♘', nil]]
|
47
51
|
Sashite::PAN.dump([12, 4, '♘', nil]) # => '12,4,♘'
|
48
|
-
|
52
|
+
Sashite::PAN.parse('12,4,♘') # => [[12, 4, '♘', nil]]
|
49
53
|
|
50
|
-
|
54
|
+
# Capturing a rook and promoting a shogi pawn
|
51
55
|
|
52
|
-
```ruby
|
53
|
-
Sashite::PAN.parse('33,24,+P,R') # => [[33, 24, '+P', 'R']]
|
54
56
|
Sashite::PAN.dump([33, 24, '+P', 'R']) # => '33,24,+P,R'
|
55
|
-
|
57
|
+
Sashite::PAN.parse('33,24,+P,R') # => [[33, 24, '+P', 'R']]
|
56
58
|
|
57
|
-
|
59
|
+
# Dropping a shogi pawn
|
58
60
|
|
59
|
-
```ruby
|
60
|
-
Sashite::PAN.parse('*,42,P') # => [[nil, 42, 'P', nil]]
|
61
61
|
Sashite::PAN.dump([nil, 42, 'P', nil]) # => '*,42,P'
|
62
|
-
|
62
|
+
Sashite::PAN.parse('*,42,P') # => [[nil, 42, 'P', nil]]
|
63
63
|
|
64
|
-
|
64
|
+
# Capturing a white chess pawn en passant
|
65
65
|
|
66
|
-
```ruby
|
67
|
-
Sashite::PAN.parse('33,32,♟;32,40,♟') # => [[33, 32, '♟', nil], [32, 40, '♟', nil]]
|
68
66
|
Sashite::PAN.dump([33, 32, '♟', nil], [32, 40, '♟', nil]) # => '33,32,♟;32,40,♟'
|
67
|
+
Sashite::PAN.parse('33,32,♟;32,40,♟') # => [[33, 32, '♟', nil], [32, 40, '♟', nil]]
|
69
68
|
```
|
70
69
|
|
71
70
|
## License
|
data/lib/sashite/pan/dumper.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'action'
|
4
|
+
|
3
5
|
module Sashite
|
4
6
|
module PAN
|
5
7
|
# Dumper class
|
6
|
-
class Dumper
|
7
|
-
def self.call(*
|
8
|
-
|
8
|
+
class Dumper < Action
|
9
|
+
def self.call(*actions)
|
10
|
+
actions.map { |action_items| new(*action_items).call }.join(';')
|
9
11
|
end
|
10
12
|
|
11
|
-
attr_reader :src_square, :dst_square, :piece_name, :piece_hand
|
12
|
-
|
13
13
|
def initialize(src_square, dst_square, piece_name, piece_hand)
|
14
14
|
unless src_square.nil?
|
15
|
-
raise src_square.inspect unless src_square.is_a?(Integer)
|
15
|
+
raise TypeError, src_square.inspect unless src_square.is_a?(Integer)
|
16
16
|
end
|
17
17
|
|
18
|
-
raise dst_square.inspect unless dst_square.is_a?(Integer)
|
19
|
-
raise piece_name.inspect unless piece_name.is_a?(String)
|
18
|
+
raise TypeError, dst_square.inspect unless dst_square.is_a?(Integer)
|
19
|
+
raise TypeError, piece_name.inspect unless piece_name.is_a?(String)
|
20
20
|
|
21
21
|
unless piece_hand.nil?
|
22
|
-
raise piece_hand.inspect unless piece_hand.is_a?(String)
|
22
|
+
raise TypeError, piece_hand.inspect unless piece_hand.is_a?(String)
|
23
23
|
end
|
24
24
|
|
25
25
|
@src_square = (src_square.nil? ? '*' : src_square)
|
data/lib/sashite/pan/parser.rb
CHANGED
@@ -1,31 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'action'
|
4
|
+
|
3
5
|
module Sashite
|
4
6
|
module PAN
|
5
7
|
# Parser class
|
6
|
-
class Parser
|
7
|
-
def self.call(
|
8
|
-
|
8
|
+
class Parser < Action
|
9
|
+
def self.call(pan_string)
|
10
|
+
pan_string.split(';').map do |serialized_action|
|
9
11
|
new(serialized_action).call
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
attr_reader :serialized_action
|
14
|
-
|
15
15
|
def initialize(serialized_action)
|
16
|
-
|
16
|
+
action_args = serialized_action.split(',')
|
17
|
+
src_square = action_args.fetch(0)
|
18
|
+
@src_square = src_square.eql?('*') ? nil : src_square.to_i
|
19
|
+
@dst_square = action_args.fetch(1).to_i
|
20
|
+
@piece_name = action_args.fetch(2)
|
21
|
+
@piece_hand = action_args.fetch(3, nil)
|
17
22
|
end
|
18
23
|
|
19
24
|
def call
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
piece_hand = action_args.fetch(3, nil)
|
27
|
-
|
28
|
-
[src_square, dst_square, piece_name, piece_hand]
|
25
|
+
[
|
26
|
+
src_square,
|
27
|
+
dst_square,
|
28
|
+
piece_name,
|
29
|
+
piece_hand
|
30
|
+
]
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sashite-pan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- README.md
|
134
134
|
- lib/sashite-pan.rb
|
135
135
|
- lib/sashite/pan.rb
|
136
|
+
- lib/sashite/pan/action.rb
|
136
137
|
- lib/sashite/pan/dumper.rb
|
137
138
|
- lib/sashite/pan/parser.rb
|
138
139
|
homepage: https://developer.sashite.com/specs/portable-action-notation
|