qi 7.0.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -8
  3. data/lib/qi.rb +19 -35
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18ca7bb7fca15a8ce854e8a205160b05a14127970039a904c3ce8ad6f8baf8fc
4
- data.tar.gz: fc4b915c93488f39835f762b1f89fb44a74ab25ca3faa47fb4a6ea846db66c77
3
+ metadata.gz: eb79c3951884c03bb69f5b570c776e6154181b2e9c780a568faeb37b079b749e
4
+ data.tar.gz: 180ff6505865b89be300c3f3fbdc99d1f945d49f2469e73c6c3b28ad2cedd3f0
5
5
  SHA512:
6
- metadata.gz: 6079a5cb3f9b5b83a5bbc0db41694e6037a46a8e5ef6ce8bd4e65f36863d17008cb5d08d806681c4b17daff89ef2d43abd4e260c4ba068b7ac499fe51a36053c
7
- data.tar.gz: 164bb2211d24d9119061a9c771438d0b77f96c0e2d51d4f18c3cfe3f82acdeaf50bd532d4eafb071441a64a18be68cefc9bae9a6dcfcf81b633cf3498912e76c
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
- "side_id": 0,
34
- "board": {
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
- # => {:side_id=>1, :board=>{3=>"s", 4=>"k", 5=>"s", 22=>"+P", 13=>"+B"}, :hands=>[["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"]]}
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
- # "side_id": 0,
9
- # "board": {
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
- # # => {:side_id=>1, :board=>{3=>"s", 4=>"k", 5=>"s", 22=>"+P", 13=>"+B"}, :hands=>[["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"]]}
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 side_id [Integer] The identifier of the player who must play.
27
- # @param board [Hash] The indexes of each piece on the board.
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
- # "side_id": 0,
37
- # "board": {
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
- # # => {:side_id=>1, :board=>{3=>"s", 4=>"k", 5=>"s", 22=>"+P", 13=>"+B"}, :hands=>[["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"]]}
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, side_id:, board:, hands:)
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 = updated_in_hand_pieces.index(moved_piece_name)
66
- updated_in_hand_pieces.delete_at(piece_in_hand_id) unless piece_in_hand_id.nil?
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
- updated_board.delete(src_square_id)
56
+ square.delete(src_square_id)
69
57
  end
70
58
 
71
- updated_board[dst_square_id] = moved_piece_name
72
- updated_in_hand_pieces.push(captured_piece_name) unless captured_piece_name.nil?
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
- side_id: side_id.succ % hands.length,
80
- board: updated_board,
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: 7.0.0
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-09-19 00:00:00.000000000 Z
11
+ date: 2020-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brutal