feen 3.0.2 → 3.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 +4 -18
- data/lib/feen.rb +13 -13
- data/lib/feen/dumper.rb +9 -9
- data/lib/feen/dumper/pieces_in_hand.rb +3 -3
- data/lib/feen/dumper/turn.rb +3 -3
- data/lib/feen/parser.rb +7 -7
- data/lib/feen/parser/board.rb +1 -1
- data/lib/feen/parser/pieces_in_hand.rb +3 -3
- data/lib/feen/parser/turn.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abb8a5158f3723e03a49a81c8770ac85bde5d0a88386d7fb9a40739736c1fefe
|
4
|
+
data.tar.gz: 43d49d36468e55b84df7020ba7ea5ae5b3b73ed34ca640593e1ba05e094260f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b447df75705569f2017bf8647ea4f6564661e6ea3467343662c16e7a4a68052eddf8952263badbd33c40132e2c4b9323481eecd882ce3be0fc44660a572d0805
|
7
|
+
data.tar.gz: 98db4cc2b5565fcaadd95e3e1f5b3c0facf04560088ac84209daa107000d0a829702a23b31b1544f4b2cb923330eb259c12a585a4da7fa564d87485de96cb915
|
data/README.md
CHANGED
@@ -38,16 +38,16 @@ require "feen"
|
|
38
38
|
|
39
39
|
# Dump a classic Tsume Shogi problem
|
40
40
|
FEEN.dump(
|
41
|
-
"
|
41
|
+
"side_id": 0,
|
42
42
|
"board": {
|
43
43
|
3 => "s",
|
44
|
-
4 => "k"
|
44
|
+
4 => "k",
|
45
45
|
5 => "s",
|
46
46
|
22 => "+P",
|
47
47
|
43 => "+B"
|
48
48
|
},
|
49
49
|
"indexes": [9, 9],
|
50
|
-
"
|
50
|
+
"hands": [
|
51
51
|
%w[S],
|
52
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
53
|
]
|
@@ -56,21 +56,7 @@ FEEN.dump(
|
|
56
56
|
|
57
57
|
# Parse a classic Tsume Shogi problem
|
58
58
|
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")
|
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[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]
|
72
|
-
# ]
|
73
|
-
# }
|
59
|
+
# => {:board=>{3=>"s", 4=>"k", 5=>"s", 22=>"+P", 43=>"+B"}, :indexes=>[9, 9], :hands=>[["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
60
|
```
|
75
61
|
|
76
62
|
## License
|
data/lib/feen.rb
CHANGED
@@ -10,15 +10,15 @@ require_relative "feen/parser"
|
|
10
10
|
module FEEN
|
11
11
|
# @example Dumps position params into a FEEN string.
|
12
12
|
#
|
13
|
-
# @param
|
13
|
+
# @param side_id [Integer] The identifier of the player who must play.
|
14
14
|
# @param board [Hash] The indexes of each piece on the board.
|
15
15
|
# @param indexes [Array] The shape of the board.
|
16
|
-
# @param
|
16
|
+
# @param hands [Array] The list of pieces in hand
|
17
17
|
# grouped by players.
|
18
18
|
#
|
19
19
|
# @example Dump a classic Tsume Shogi problem
|
20
20
|
# dump(
|
21
|
-
# "
|
21
|
+
# "side_id": 0,
|
22
22
|
# "board": {
|
23
23
|
# 3 => "s",
|
24
24
|
# 4 => "k",
|
@@ -26,21 +26,21 @@ module FEEN
|
|
26
26
|
# 22 => "+P",
|
27
27
|
# 43 => "+B"
|
28
28
|
# },
|
29
|
-
# "
|
30
|
-
# "pieces_in_hand_grouped_by_sides": [
|
29
|
+
# "hands": [
|
31
30
|
# %w[S],
|
32
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]
|
33
|
-
# ]
|
32
|
+
# ],
|
33
|
+
# "indexes": [9, 9]
|
34
34
|
# )
|
35
35
|
# # => "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
36
|
#
|
37
37
|
# @return [String] The FEEN string representing the position.
|
38
|
-
def self.dump(
|
38
|
+
def self.dump(board:, hands:, indexes:, side_id:)
|
39
39
|
Dumper.call(
|
40
|
-
active_side_id: active_side_id,
|
41
40
|
board: board,
|
41
|
+
hands: hands,
|
42
42
|
indexes: indexes,
|
43
|
-
|
43
|
+
side_id: side_id
|
44
44
|
)
|
45
45
|
end
|
46
46
|
|
@@ -51,7 +51,7 @@ module FEEN
|
|
51
51
|
# @example Parse a classic Tsume Shogi problem
|
52
52
|
# 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
53
|
# # => {
|
54
|
-
# # "
|
54
|
+
# # "side_id": 0,
|
55
55
|
# # "board": {
|
56
56
|
# # 3 => "s",
|
57
57
|
# # 4 => "k",
|
@@ -59,11 +59,11 @@ module FEEN
|
|
59
59
|
# # 22 => "+P",
|
60
60
|
# # 43 => "+B"
|
61
61
|
# # },
|
62
|
-
# # "
|
63
|
-
# # "pieces_in_hand_grouped_by_sides": [
|
62
|
+
# # "hands": [
|
64
63
|
# # %w[S],
|
65
64
|
# # %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]
|
66
|
-
# # ]
|
65
|
+
# # ],
|
66
|
+
# # "indexes": [9, 9]
|
67
67
|
# # }
|
68
68
|
#
|
69
69
|
# @return [Hash] The position params representing the position.
|
data/lib/feen/dumper.rb
CHANGED
@@ -9,15 +9,14 @@ module FEEN
|
|
9
9
|
module Dumper
|
10
10
|
# Dump position params into a FEEN string.
|
11
11
|
#
|
12
|
-
# @param
|
12
|
+
# @param side_id [Integer] The identifier of the player who must play.
|
13
13
|
# @param board [Hash] The indexes of each piece on the board.
|
14
14
|
# @param indexes [Array] The shape of the board.
|
15
|
-
# @param
|
15
|
+
# @param hands [Array] The list of pieces in hand
|
16
16
|
# grouped by players.
|
17
17
|
#
|
18
18
|
# @example Dump a classic Tsume Shogi problem
|
19
19
|
# call(
|
20
|
-
# "active_side_id": 0,
|
21
20
|
# "board": {
|
22
21
|
# 3 => "s",
|
23
22
|
# 4 => "k",
|
@@ -25,20 +24,21 @@ module FEEN
|
|
25
24
|
# 22 => "+P",
|
26
25
|
# 43 => "+B"
|
27
26
|
# },
|
28
|
-
# "
|
29
|
-
# "pieces_in_hand_grouped_by_sides": [
|
27
|
+
# "hands": [
|
30
28
|
# %w[S],
|
31
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]
|
32
|
-
# ]
|
30
|
+
# ],
|
31
|
+
# "indexes": [9, 9],
|
32
|
+
# "side_id": 0
|
33
33
|
# )
|
34
34
|
# # => "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
35
|
#
|
36
36
|
# @return [String] The FEEN string representing the position.
|
37
|
-
def self.call(
|
37
|
+
def self.call(board:, hands:, indexes:, side_id:)
|
38
38
|
[
|
39
39
|
Board.new(indexes, board).to_s,
|
40
|
-
Turn.dump(
|
41
|
-
PiecesInHand.dump(
|
40
|
+
Turn.dump(side_id, hands.length),
|
41
|
+
PiecesInHand.dump(hands)
|
42
42
|
].join(" ")
|
43
43
|
end
|
44
44
|
end
|
@@ -13,13 +13,13 @@ module FEEN
|
|
13
13
|
class PiecesInHand
|
14
14
|
# Serialize pieces in hand lists into a string.
|
15
15
|
#
|
16
|
-
# @param
|
16
|
+
# @param hands [Array] The list of pieces in hand
|
17
17
|
# grouped by players.
|
18
18
|
#
|
19
19
|
# @return [String] A string representing the pieces in hand of both
|
20
20
|
# players.
|
21
|
-
def self.dump(
|
22
|
-
|
21
|
+
def self.dump(hands)
|
22
|
+
hands.map { |pieces| new(pieces).to_s }.join("/")
|
23
23
|
end
|
24
24
|
|
25
25
|
# @param pieces [Array] A list of pieces in hand.
|
data/lib/feen/dumper/turn.rb
CHANGED
@@ -4,15 +4,15 @@ module FEEN
|
|
4
4
|
module Dumper
|
5
5
|
# The turn module.
|
6
6
|
module Turn
|
7
|
-
# @param
|
7
|
+
# @param side_id [Integer] The identifier of the active player.
|
8
8
|
# @param sides_count [Integer] The number of players.
|
9
9
|
#
|
10
10
|
# @example Dump the number that identify the player who have to play
|
11
11
|
# dump(0, 2) # => "0"
|
12
12
|
#
|
13
13
|
# @return [String] The number that identify the player who have to play.
|
14
|
-
def self.dump(
|
15
|
-
String(Integer(
|
14
|
+
def self.dump(side_id, sides_count)
|
15
|
+
String(Integer(side_id) % Integer(sides_count))
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/feen/parser.rb
CHANGED
@@ -15,7 +15,6 @@ module FEEN
|
|
15
15
|
# @example Parse a classic Tsume Shogi problem
|
16
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
|
-
# # "active_side_id": 0,
|
19
18
|
# # "board": {
|
20
19
|
# # 3 => "s",
|
21
20
|
# # 4 => "k",
|
@@ -23,22 +22,23 @@ module FEEN
|
|
23
22
|
# # 22 => "+P",
|
24
23
|
# # 43 => "+B"
|
25
24
|
# # },
|
26
|
-
# # "
|
27
|
-
# # "pieces_in_hand_grouped_by_sides": [
|
25
|
+
# # "hands": [
|
28
26
|
# # %w[S],
|
29
27
|
# # %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]
|
30
|
-
# # ]
|
28
|
+
# # ],
|
29
|
+
# # "indexes": [9, 9],
|
30
|
+
# # "side_id": 0
|
31
31
|
# # }
|
32
32
|
#
|
33
33
|
# @return [Hash] The position params representing the position.
|
34
34
|
def self.call(feen)
|
35
|
-
board,
|
35
|
+
board, side_id, in_hand = feen.split(" ")
|
36
36
|
|
37
37
|
{
|
38
|
-
active_side_id: Turn.parse(active_side_id),
|
39
38
|
board: Board.new(board).to_h,
|
40
39
|
indexes: Shape.new(board).to_a,
|
41
|
-
|
40
|
+
hands: PiecesInHand.parse(in_hand),
|
41
|
+
side_id: Turn.parse(side_id)
|
42
42
|
}
|
43
43
|
end
|
44
44
|
end
|
data/lib/feen/parser/board.rb
CHANGED
@@ -6,7 +6,7 @@ module FEEN
|
|
6
6
|
module PiecesInHand
|
7
7
|
# The list of pieces in hand grouped by players.
|
8
8
|
#
|
9
|
-
# @param
|
9
|
+
# @param hands_str [String] The serialized list of
|
10
10
|
# pieces in hand grouped by players.
|
11
11
|
#
|
12
12
|
# @example Parse a list of serialized pieces in hand
|
@@ -17,8 +17,8 @@ module FEEN
|
|
17
17
|
# # ]
|
18
18
|
#
|
19
19
|
# @return [Array] The list of pieces in hand grouped by players.
|
20
|
-
def self.parse(
|
21
|
-
|
20
|
+
def self.parse(hands_str)
|
21
|
+
hands_str
|
22
22
|
.split("/", -1)
|
23
23
|
.map { |pieces_in_hand_str| pieces_in_hand_str.split(",") }
|
24
24
|
end
|
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: 3.0
|
4
|
+
version: 3.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-09-
|
11
|
+
date: 2020-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brutal
|
@@ -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
|
- - ">="
|