qi 7.0.0 → 8.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 +4 -8
- data/lib/qi.rb +19 -35
- 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: eb79c3951884c03bb69f5b570c776e6154181b2e9c780a568faeb37b079b749e
|
4
|
+
data.tar.gz: 180ff6505865b89be300c3f3fbdc99d1f945d49f2469e73c6c3b28ad2cedd3f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e1281cc8424faee3b9be0be0842b816aa824595e3f9e62e54c0bb0949dcf1671ce942bfb47bf5ffcb78abdff03dd11de723b3dba58256570b33b83fad6545a9
|
7
|
+
data.tar.gz: e3b0c8103baa427ff22f770c6afc70eef6c5251fee580864c23129c264ea5534528dd365099fa9f5e4bf2b9f5d8d4762094e6bf771bab2acde4eeeeee795d680
|
data/README.md
CHANGED
@@ -30,20 +30,16 @@ require "qi"
|
|
30
30
|
|
31
31
|
Qi.call(
|
32
32
|
[43, 13, "+B"],
|
33
|
-
|
34
|
-
|
33
|
+
*%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],
|
34
|
+
**{
|
35
35
|
3 => "s",
|
36
36
|
4 => "k",
|
37
37
|
5 => "s",
|
38
38
|
22 => "+P",
|
39
39
|
43 => "+B"
|
40
|
-
}
|
41
|
-
"hands": [
|
42
|
-
%w[S],
|
43
|
-
%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]
|
44
|
-
]
|
40
|
+
}
|
45
41
|
)
|
46
|
-
# => {:
|
42
|
+
# => {:square=>{3=>"s", 4=>"k", 5=>"s", 22=>"+P", 13=>"+B"}, :in_hand=>["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"]}
|
47
43
|
```
|
48
44
|
|
49
45
|
## License
|
data/lib/qi.rb
CHANGED
@@ -5,54 +5,42 @@
|
|
5
5
|
# @example
|
6
6
|
# Qi.call(
|
7
7
|
# [43, 13, "+B"],
|
8
|
-
# "
|
9
|
-
# "
|
8
|
+
# "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],
|
9
|
+
# "square": {
|
10
10
|
# 3 => "s",
|
11
11
|
# 4 => "k",
|
12
12
|
# 5 => "s",
|
13
13
|
# 22 => "+P",
|
14
14
|
# 43 => "+B"
|
15
|
-
# }
|
16
|
-
# "hands": [
|
17
|
-
# %w[S],
|
18
|
-
# %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]
|
19
|
-
# ]
|
15
|
+
# }
|
20
16
|
# )
|
21
|
-
# # => {:
|
17
|
+
# # => {:in_hand=>["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"], :square=>{3=>"s", 4=>"k", 5=>"s", 22=>"+P", 13=>"+B"}}
|
22
18
|
module Qi
|
23
19
|
# Apply a move to the position.
|
24
20
|
#
|
25
21
|
# @param move [Array] The move to play.
|
26
|
-
# @param
|
27
|
-
# @param
|
28
|
-
# @param hands [Array] The list of pieces in hand grouped by players.
|
22
|
+
# @param in_hand [Array] The list of pieces in hand.
|
23
|
+
# @param square [Hash] The index of each piece on the board.
|
29
24
|
#
|
30
25
|
# @see https://developer.sashite.com/specs/portable-chess-notation
|
31
26
|
# @see https://developer.sashite.com/specs/portable-move-notation
|
32
27
|
#
|
33
|
-
# @example
|
28
|
+
# @example A classic Shogi problem
|
34
29
|
# call(
|
35
30
|
# [43, 13, "+B"],
|
36
|
-
#
|
37
|
-
#
|
31
|
+
# *%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],
|
32
|
+
# **{
|
38
33
|
# 3 => "s",
|
39
34
|
# 4 => "k",
|
40
35
|
# 5 => "s",
|
41
36
|
# 22 => "+P",
|
42
37
|
# 43 => "+B"
|
43
|
-
# }
|
44
|
-
# "hands": [
|
45
|
-
# %w[S],
|
46
|
-
# %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]
|
47
|
-
# ]
|
38
|
+
# }
|
48
39
|
# )
|
49
|
-
# # => {:
|
40
|
+
# # => {:in_hand=>["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"], :square=>{3=>"s", 4=>"k", 5=>"s", 22=>"+P", 13=>"+B"}}
|
50
41
|
#
|
51
42
|
# @return [Hash] The next position.
|
52
|
-
def self.call(move,
|
53
|
-
updated_board = board.dup
|
54
|
-
updated_in_hand_pieces = hands.fetch(side_id).dup
|
55
|
-
|
43
|
+
def self.call(move, *in_hand, **square)
|
56
44
|
actions = move.each_slice(4)
|
57
45
|
|
58
46
|
actions.each do |action|
|
@@ -62,23 +50,19 @@ module Qi
|
|
62
50
|
captured_piece_name = action.fetch(3, nil)
|
63
51
|
|
64
52
|
if src_square_id.nil?
|
65
|
-
piece_in_hand_id =
|
66
|
-
|
53
|
+
piece_in_hand_id = in_hand.index(moved_piece_name)
|
54
|
+
in_hand.delete_at(piece_in_hand_id) unless piece_in_hand_id.nil?
|
67
55
|
else
|
68
|
-
|
56
|
+
square.delete(src_square_id)
|
69
57
|
end
|
70
58
|
|
71
|
-
|
72
|
-
|
59
|
+
square[dst_square_id] = moved_piece_name
|
60
|
+
in_hand.push(captured_piece_name) unless captured_piece_name.nil?
|
73
61
|
end
|
74
62
|
|
75
|
-
updated_hands = hands.dup
|
76
|
-
updated_hands[side_id] = updated_in_hand_pieces
|
77
|
-
|
78
63
|
{
|
79
|
-
|
80
|
-
|
81
|
-
hands: updated_hands
|
64
|
+
in_hand: in_hand,
|
65
|
+
square: square
|
82
66
|
}
|
83
67
|
end
|
84
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 8.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-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brutal
|