feen 3.0.0 → 4.0.1
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 +9 -26
- data/lib/feen.rb +33 -41
- data/lib/feen/dumper.rb +22 -26
- data/lib/feen/dumper/in_hand.rb +27 -0
- data/lib/feen/dumper/{board.rb → square.rb} +3 -3
- data/lib/feen/dumper/turn.rb +4 -5
- data/lib/feen/parser.rb +20 -33
- data/lib/feen/parser/in_hand.rb +27 -0
- data/lib/feen/parser/{board.rb → square.rb} +4 -4
- data/lib/feen/parser/turn.rb +3 -3
- metadata +7 -7
- data/lib/feen/dumper/pieces_in_hand.rb +0 -36
- data/lib/feen/parser/pieces_in_hand.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a033acfb60b8db7f259e6e787c71c6e9cae62ef3127faeddfec5c881e9a0171
|
4
|
+
data.tar.gz: f62cf07a12178a848df661c9a695bc7eb9c8adcac1ea399c252f7c4d9aee77af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d96c233e0adb0998281b40e8b282526275ace24c53d9200fffd66907617b0b905d34c592ad7f45659d3f8df9dfa64e738c825c2582b6e5d18da443008a2ae348
|
7
|
+
data.tar.gz: 443ec302a41d65bc96ca9605edc8d3b2f8fbfd323d042da95a3d783c86f7af301389d8d61f9e1114ec019084d94afe1af8602a70e9b4511ce6a8df177e8f6b82
|
data/README.md
CHANGED
@@ -38,39 +38,22 @@ require "feen"
|
|
38
38
|
|
39
39
|
# Dump a classic Tsume Shogi problem
|
40
40
|
FEEN.dump(
|
41
|
-
"
|
42
|
-
"
|
41
|
+
"in_hand": %w[S r r b g g g g s n n n n p p p p p p p p p p p p p p p p p],
|
42
|
+
"shape": [9, 9],
|
43
|
+
"side_id": 0,
|
44
|
+
"square": {
|
43
45
|
3 => "s",
|
44
|
-
4 => "k"
|
46
|
+
4 => "k",
|
45
47
|
5 => "s",
|
46
48
|
22 => "+P",
|
47
49
|
43 => "+B"
|
48
|
-
}
|
49
|
-
"indexes": [9, 9],
|
50
|
-
"pieces_in_hand_grouped_by_sides": [
|
51
|
-
%w[S],
|
52
|
-
%w[r r b g g g g s n n n n p p p p p p p p p p p p p p p p p]
|
53
|
-
]
|
50
|
+
}
|
54
51
|
)
|
55
|
-
# => "3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S
|
52
|
+
# => "3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s"
|
56
53
|
|
57
54
|
# Parse a classic Tsume Shogi problem
|
58
|
-
FEEN.parse("3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S
|
59
|
-
# => {
|
60
|
-
# "active_side_id": 0,
|
61
|
-
# "board": {
|
62
|
-
# 3 => "s",
|
63
|
-
# 4 => "k" ,
|
64
|
-
# 5 => "s",
|
65
|
-
# 22 => "+P",
|
66
|
-
# 43 => "+B"
|
67
|
-
# },
|
68
|
-
# "indexes": [9, 9],
|
69
|
-
# "pieces_in_hand_grouped_by_sides": [
|
70
|
-
# %w[S],
|
71
|
-
# %w[r r b g g g g s n n n n p p p p p p p p p p p p p p p p p]
|
72
|
-
# ]
|
73
|
-
# }
|
55
|
+
FEEN.parse("3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s")
|
56
|
+
# => {:square=>{3=>"s", 4=>"k", 5=>"s", 22=>"+P", 43=>"+B"}, :shape=>[9, 9], :in_hand=>["S", "b", "g", "g", "g", "g", "n", "n", "n", "n", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "r", "r", "s"], :side_id=>0}
|
74
57
|
```
|
75
58
|
|
76
59
|
## License
|
data/lib/feen.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "feen
|
4
|
-
require_relative "feen
|
3
|
+
require_relative File.join("feen", "dumper")
|
4
|
+
require_relative File.join("feen", "parser")
|
5
5
|
|
6
6
|
# This module provides a Ruby interface for data serialization and
|
7
7
|
# deserialization in FEEN format.
|
@@ -10,37 +10,33 @@ require_relative "feen/parser"
|
|
10
10
|
module FEEN
|
11
11
|
# @example Dumps position params into a FEEN string.
|
12
12
|
#
|
13
|
-
# @param
|
14
|
-
# @param
|
15
|
-
# @param
|
16
|
-
# @param
|
17
|
-
# grouped by players.
|
13
|
+
# @param in_hand [Array] The list of pieces in hand.
|
14
|
+
# @param shape [Array] The shape of the board.
|
15
|
+
# @param side_id [Integer] The identifier of the player who must play.
|
16
|
+
# @param square [Hash] The index of each piece on the board.
|
18
17
|
#
|
19
18
|
# @example Dump a classic Tsume Shogi problem
|
20
19
|
# dump(
|
21
|
-
# "
|
22
|
-
# "
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# %w[S],
|
32
|
-
# %w[r r b g g g g s n n n n p p p p p p p p p p p p p p p p p]
|
33
|
-
# ]
|
20
|
+
# "in_hand": %w[S r r b g g g g s n n n n p p p p p p p p p p p p p p p p p],
|
21
|
+
# "shape": [9, 9],
|
22
|
+
# "side_id": 0,
|
23
|
+
# "square": {
|
24
|
+
# 3 => "s",
|
25
|
+
# 4 => "k",
|
26
|
+
# 5 => "s",
|
27
|
+
# 22 => "+P",
|
28
|
+
# 43 => "+B"
|
29
|
+
# }
|
34
30
|
# )
|
35
|
-
# # => "3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S
|
31
|
+
# # => "3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s"
|
36
32
|
#
|
37
33
|
# @return [String] The FEEN string representing the position.
|
38
|
-
def self.dump(
|
34
|
+
def self.dump(in_hand:, shape:, side_id:, square:)
|
39
35
|
Dumper.call(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
in_hand: in_hand,
|
37
|
+
shape: shape,
|
38
|
+
side_id: side_id,
|
39
|
+
square: square
|
44
40
|
)
|
45
41
|
end
|
46
42
|
|
@@ -49,22 +45,18 @@ module FEEN
|
|
49
45
|
# @param feen [String] The FEEN string representing a position.
|
50
46
|
#
|
51
47
|
# @example Parse a classic Tsume Shogi problem
|
52
|
-
# parse("3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S
|
48
|
+
# parse("3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s")
|
53
49
|
# # => {
|
54
|
-
# # "
|
55
|
-
# # "
|
56
|
-
# #
|
57
|
-
# #
|
58
|
-
# #
|
59
|
-
# #
|
60
|
-
# #
|
61
|
-
# #
|
62
|
-
# #
|
63
|
-
# #
|
64
|
-
# # %w[S],
|
65
|
-
# # %w[r r b g g g g s n n n n p p p p p p p p p p p p p p p p p]
|
66
|
-
# # ]
|
67
|
-
# # }
|
50
|
+
# # "in_hand": ["S", "b", "g", "g", "g", "g", "n", "n", "n", "n", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "r", "r", "s"],
|
51
|
+
# # "shape": [9, 9],
|
52
|
+
# # "side_id": 0,
|
53
|
+
# # "square": {
|
54
|
+
# # 3 => "s",
|
55
|
+
# # 4 => "k",
|
56
|
+
# # 5 => "s",
|
57
|
+
# # 22 => "+P",
|
58
|
+
# # 43 => "+B"
|
59
|
+
# # }
|
68
60
|
#
|
69
61
|
# @return [Hash] The position params representing the position.
|
70
62
|
def self.parse(feen)
|
data/lib/feen/dumper.rb
CHANGED
@@ -1,44 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "dumper
|
4
|
-
require_relative "dumper
|
5
|
-
require_relative "dumper
|
3
|
+
require_relative File.join("dumper", "in_hand")
|
4
|
+
require_relative File.join("dumper", "square")
|
5
|
+
require_relative File.join("dumper", "turn")
|
6
6
|
|
7
7
|
module FEEN
|
8
8
|
# The dumper module.
|
9
9
|
module Dumper
|
10
10
|
# Dump position params into a FEEN string.
|
11
11
|
#
|
12
|
-
# @param
|
13
|
-
# @param
|
14
|
-
# @param
|
15
|
-
# @param
|
16
|
-
# grouped by players.
|
12
|
+
# @param in_hand [Array] The list of pieces in hand.
|
13
|
+
# @param shape [Array] The shape of the board.
|
14
|
+
# @param side_id [Integer] The identifier of the player who must play.
|
15
|
+
# @param square [Hash] The index of each piece on the board.
|
17
16
|
#
|
18
17
|
# @example Dump a classic Tsume Shogi problem
|
19
18
|
# call(
|
20
|
-
# "
|
21
|
-
# "
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# %w[S],
|
31
|
-
# %w[r r b g g g g s n n n n p p p p p p p p p p p p p p p p p]
|
32
|
-
# ]
|
19
|
+
# "in_hand": %w[S r r b g g g g s n n n n p p p p p p p p p p p p p p p p p],
|
20
|
+
# "shape": [9, 9],
|
21
|
+
# "side_id": 0,
|
22
|
+
# "square": {
|
23
|
+
# 3 => "s",
|
24
|
+
# 4 => "k",
|
25
|
+
# 5 => "s",
|
26
|
+
# 22 => "+P",
|
27
|
+
# 43 => "+B"
|
28
|
+
# }
|
33
29
|
# )
|
34
|
-
# # => "3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S
|
30
|
+
# # => "3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s"
|
35
31
|
#
|
36
32
|
# @return [String] The FEEN string representing the position.
|
37
|
-
def self.call(
|
33
|
+
def self.call(in_hand:, shape:, side_id:, square:)
|
38
34
|
[
|
39
|
-
|
40
|
-
Turn.dump(
|
41
|
-
|
35
|
+
Square.new(shape, square).to_s,
|
36
|
+
Turn.dump(side_id),
|
37
|
+
InHand.dump(in_hand)
|
42
38
|
].join(" ")
|
43
39
|
end
|
44
40
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FEEN
|
4
|
+
module Dumper
|
5
|
+
# The pieces in hand module.
|
6
|
+
module InHand
|
7
|
+
# Serialize pieces in hand lists into a string.
|
8
|
+
#
|
9
|
+
# @param piece_names [Array] A list of pieces in hand.
|
10
|
+
#
|
11
|
+
# @example Dump a list of pieces in hand
|
12
|
+
# dump(["S", "b", "g", "g", "g", "g", "n", "n", "n", "n", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "r", "r", "s"])
|
13
|
+
# # => "S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s"
|
14
|
+
#
|
15
|
+
# @example Dump an empty list of pieces in hand
|
16
|
+
# dump([])
|
17
|
+
# # => "-"
|
18
|
+
#
|
19
|
+
# @return [String] A string representing the pieces in hand.
|
20
|
+
def self.dump(piece_names)
|
21
|
+
return "-" if piece_names.empty?
|
22
|
+
|
23
|
+
piece_names.sort.join("/")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module FEEN
|
4
4
|
module Dumper
|
5
|
-
# The
|
5
|
+
# The square class.
|
6
6
|
#
|
7
7
|
# @example Dump an empty board of Xiangqi
|
8
8
|
# Board.new([10, 9]).to_s # => "9/9/9/9/9/9/9/9/9/9"
|
@@ -45,9 +45,9 @@ module FEEN
|
|
45
45
|
# 89 => "俥"
|
46
46
|
# }
|
47
47
|
# ).to_s # => "車,馬,象,士,將,士,象,馬,車/9/1,砲,5,砲,1/卒,1,卒,1,卒,1,卒,1,卒/9/9/兵,1,兵,1,兵,1,兵,1,兵/1,炮,5,炮,1/9/俥,傌,相,仕,帥,仕,相,傌,俥"
|
48
|
-
class
|
48
|
+
class Square
|
49
49
|
# @param indexes [Array] The shape of the board.
|
50
|
-
# @param board [Hash] The
|
50
|
+
# @param board [Hash] The index of each piece on the board.
|
51
51
|
def initialize(indexes, board)
|
52
52
|
@indexes = indexes
|
53
53
|
@squares = Array.new(length) { |i| board.fetch(i, nil) }
|
data/lib/feen/dumper/turn.rb
CHANGED
@@ -4,15 +4,14 @@ module FEEN
|
|
4
4
|
module Dumper
|
5
5
|
# The turn module.
|
6
6
|
module Turn
|
7
|
-
# @param
|
8
|
-
# @param sides_count [Integer] The number of players.
|
7
|
+
# @param side_id [Integer] The identifier of the active player.
|
9
8
|
#
|
10
9
|
# @example Dump the number that identify the player who have to play
|
11
|
-
# dump(0
|
10
|
+
# dump(0) # => "0"
|
12
11
|
#
|
13
12
|
# @return [String] The number that identify the player who have to play.
|
14
|
-
def self.dump(
|
15
|
-
String(
|
13
|
+
def self.dump(side_id)
|
14
|
+
String(side_id)
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
data/lib/feen/parser.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "parser
|
4
|
-
require_relative "parser
|
5
|
-
require_relative "parser
|
6
|
-
require_relative "parser
|
3
|
+
require_relative File.join("parser", "in_hand")
|
4
|
+
require_relative File.join("parser", "shape")
|
5
|
+
require_relative File.join("parser", "square")
|
6
|
+
require_relative File.join("parser", "turn")
|
7
7
|
|
8
8
|
module FEEN
|
9
9
|
# The parser module.
|
@@ -13,41 +13,28 @@ module FEEN
|
|
13
13
|
# @param feen [String] The FEEN string representing a position.
|
14
14
|
#
|
15
15
|
# @example Parse a classic Tsume Shogi problem
|
16
|
-
# call("3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S
|
16
|
+
# call("3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s")
|
17
17
|
# # => {
|
18
|
-
# # "
|
19
|
-
# # "
|
20
|
-
# #
|
21
|
-
# #
|
22
|
-
# #
|
23
|
-
# #
|
24
|
-
# #
|
25
|
-
# #
|
26
|
-
# #
|
27
|
-
# #
|
28
|
-
# # %w[S],
|
29
|
-
# # %w[r r b g g g g s n n n n p p p p p p p p p p p p p p p p p]
|
30
|
-
# # ]
|
31
|
-
# # }
|
18
|
+
# # "in_hand": ["S", "b", "g", "g", "g", "g", "n", "n", "n", "n", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "r", "r", "s"],
|
19
|
+
# # "shape": [9, 9],
|
20
|
+
# # "side_id": 0,
|
21
|
+
# # "square": {
|
22
|
+
# # 3 => "s",
|
23
|
+
# # 4 => "k",
|
24
|
+
# # 5 => "s",
|
25
|
+
# # 22 => "+P",
|
26
|
+
# # 43 => "+B"
|
27
|
+
# # }
|
32
28
|
#
|
33
29
|
# @return [Hash] The position params representing the position.
|
34
30
|
def self.call(feen)
|
35
|
-
|
36
|
-
end
|
31
|
+
square_str, side_id_str, in_hand_str = feen.split(" ")
|
37
32
|
|
38
|
-
# Parse the FEEN string's three fields and return the position params.
|
39
|
-
#
|
40
|
-
# @param board [String] The flatten board.
|
41
|
-
# @param active_side_id [String] The active side identifier.
|
42
|
-
# @param in_hand [String] The captured actors.
|
43
|
-
#
|
44
|
-
# @return [Hash] The position params representing the position.
|
45
|
-
private_class_method def self.params(board, active_side_id, in_hand)
|
46
33
|
{
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
34
|
+
in_hand: InHand.parse(in_hand_str),
|
35
|
+
shape: Shape.new(square_str).to_a,
|
36
|
+
side_id: Turn.parse(side_id_str),
|
37
|
+
square: Square.new(square_str).to_h
|
51
38
|
}
|
52
39
|
end
|
53
40
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FEEN
|
4
|
+
module Parser
|
5
|
+
# The pieces in hand module.
|
6
|
+
module InHand
|
7
|
+
# The list of pieces in hand grouped by players.
|
8
|
+
#
|
9
|
+
# @param piece_names_str [String] The serialized list of pieces in hand.
|
10
|
+
#
|
11
|
+
# @example Parse a list of serialized pieces in hand
|
12
|
+
# parse("S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s")
|
13
|
+
# # => ["S", "b", "g", "g", "g", "g", "n", "n", "n", "n", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "r", "r", "s"]
|
14
|
+
#
|
15
|
+
# @example Parse an empty list of serialized pieces in hand
|
16
|
+
# parse("-")
|
17
|
+
# # => []
|
18
|
+
#
|
19
|
+
# @return [Array] The list of pieces in hand grouped by players.
|
20
|
+
def self.parse(piece_names_str)
|
21
|
+
return [] if piece_names_str == "-"
|
22
|
+
|
23
|
+
piece_names_str.split(",")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module FEEN
|
4
4
|
module Parser
|
5
|
-
# The
|
5
|
+
# The square class.
|
6
6
|
#
|
7
7
|
# @example Parse a Shogi problem board and return an array
|
8
8
|
# Board.new("3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9").to_a
|
@@ -22,12 +22,12 @@ module FEEN
|
|
22
22
|
# Board.new("3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9").to_h
|
23
23
|
# # => {
|
24
24
|
# # 3 => "s",
|
25
|
-
# # 4 => "k"
|
25
|
+
# # 4 => "k",
|
26
26
|
# # 5 => "s",
|
27
27
|
# # 22 => "+P",
|
28
28
|
# # 43 => "+B"
|
29
29
|
# # }
|
30
|
-
class
|
30
|
+
class Square
|
31
31
|
# @param board [String] The flatten board.
|
32
32
|
def initialize(board)
|
33
33
|
@board = board
|
@@ -40,7 +40,7 @@ module FEEN
|
|
40
40
|
.flat_map { |str| row(str) }
|
41
41
|
end
|
42
42
|
|
43
|
-
# @return [Hash] The
|
43
|
+
# @return [Hash] The index of each piece on the board.
|
44
44
|
def to_h
|
45
45
|
to_a
|
46
46
|
.each_with_index
|
data/lib/feen/parser/turn.rb
CHANGED
@@ -4,15 +4,15 @@ module FEEN
|
|
4
4
|
module Parser
|
5
5
|
# The turn module.
|
6
6
|
module Turn
|
7
|
-
# @param
|
7
|
+
# @param side_id [String] The identifier of bottom-side and
|
8
8
|
# top-side.
|
9
9
|
#
|
10
10
|
# @example Parse the number that identify the player who have to play
|
11
11
|
# parse("0") # => 0
|
12
12
|
#
|
13
13
|
# @return [Integer] The number that identify the player who have to play.
|
14
|
-
def self.parse(
|
15
|
-
Integer(
|
14
|
+
def self.parse(side_id)
|
15
|
+
Integer(side_id)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.1
|
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-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brutal
|
@@ -132,13 +132,13 @@ files:
|
|
132
132
|
- README.md
|
133
133
|
- lib/feen.rb
|
134
134
|
- lib/feen/dumper.rb
|
135
|
-
- lib/feen/dumper/
|
136
|
-
- lib/feen/dumper/
|
135
|
+
- lib/feen/dumper/in_hand.rb
|
136
|
+
- lib/feen/dumper/square.rb
|
137
137
|
- lib/feen/dumper/turn.rb
|
138
138
|
- lib/feen/parser.rb
|
139
|
-
- lib/feen/parser/
|
140
|
-
- lib/feen/parser/pieces_in_hand.rb
|
139
|
+
- lib/feen/parser/in_hand.rb
|
141
140
|
- lib/feen/parser/shape.rb
|
141
|
+
- lib/feen/parser/square.rb
|
142
142
|
- lib/feen/parser/turn.rb
|
143
143
|
homepage: https://developer.sashite.com/specs/forsyth-edwards-expanded-notation
|
144
144
|
licenses:
|
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
155
|
requirements:
|
156
156
|
- - ">="
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
158
|
+
version: 2.7.0
|
159
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
160
|
requirements:
|
161
161
|
- - ">="
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module FEEN
|
4
|
-
module Dumper
|
5
|
-
# The pieces in hand class.
|
6
|
-
#
|
7
|
-
# @example Serialize a list of pieces in hand grouped by sides
|
8
|
-
# PiecesInHand.dump(
|
9
|
-
# %w[S],
|
10
|
-
# %w[r r b g g g g s n n n n p p p p p p p p p p p p p p p p p]
|
11
|
-
# )
|
12
|
-
# # => "S/b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s"
|
13
|
-
class PiecesInHand
|
14
|
-
# Serialize pieces in hand lists into a string.
|
15
|
-
#
|
16
|
-
# @param pieces_in_hand_grouped_by_sides [Array] The list of pieces in hand
|
17
|
-
# grouped by players.
|
18
|
-
#
|
19
|
-
# @return [String] A string representing the pieces in hand of both
|
20
|
-
# players.
|
21
|
-
def self.dump(pieces_in_hand_grouped_by_sides)
|
22
|
-
pieces_in_hand_grouped_by_sides.map { |pieces| new(pieces).to_s }.join("/")
|
23
|
-
end
|
24
|
-
|
25
|
-
# @param pieces [Array] A list of pieces in hand.
|
26
|
-
def initialize(pieces)
|
27
|
-
@pieces = pieces.sort
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [String] A string representing the pieces in hand.
|
31
|
-
def to_s
|
32
|
-
@pieces.join(",")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module FEEN
|
4
|
-
module Parser
|
5
|
-
# The pieces in hand module.
|
6
|
-
module PiecesInHand
|
7
|
-
# The list of pieces in hand grouped by players.
|
8
|
-
#
|
9
|
-
# @param pieces_in_hand_grouped_by_sides_str [String] The serialized list of
|
10
|
-
# pieces in hand grouped by players.
|
11
|
-
#
|
12
|
-
# @example Parse a list of serialized pieces in hand
|
13
|
-
# parse("S/b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s")
|
14
|
-
# # => [
|
15
|
-
# # %w[S],
|
16
|
-
# # %w[b g g g g n n n n p p p p p p p p p p p p p p p p p r r s]
|
17
|
-
# # ]
|
18
|
-
#
|
19
|
-
# @return [Array] The list of pieces in hand grouped by players.
|
20
|
-
def self.parse(pieces_in_hand_grouped_by_sides_str)
|
21
|
-
pieces_in_hand_grouped_by_sides_str
|
22
|
-
.split("/", -1)
|
23
|
-
.map { |pieces_in_hand_str| pieces_in_hand_str.split(",") }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|