portable_move_notation 0.2.0 → 1.0.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 +10 -18
- data/lib/portable_move_notation.rb +5 -5
- data/lib/portable_move_notation/action/{dump.rb → dumper.rb} +9 -7
- data/lib/portable_move_notation/action/{load.rb → parser.rb} +2 -2
- data/lib/portable_move_notation/dumper.rb +14 -0
- data/lib/portable_move_notation/parser.rb +13 -0
- metadata +8 -7
- data/lib/portable_move_notation/dump.rb +0 -11
- data/lib/portable_move_notation/load.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea18bccd3175b8aa44c30320449202c692edd0e62f5024b0f1a35a912124f52
|
4
|
+
data.tar.gz: 0d57d166480c1c823b8ef6a6d6d4333947c467eebe3fc8f3386e72a217faaf19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfd09a1595d388851a9e9e286f83abf130005c2a883938a369bee3111fce52631e8b22b79f7f21d3cb9415dc3e09a9b7e9ea8c36724a7eb28072eb76b9af0110
|
7
|
+
data.tar.gz: 6f2be96f2952714b6977d6c2e811a67ef0c4d07fa4b324b5c98b754d8e8572961f74ce6a2c2b27336b57fb7a3145daf54b078d798d737845bacbcc039bc458ee
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Portable Move Notation
|
2
2
|
|
3
|
-
A Ruby interface for data serialization in PMN format.
|
3
|
+
A Ruby interface for data serialization in [PMN](https://developer.sashite.com/specs/portable-move-notation) format.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -27,14 +27,14 @@ require 'portable_move_notation'
|
|
27
27
|
|
28
28
|
# Parse a PMN string
|
29
29
|
|
30
|
-
PortableMoveNotation.
|
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
31
|
|
32
32
|
# Emit some PMN
|
33
33
|
|
34
34
|
some_moves = [
|
35
|
-
[
|
36
|
-
[
|
37
|
-
[
|
35
|
+
[52, 36, 'C:P', nil],
|
36
|
+
[12, 28, 'c:p', nil],
|
37
|
+
[53, 37, 'C:P', nil]
|
38
38
|
]
|
39
39
|
|
40
40
|
PortableMoveNotation.dump(*some_moves) # => '52,36,C:P.12,28,c:p.53,37,C:P'
|
@@ -45,50 +45,42 @@ PortableMoveNotation.dump(*some_moves) # => '52,36,C:P.12,28,c:p.53,37,C:P'
|
|
45
45
|
#### Castling on kingside
|
46
46
|
|
47
47
|
```ruby
|
48
|
-
PortableMoveNotation.
|
48
|
+
PortableMoveNotation.parse('60,62,C:-K;63,61,C:R') # => [[60, 62, 'C:-K', nil, 63, 61, 'C:R', nil]]
|
49
49
|
PortableMoveNotation.dump(*[[[60, 62, 'C:-K', nil], [63, 61, 'C:R', nil]]]) # => '60,62,C:-K;63,61,C:R'
|
50
50
|
```
|
51
51
|
|
52
52
|
#### Promoting a chess pawn into a knight
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
PortableMoveNotation.
|
55
|
+
PortableMoveNotation.parse('12,4,C:P,C:N') # => [[12, 4, 'C:P', 'C:N']]
|
56
56
|
PortableMoveNotation.dump(*[[[12, 4, 'C:P', 'C:N']]]) # => '12,4,C:P,C:N'
|
57
57
|
```
|
58
58
|
|
59
59
|
#### Promoting a shogi pawn
|
60
60
|
|
61
61
|
```ruby
|
62
|
-
PortableMoveNotation.
|
62
|
+
PortableMoveNotation.parse('33,24,S:P,S:+P') # => [[33, 24, 'S:P', 'S:+P']]
|
63
63
|
PortableMoveNotation.dump(*[[[33, 24, 'S:P', 'S:+P']]]) # => '33,24,S:P,S:+P'
|
64
64
|
```
|
65
65
|
|
66
66
|
#### Dropping a shogi pawn
|
67
67
|
|
68
68
|
```ruby
|
69
|
-
PortableMoveNotation.
|
69
|
+
PortableMoveNotation.parse('*,42,S:P') # => [[nil, 42, 'S:P', nil]]
|
70
70
|
PortableMoveNotation.dump(*[[[nil, 42, 'S:P', nil]]]) # => '*,42,S:P'
|
71
71
|
```
|
72
72
|
|
73
73
|
#### Capturing a white chess pawn en passant
|
74
74
|
|
75
75
|
```ruby
|
76
|
-
PortableMoveNotation.
|
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
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'
|
78
78
|
```
|
79
79
|
|
80
|
-
## Contributing
|
81
|
-
|
82
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/sashite/portable_move_notation.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://www.contributor-covenant.org/) code of conduct.
|
83
|
-
|
84
80
|
## License
|
85
81
|
|
86
82
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
87
83
|
|
88
|
-
## Code of Conduct
|
89
|
-
|
90
|
-
Everyone interacting in the PortableMoveNotation project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sashite/portable_move_notation.rb/blob/master/CODE_OF_CONDUCT.md).
|
91
|
-
|
92
84
|
## About Sashite
|
93
85
|
|
94
86
|
The `portable_move_notation` gem is maintained by [Sashite](https://sashite.com/).
|
@@ -3,13 +3,13 @@
|
|
3
3
|
# Portable Move Notation module
|
4
4
|
module PortableMoveNotation
|
5
5
|
def self.dump(*moves)
|
6
|
-
|
6
|
+
Dumper.call(*moves)
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.
|
10
|
-
|
9
|
+
def self.parse(pmn_string)
|
10
|
+
Parser.call(pmn_string)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
require_relative 'portable_move_notation/
|
15
|
-
require_relative 'portable_move_notation/
|
14
|
+
require_relative 'portable_move_notation/dumper'
|
15
|
+
require_relative 'portable_move_notation/parser'
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module PortableMoveNotation
|
4
4
|
module Action
|
5
|
-
class
|
5
|
+
class Dumper
|
6
6
|
def self.call(*unserialized_actions)
|
7
7
|
unserialized_actions.map { |params| new(*params).call }.join(';')
|
8
8
|
end
|
@@ -28,13 +28,15 @@ module PortableMoveNotation
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def call
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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?
|
36
38
|
|
37
|
-
|
39
|
+
[src_square, dst_square, piece_name, piece_hand]
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
module PortableMoveNotation
|
4
4
|
module Action
|
5
|
-
class
|
5
|
+
class Parser
|
6
6
|
def self.call(serialized_actions)
|
7
|
-
serialized_actions.split(';').
|
7
|
+
serialized_actions.split(';').flat_map do |serialized_action|
|
8
8
|
new(serialized_action).call
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PortableMoveNotation
|
4
|
+
class Dumper
|
5
|
+
def self.call(*unserialized_moves)
|
6
|
+
unserialized_moves.map do |move|
|
7
|
+
actions = move.each_slice(4)
|
8
|
+
Action::Dumper.call(*actions)
|
9
|
+
end.join('.')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require_relative 'action/dumper'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PortableMoveNotation
|
4
|
+
class Parser
|
5
|
+
def self.call(serialized_moves_string)
|
6
|
+
serialized_moves_string.split('.').map do |serialized_actions|
|
7
|
+
Action::Parser.call(serialized_actions)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require_relative 'action/parser'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: portable_move_notation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.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-
|
11
|
+
date: 2020-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -122,7 +122,8 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
description: A Ruby interface for data serialization in PMN
|
125
|
+
description: A Ruby interface for data serialization in PMN (Portable Move Notation)
|
126
|
+
format.
|
126
127
|
email: contact@cyril.email
|
127
128
|
executables: []
|
128
129
|
extensions: []
|
@@ -131,10 +132,10 @@ files:
|
|
131
132
|
- LICENSE.md
|
132
133
|
- README.md
|
133
134
|
- lib/portable_move_notation.rb
|
134
|
-
- lib/portable_move_notation/action/
|
135
|
-
- lib/portable_move_notation/action/
|
136
|
-
- lib/portable_move_notation/
|
137
|
-
- lib/portable_move_notation/
|
135
|
+
- lib/portable_move_notation/action/dumper.rb
|
136
|
+
- lib/portable_move_notation/action/parser.rb
|
137
|
+
- lib/portable_move_notation/dumper.rb
|
138
|
+
- lib/portable_move_notation/parser.rb
|
138
139
|
homepage: https://developer.sashite.com/specs/portable-move-notation
|
139
140
|
licenses:
|
140
141
|
- MIT
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module PortableMoveNotation
|
4
|
-
class Load
|
5
|
-
def self.call(serialized_moves)
|
6
|
-
serialized_moves.split('.').map do |serialized_actions|
|
7
|
-
Action::Load.call(serialized_actions)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
require_relative 'action/load'
|