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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53ffebf45c7d54e896af8ea265e9a3e6be43f5d3367f8f4d75a3be35ede0769c
4
- data.tar.gz: b942b667c90dadea80c7dfadb87872a3024c3a15dbaf866814c530957ad12fd3
3
+ metadata.gz: 4120730f5c39a876c2dc1bba4536f997b822ddfee043e37cdb1dc68f1ffcbb31
4
+ data.tar.gz: 3a0365e075d0c0238625d841c78ccb52e21106bc47cc312ce6b1e4e47d08d6b9
5
5
  SHA512:
6
- metadata.gz: 921e336e081f5d238e05750f245e81aa5d1b10a8b7fd5eddd1eec95518d3b210c77a4d14ecf3d53f6098217c3113a3dba27abaafddc5cb981f7f3d304bc00202
7
- data.tar.gz: 840842f00f4da13daefefac0389a616296c692e8da099da0c37959e5ea6e1ae2fcb5fbb3a3e0643bbd903874f61d11b1ef398db30e29ee1c432654492ffdd305
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
- "3": "s",
44
- "4": "k" ,
45
- "5": "s",
46
- "22": "+P",
47
- "43": "+B"
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
- # "3": "s",
63
- # "4": "k" ,
64
- # "5": "s",
65
- # "22": "+P",
66
- # "43": "+B"
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": [
@@ -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(*indexes, **board).to_s,
39
+ Board.new(indexes, board).to_s,
40
40
  Turn.dump(active_side_id, pieces_in_hand_grouped_by_sides.length),
41
- PiecesInHand.dump(*pieces_in_hand_grouped_by_sides)
41
+ PiecesInHand.dump(pieces_in_hand_grouped_by_sides)
42
42
  ].join(" ")
43
43
  end
44
44
  end
@@ -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(10, 9,
12
- # "0": "車",
13
- # "1": "馬",
14
- # "2": "",
15
- # "3": "",
16
- # "4": "",
17
- # "5": "士",
18
- # "6": "",
19
- # "7": "",
20
- # "8": "",
21
- # "19": "",
22
- # "25": "",
23
- # "27": "",
24
- # "29": "",
25
- # "31": "卒",
26
- # "33": "卒",
27
- # "35": "卒",
28
- # "54": "",
29
- # "56": "",
30
- # "58": "兵",
31
- # "60": "兵",
32
- # "62": "兵",
33
- # "64": "",
34
- # "70": "",
35
- # "81": "",
36
- # "82": "",
37
- # "83": "",
38
- # "84": "",
39
- # "85": "",
40
- # "86": "仕",
41
- # "87": "",
42
- # "88": "",
43
- # "89": "俥").to_s # => "車,馬,象,士,將,士,象,馬,車/9/1,砲,5,砲,1/卒,1,卒,1,卒,1,卒,1,卒/9/9/兵,1,兵,1,兵,1,兵,1,兵/1,炮,5,炮,1/9/俥,傌,相,仕,帥,仕,相,傌,俥"
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(*indexes, **board)
51
+ def initialize(indexes, board)
48
52
  @indexes = indexes
49
- @squares = Array.new(length) { |i| board.fetch(i.to_s.to_sym, nil) }
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, *@indexes)
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, *remaining_indexes)
64
- return row(*squares) if remaining_indexes.length == 1
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, *remaining_indexes[1..]) }
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(*squares)
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(*pieces_in_hand_grouped_by_sides)
22
- pieces_in_hand_grouped_by_sides.map { |pieces| new(*pieces).to_s }.join("/")
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(*pieces)
26
+ def initialize(pieces)
27
27
  @pieces = pieces.sort
28
28
  end
29
29
 
@@ -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
- # # "3": "s",
25
- # # "4": "k" ,
26
- # # "5": "s",
27
- # # "22": "+P",
28
- # # "43": "+B"
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.to_s.to_sym => v)
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: 2.0.0
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-24 00:00:00.000000000 Z
11
+ date: 2020-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brutal