qi 6.3.0 → 6.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/qi/position.rb +10 -9
- 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: e72084022a3eaca3cec4ff33c2106c99e2b5da61412049b37180f0ddddd87793
|
4
|
+
data.tar.gz: 56082cc561866965d8f37178f8e6710d54593e4d67f6a24bd63ec23e5c183094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f12a76bed9d203b56fcadf2133ec8e985494827d8e5533a7c4bcbe2c350de43d9ff8254c5b9f66c862ddb137f74fb4522b0f88ccd1d29fbec7d972a3acea5984
|
7
|
+
data.tar.gz: 057b02a60a91a292bce36d173128e8a22117211d2afc32d5155ff81e289ebe7fb501b31a1c03c148c335c4ed61c3819f7b47fb8a51b0804f6098f3926b7c6a6c
|
data/lib/qi/position.rb
CHANGED
@@ -18,15 +18,15 @@ module Qi
|
|
18
18
|
# @return [Array] The list of pieces in hand for each side.
|
19
19
|
attr_reader :pieces_in_hand_grouped_by_sides
|
20
20
|
|
21
|
-
# The list of squares
|
21
|
+
# The list of squares on the board.
|
22
22
|
#
|
23
23
|
# @!attribute [r] squares
|
24
|
-
# @return [Array] The list of squares.
|
24
|
+
# @return [Array] The list of squares on the board.
|
25
25
|
attr_reader :squares
|
26
26
|
|
27
27
|
# Initialize a position.
|
28
28
|
#
|
29
|
-
# @param squares [Array] The list of squares
|
29
|
+
# @param squares [Array] The list of squares on the board.
|
30
30
|
# @param active_side_id [Integer] The identifier of the player who must play.
|
31
31
|
# @param pieces_in_hand_grouped_by_sides [Array] The list of pieces in hand
|
32
32
|
# grouped by players.
|
@@ -124,16 +124,18 @@ module Qi
|
|
124
124
|
# )
|
125
125
|
def initialize(*squares, active_side_id: 0, pieces_in_hand_grouped_by_sides: [[], []])
|
126
126
|
@squares = squares
|
127
|
-
@active_side_id = active_side_id % pieces_in_hand_grouped_by_sides.
|
127
|
+
@active_side_id = active_side_id % pieces_in_hand_grouped_by_sides.size
|
128
128
|
@pieces_in_hand_grouped_by_sides = pieces_in_hand_grouped_by_sides
|
129
129
|
|
130
130
|
freeze
|
131
131
|
end
|
132
132
|
|
133
|
-
# Apply a move
|
133
|
+
# Apply a move to the position.
|
134
134
|
#
|
135
135
|
# @param move [Array] The move to play.
|
136
136
|
# @see https://developer.sashite.com/specs/portable-move-notation
|
137
|
+
# @see https://github.com/sashite/pmn.rb
|
138
|
+
#
|
137
139
|
# @return [Position] The new position.
|
138
140
|
def call(move)
|
139
141
|
updated_squares = squares.dup
|
@@ -149,7 +151,7 @@ module Qi
|
|
149
151
|
|
150
152
|
if src_square_id.nil?
|
151
153
|
piece_in_hand_id = updated_in_hand_pieces.index(moved_piece_name)
|
152
|
-
updated_in_hand_pieces.delete_at(piece_in_hand_id)
|
154
|
+
updated_in_hand_pieces.delete_at(piece_in_hand_id) unless piece_in_hand_id.nil?
|
153
155
|
else
|
154
156
|
updated_squares[src_square_id] = nil
|
155
157
|
end
|
@@ -165,15 +167,14 @@ module Qi
|
|
165
167
|
updated_pieces_in_hand_grouped_by_sides[active_side_id] = updated_in_hand_pieces
|
166
168
|
|
167
169
|
self.class.new(*updated_squares,
|
168
|
-
active_side_id: active_side_id.
|
170
|
+
active_side_id: active_side_id.succ,
|
169
171
|
pieces_in_hand_grouped_by_sides: updated_pieces_in_hand_grouped_by_sides
|
170
172
|
)
|
171
173
|
end
|
172
174
|
|
173
175
|
# The list of pieces in hand owned by the current player.
|
174
176
|
#
|
175
|
-
# @return [Array]
|
176
|
-
# ones otherwise.
|
177
|
+
# @return [Array] The list of pieces in hand of the active side.
|
177
178
|
def in_hand_pieces
|
178
179
|
pieces_in_hand_grouped_by_sides.fetch(active_side_id)
|
179
180
|
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: 6.3.
|
4
|
+
version: 6.3.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-08-
|
11
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brutal
|