portable_move_notation 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ea18bccd3175b8aa44c30320449202c692edd0e62f5024b0f1a35a912124f52
4
- data.tar.gz: 0d57d166480c1c823b8ef6a6d6d4333947c467eebe3fc8f3386e72a217faaf19
3
+ metadata.gz: 73a731b3522fb1d2baf81b537a87f984f58606fcdbd248f2f83de88a4b060296
4
+ data.tar.gz: b8d8312a438c55ec0420a473f99ba1a91030f755bc571c80cfd7ecee7b8c2d88
5
5
  SHA512:
6
- metadata.gz: cfd09a1595d388851a9e9e286f83abf130005c2a883938a369bee3111fce52631e8b22b79f7f21d3cb9415dc3e09a9b7e9ea8c36724a7eb28072eb76b9af0110
7
- data.tar.gz: 6f2be96f2952714b6977d6c2e811a67ef0c4d07fa4b324b5c98b754d8e8572961f74ce6a2c2b27336b57fb7a3145daf54b078d798d737845bacbcc039bc458ee
6
+ metadata.gz: 3e476824bb39f33c3531fce025ce31cb301a12a8b08a1b2cdfde8c7513617a2df74fe22f9e98d09d66257334865752218fdf3888cd62bbf4bde3216c03d99a07
7
+ data.tar.gz: b65d9ca2de5d5508d3bafafe1faa1166bde086e5237692a6b2e292d55f8523977f6eb968eb65f9c95df76287a7e8e1e4c707d6cab8fab92d5b18ecffb752677b
data/README.md CHANGED
@@ -25,56 +25,48 @@ Working with PMN can be very simple, for example:
25
25
  ```ruby
26
26
  require 'portable_move_notation'
27
27
 
28
- # Parse a PMN string
29
-
30
- PortableMoveNotation.parse('52,36,C:P.12,28,c:p.53,37,C:P') # => [[52, 36, 'C:P', nil], [12, 28, 'c:p', nil], [53, 37, 'C:P', nil]]
31
-
32
- # Emit some PMN
28
+ # Emit a PMN string
33
29
 
34
30
  some_moves = [
35
- [52, 36, 'C:P', nil],
36
- [12, 28, 'c:p', nil],
37
- [53, 37, 'C:P', nil]
31
+ [52, 36, '', nil],
32
+ [12, 28, '', nil],
33
+ [53, 37, '', nil]
38
34
  ]
39
35
 
40
- PortableMoveNotation.dump(*some_moves) # => '52,36,C:P.12,28,c:p.53,37,C:P'
41
- ```
42
-
43
- ### Other examples
36
+ PortableMoveNotation.dump(*some_moves) # => "52,36,♙.12,28,♟.53,37,♙"
44
37
 
45
- #### Castling on kingside
38
+ # Parse a PMN string
46
39
 
47
- ```ruby
48
- PortableMoveNotation.parse('60,62,C:-K;63,61,C:R') # => [[60, 62, 'C:-K', nil, 63, 61, 'C:R', nil]]
49
- PortableMoveNotation.dump(*[[[60, 62, 'C:-K', nil], [63, 61, 'C:R', nil]]]) # => '60,62,C:-K;63,61,C:R'
40
+ PortableMoveNotation.parse('52,36,♙.12,28,♟.53,37,♙') # => [[52, 36, "♙", nil], [12, 28, "♟", nil], [53, 37, "♙", nil]]
50
41
  ```
51
42
 
52
- #### Promoting a chess pawn into a knight
43
+ ## Examples
53
44
 
54
45
  ```ruby
55
- PortableMoveNotation.parse('12,4,C:P,C:N') # => [[12, 4, 'C:P', 'C:N']]
56
- PortableMoveNotation.dump(*[[[12, 4, 'C:P', 'C:N']]]) # => '12,4,C:P,C:N'
57
- ```
46
+ # Black castles on king-side
58
47
 
59
- #### Promoting a shogi pawn
48
+ PortableMoveNotation.dump([60, 62, '♔', nil, 63, 61, '♖', nil]) # => "60,62,♔;63,61,♖"
49
+ PortableMoveNotation.parse('60,62,♔;63,61,♖') # => [[60, 62, "♔", nil, 63, 61, "♖", nil]]
60
50
 
61
- ```ruby
62
- PortableMoveNotation.parse('33,24,S:P,S:+P') # => [[33, 24, 'S:P', 'S:+P']]
63
- PortableMoveNotation.dump(*[[[33, 24, 'S:P', 'S:+P']]]) # => '33,24,S:P,S:+P'
64
- ```
51
+ # Promoting a chess pawn into a knight
65
52
 
66
- #### Dropping a shogi pawn
53
+ PortableMoveNotation.dump([12, 4, '♘', nil]) # => "12,4,♘"
54
+ PortableMoveNotation.parse('12,4,♘') # => [[12, 4, "♘", nil]]
67
55
 
68
- ```ruby
69
- PortableMoveNotation.parse('*,42,S:P') # => [[nil, 42, 'S:P', nil]]
70
- PortableMoveNotation.dump(*[[[nil, 42, 'S:P', nil]]]) # => '*,42,S:P'
71
- ```
56
+ # Capturing a rook and promoting a shogi pawn
72
57
 
73
- #### Capturing a white chess pawn en passant
58
+ PortableMoveNotation.dump([33, 24, '+P', 'R']) # => "33,24,+P,R"
59
+ PortableMoveNotation.parse('33,24,+P,R') # => [[33, 24, "+P", "R"]]
74
60
 
75
- ```ruby
76
- PortableMoveNotation.parse('48,32,C:P.33,32,c:p;32,40,c:p') # => [[48, 32, 'C:P', nil], [33, 32, 'c:p', nil, 32, 40, 'c:p', nil]]
77
- PortableMoveNotation.dump(*[[[48, 32, 'C:P', nil]], [[33, 32, 'c:p', nil], [32, 40, 'c:p', nil]]]) # => '48,32,C:P.33,32,c:p;32,40,c:p'
61
+ # Dropping a shogi pawn
62
+
63
+ PortableMoveNotation.dump([nil, 42, 'P', nil]) # => "*,42,P"
64
+ PortableMoveNotation.parse('*,42,P') # => [[nil, 42, "P", nil]]
65
+
66
+ # Capturing a white chess pawn en passant
67
+
68
+ PortableMoveNotation.dump([48, 32, '♙', nil], [33, 32, '♟', nil, 32, 40, '♟', nil]) # => "48,32,♙.33,32,♟;32,40,♟"
69
+ PortableMoveNotation.parse('48,32,♙.33,32,♟;32,40,♟') # => [[48, 32, "♙", nil], [33, 32, "♟", nil, 32, 40, "♟", nil]]
78
70
  ```
79
71
 
80
72
  ## License
@@ -3,12 +3,12 @@
3
3
  module PortableMoveNotation
4
4
  class Dumper
5
5
  def self.call(*unserialized_moves)
6
- unserialized_moves.map do |move|
7
- actions = move.each_slice(4)
8
- Action::Dumper.call(*actions)
6
+ unserialized_moves.map do |unserialized_move|
7
+ unserialized_actions = unserialized_move.each_slice(4)
8
+ ::Sashite::PAN::Dumper.call(*unserialized_actions)
9
9
  end.join('.')
10
10
  end
11
11
  end
12
12
  end
13
13
 
14
- require_relative 'action/dumper'
14
+ require 'sashite/pan/dumper'
@@ -3,11 +3,11 @@
3
3
  module PortableMoveNotation
4
4
  class Parser
5
5
  def self.call(serialized_moves_string)
6
- serialized_moves_string.split('.').map do |serialized_actions|
7
- Action::Parser.call(serialized_actions)
6
+ serialized_moves_string.split('.').map do |serialized_actions_string|
7
+ ::Sashite::PAN::Parser.call(serialized_actions_string).flatten(1)
8
8
  end
9
9
  end
10
10
  end
11
11
  end
12
12
 
13
- require_relative 'action/parser'
13
+ require 'sashite/pan/parser'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portable_move_notation
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
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-14 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sashite-pan
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: awesome_print
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -132,8 +146,6 @@ files:
132
146
  - LICENSE.md
133
147
  - README.md
134
148
  - lib/portable_move_notation.rb
135
- - lib/portable_move_notation/action/dumper.rb
136
- - lib/portable_move_notation/action/parser.rb
137
149
  - lib/portable_move_notation/dumper.rb
138
150
  - lib/portable_move_notation/parser.rb
139
151
  homepage: https://developer.sashite.com/specs/portable-move-notation
@@ -143,7 +155,6 @@ metadata:
143
155
  bug_tracker_uri: https://github.com/sashite/portable_move_notation.rb/issues
144
156
  documentation_uri: https://rubydoc.info/gems/portable_move_notation/index
145
157
  source_code_uri: https://github.com/sashite/portable_move_notation.rb
146
- wiki_uri: https://github.com/sashite/portable_move_notation.rb/wiki
147
158
  post_install_message:
148
159
  rdoc_options: []
149
160
  require_paths:
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PortableMoveNotation
4
- module Action
5
- class Dumper
6
- def self.call(*unserialized_actions)
7
- unserialized_actions.map { |params| new(*params).call }.join(';')
8
- end
9
-
10
- attr_reader :src_square, :dst_square, :piece_name, :piece_hand
11
-
12
- def initialize(src_square, dst_square, piece_name, piece_hand)
13
- unless src_square.nil?
14
- raise src_square.inspect unless src_square.is_a?(Integer)
15
- end
16
-
17
- raise dst_square.inspect unless dst_square.is_a?(Integer)
18
- raise piece_name.inspect unless piece_name.is_a?(String)
19
-
20
- unless piece_hand.nil?
21
- raise piece_hand.inspect unless piece_hand.is_a?(String)
22
- end
23
-
24
- @src_square = (src_square.nil? ? '*' : src_square)
25
- @dst_square = dst_square
26
- @piece_name = piece_name
27
- @piece_hand = piece_hand
28
- end
29
-
30
- def call
31
- action_items.join(',')
32
- end
33
-
34
- private
35
-
36
- def action_items
37
- return [src_square, dst_square, piece_name] if piece_hand.nil?
38
-
39
- [src_square, dst_square, piece_name, piece_hand]
40
- end
41
- end
42
- end
43
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PortableMoveNotation
4
- module Action
5
- class Parser
6
- def self.call(serialized_actions)
7
- serialized_actions.split(';').flat_map do |serialized_action|
8
- new(serialized_action).call
9
- end
10
- end
11
-
12
- attr_reader :serialized_action
13
-
14
- def initialize(serialized_action)
15
- @serialized_action = serialized_action
16
- end
17
-
18
- def call
19
- action_args = serialized_action.split(',')
20
-
21
- src_square = action_args.fetch(0)
22
- src_square = src_square.eql?('*') ? nil : src_square.to_i
23
- dst_square = action_args.fetch(1).to_i
24
- piece_name = action_args.fetch(2)
25
- piece_hand = action_args.fetch(3, nil)
26
-
27
- [src_square, dst_square, piece_name, piece_hand]
28
- end
29
- end
30
- end
31
- end