feen 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -10
- data/lib/feen/dumper.rb +2 -2
- data/lib/feen/dumper/board.rb +45 -41
- data/lib/feen/dumper/pieces_in_hand.rb +3 -3
- data/lib/feen/parser/board.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4120730f5c39a876c2dc1bba4536f997b822ddfee043e37cdb1dc68f1ffcbb31
|
4
|
+
data.tar.gz: 3a0365e075d0c0238625d841c78ccb52e21106bc47cc312ce6b1e4e47d08d6b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 202e76081fbe4cbef65fdfa4833d370d7e2310ff6d3498fffa2baf10118afa12c1f15260a2e3f2f2ceecec6a99601b8a5bb89508e5e188583fad5015d944deb5
|
7
|
+
data.tar.gz: c9f8c235a87923c74d7f804535ad740d86eadfebd23c4cfa7756d4a9159a1a30c97874e619bad8e6f84a1def42f500048a6196a44a6f6422918237d4b89d4440
|
data/README.md
CHANGED
@@ -40,11 +40,11 @@ require "feen"
|
|
40
40
|
FEEN.dump(
|
41
41
|
"active_side_id": 0,
|
42
42
|
"board": {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
3 => "s",
|
44
|
+
4 => "k" ,
|
45
|
+
5 => "s",
|
46
|
+
22 => "+P",
|
47
|
+
43 => "+B"
|
48
48
|
},
|
49
49
|
"indexes": [9, 9],
|
50
50
|
"pieces_in_hand_grouped_by_sides": [
|
@@ -59,11 +59,11 @@ 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,
|
|
59
59
|
# => {
|
60
60
|
# "active_side_id": 0,
|
61
61
|
# "board": {
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
62
|
+
# 3 => "s",
|
63
|
+
# 4 => "k" ,
|
64
|
+
# 5 => "s",
|
65
|
+
# 22 => "+P",
|
66
|
+
# 43 => "+B"
|
67
67
|
# },
|
68
68
|
# "indexes": [9, 9],
|
69
69
|
# "pieces_in_hand_grouped_by_sides": [
|
data/lib/feen/dumper.rb
CHANGED
@@ -36,9 +36,9 @@ module FEEN
|
|
36
36
|
# @return [String] The FEEN string representing the position.
|
37
37
|
def self.call(active_side_id:, board:, indexes:, pieces_in_hand_grouped_by_sides:)
|
38
38
|
[
|
39
|
-
Board.new(
|
39
|
+
Board.new(indexes, board).to_s,
|
40
40
|
Turn.dump(active_side_id, pieces_in_hand_grouped_by_sides.length),
|
41
|
-
PiecesInHand.dump(
|
41
|
+
PiecesInHand.dump(pieces_in_hand_grouped_by_sides)
|
42
42
|
].join(" ")
|
43
43
|
end
|
44
44
|
end
|
data/lib/feen/dumper/board.rb
CHANGED
@@ -5,53 +5,57 @@ module FEEN
|
|
5
5
|
# The board class.
|
6
6
|
#
|
7
7
|
# @example Dump an empty board of Xiangqi
|
8
|
-
# Board.new(10, 9).to_s # => "9/9/9/9/9/9/9/9/9/9"
|
8
|
+
# Board.new([10, 9]).to_s # => "9/9/9/9/9/9/9/9/9/9"
|
9
9
|
#
|
10
10
|
# @example Dump the Xiangqi starting position board
|
11
|
-
# Board.new(
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
11
|
+
# Board.new(
|
12
|
+
# [10, 9],
|
13
|
+
# {
|
14
|
+
# 0 => "車",
|
15
|
+
# 1 => "馬",
|
16
|
+
# 2 => "象",
|
17
|
+
# 3 => "士",
|
18
|
+
# 4 => "將",
|
19
|
+
# 5 => "士",
|
20
|
+
# 6 => "象",
|
21
|
+
# 7 => "馬",
|
22
|
+
# 8 => "車",
|
23
|
+
# 19 => "砲",
|
24
|
+
# 25 => "砲",
|
25
|
+
# 27 => "卒",
|
26
|
+
# 29 => "卒",
|
27
|
+
# 31 => "卒",
|
28
|
+
# 33 => "卒",
|
29
|
+
# 35 => "卒",
|
30
|
+
# 54 => "兵",
|
31
|
+
# 56 => "兵",
|
32
|
+
# 58 => "兵",
|
33
|
+
# 60 => "兵",
|
34
|
+
# 62 => "兵",
|
35
|
+
# 64 => "炮",
|
36
|
+
# 70 => "炮",
|
37
|
+
# 81 => "俥",
|
38
|
+
# 82 => "傌",
|
39
|
+
# 83 => "相",
|
40
|
+
# 84 => "仕",
|
41
|
+
# 85 => "帥",
|
42
|
+
# 86 => "仕",
|
43
|
+
# 87 => "相",
|
44
|
+
# 88 => "傌",
|
45
|
+
# 89 => "俥"
|
46
|
+
# }
|
47
|
+
# ).to_s # => "車,馬,象,士,將,士,象,馬,車/9/1,砲,5,砲,1/卒,1,卒,1,卒,1,卒,1,卒/9/9/兵,1,兵,1,兵,1,兵,1,兵/1,炮,5,炮,1/9/俥,傌,相,仕,帥,仕,相,傌,俥"
|
44
48
|
class Board
|
45
49
|
# @param indexes [Array] The shape of the board.
|
46
50
|
# @param board [Hash] The indexes of each piece on the board.
|
47
|
-
def initialize(
|
51
|
+
def initialize(indexes, board)
|
48
52
|
@indexes = indexes
|
49
|
-
@squares = Array.new(length) { |i| board.fetch(i
|
53
|
+
@squares = Array.new(length) { |i| board.fetch(i, nil) }
|
50
54
|
end
|
51
55
|
|
52
56
|
# @return [String] The string representing the board.
|
53
57
|
def to_s
|
54
|
-
unflatten(@squares,
|
58
|
+
unflatten(@squares, @indexes)
|
55
59
|
end
|
56
60
|
|
57
61
|
private
|
@@ -60,17 +64,17 @@ module FEEN
|
|
60
64
|
@indexes.inject(:*)
|
61
65
|
end
|
62
66
|
|
63
|
-
def unflatten(squares,
|
64
|
-
return row(
|
67
|
+
def unflatten(squares, remaining_indexes)
|
68
|
+
return row(squares) if remaining_indexes.length == 1
|
65
69
|
|
66
70
|
squares
|
67
71
|
.each_slice(squares.length / remaining_indexes.fetch(0))
|
68
72
|
.to_a
|
69
|
-
.map { |sub_squares| unflatten(sub_squares,
|
73
|
+
.map { |sub_squares| unflatten(sub_squares, remaining_indexes[1..]) }
|
70
74
|
.join("/" * remaining_indexes.length.pred)
|
71
75
|
end
|
72
76
|
|
73
|
-
def row(
|
77
|
+
def row(squares)
|
74
78
|
squares
|
75
79
|
.map { |square| square.nil? ? 1 : square }
|
76
80
|
.join(",")
|
@@ -18,12 +18,12 @@ module FEEN
|
|
18
18
|
#
|
19
19
|
# @return [String] A string representing the pieces in hand of both
|
20
20
|
# players.
|
21
|
-
def self.dump(
|
22
|
-
pieces_in_hand_grouped_by_sides.map { |pieces| new(
|
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
23
|
end
|
24
24
|
|
25
25
|
# @param pieces [Array] A list of pieces in hand.
|
26
|
-
def initialize(
|
26
|
+
def initialize(pieces)
|
27
27
|
@pieces = pieces.sort
|
28
28
|
end
|
29
29
|
|
data/lib/feen/parser/board.rb
CHANGED
@@ -21,11 +21,11 @@ module FEEN
|
|
21
21
|
# @example Parse a Shogi problem board and return a hash
|
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
|
-
# #
|
25
|
-
# #
|
26
|
-
# #
|
27
|
-
# #
|
28
|
-
# #
|
24
|
+
# # 3 => "s",
|
25
|
+
# # 4 => "k" ,
|
26
|
+
# # 5 => "s",
|
27
|
+
# # 22 => "+P",
|
28
|
+
# # 43 => "+B"
|
29
29
|
# # }
|
30
30
|
class Board
|
31
31
|
# @param board [String] The flatten board.
|
@@ -47,7 +47,7 @@ module FEEN
|
|
47
47
|
.inject({}) do |h, (v, i)|
|
48
48
|
next h if v.nil?
|
49
49
|
|
50
|
-
h.merge(i
|
50
|
+
h.merge(i => v)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
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: 3.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-08
|
11
|
+
date: 2020-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brutal
|