qi 9.0.0.beta2 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/lib/qi.rb +12 -7
  4. metadata +4 -5
  5. data/lib/qi/move.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f66c9affa38d8e5dadfc596d5df81b47839187830d834600d624558d3643077e
4
- data.tar.gz: fd345a4baeacbf22a0a898731dc26b19063727190a497a6d4cf779ca6275bf96
3
+ metadata.gz: 52024f72e11787560aa6fc8bed990c359e49d3e995f2d3cfea875de5febaeba5
4
+ data.tar.gz: d04a6301684f284f29aa1b67c811ca596006a6aa0f33e22d1c67790da55418ef
5
5
  SHA512:
6
- metadata.gz: f5ef7c30f20b03fb3a6712c8b14824b1878a0f706159973b9d5c0c6270092042e12a4ecc50254e99f8d6107466367f58d530d77489370b3a54437e8f31bf42bb
7
- data.tar.gz: 9364870e925d1769e5c9d233bcc8acb626a0a9d70d62725eafda311a926bd6ed398cb5e0efbff71a09ca659bcfc5e67037126ee4c4cffaa7b79e2687dcc1f470
6
+ metadata.gz: e9afd43466c2ea7b6608d0f94996bffd40622fa2ff98bc008098c78375074c4ae8c6e12235520053a35619fca22b3588ccc120d06910f9b8af10cf349273af6c
7
+ data.tar.gz: 4264fd4ff0e12bc86b1451b1a411bea1e700cb58581f87e0216a0b601bd26c2443e144c44ddb765e8e6428ae0bdc2f406342248851a5c36c9f9c00494c8c1253
data/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  Add this line to your application's Gemfile:
14
14
 
15
15
  ```ruby
16
- gem "qi", ">= 9.0.0.beta2"
16
+ gem "qi"
17
17
  ```
18
18
 
19
19
  And then execute:
@@ -25,16 +25,16 @@ bundle
25
25
  Or install it yourself as:
26
26
 
27
27
  ```sh
28
- gem install qi --pre
28
+ gem install qi
29
29
  ```
30
30
 
31
- ## Examples
31
+ ## Example
32
32
 
33
33
  ```ruby
34
34
  require "qi"
35
35
 
36
36
  Qi.call(
37
- [43, 13, "+B"],
37
+ 43, 13, "+B",
38
38
  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],
39
39
  square: {
40
40
  3 => "s",
@@ -44,7 +44,7 @@ Qi.call(
44
44
  43 => "+B"
45
45
  }
46
46
  )
47
- # => {: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
+ # => {: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"}}
48
48
  ```
49
49
 
50
50
  ## License
data/lib/qi.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative File.join("qi", "move")
3
+ require_relative File.join("qi", "action")
4
4
 
5
5
  # The Qi abstraction.
6
6
  #
7
7
  # @example Apply a move to a classic Shogi problem
8
8
  # Qi.call(
9
- # [43, 13, "+B"],
9
+ # 43, 13, "+B",
10
10
  # 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],
11
11
  # square: {
12
12
  # 3 => "s",
@@ -18,9 +18,12 @@ require_relative File.join("qi", "move")
18
18
  # )
19
19
  # # => {: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"}}
20
20
  module Qi
21
- # Apply a move to the position.
21
+ # Apply an action to the position.
22
22
  #
23
- # @param move [Array] The move to play.
23
+ # @param src_square_id [Integer] A source square index.
24
+ # @param dst_square_id [Integer] A target square index.
25
+ # @param moved_piece_name [String] A piece name.
26
+ # @param captured_piece_name [String] A captured piece name.
24
27
  # @param in_hand [Array] The list of pieces in hand.
25
28
  # @param square [Hash] The index of each piece on the board.
26
29
  #
@@ -29,7 +32,9 @@ module Qi
29
32
  #
30
33
  # @example Apply a move to a classic Shogi problem
31
34
  # call(
32
- # [43, 13, "+B"],
35
+ # 43,
36
+ # 13,
37
+ # "+B",
33
38
  # 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],
34
39
  # square: {
35
40
  # 3 => "s",
@@ -42,7 +47,7 @@ module Qi
42
47
  # # => {: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"}}
43
48
  #
44
49
  # @return [Hash] The piece set of the next position.
45
- def self.call(move, in_hand:, square:)
46
- Move.new(move).call(in_hand: in_hand, square: square)
50
+ def self.call(src_square_id, dst_square_id, moved_piece_name, captured_piece_name = nil, in_hand:, square:)
51
+ Action.new(src_square_id, dst_square_id, moved_piece_name, captured_piece_name).call(in_hand: in_hand, square: square)
47
52
  end
48
53
  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: 9.0.0.beta2
4
+ version: 9.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: 2021-08-13 00:00:00.000000000 Z
11
+ date: 2021-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brutal
@@ -160,7 +160,6 @@ files:
160
160
  - README.md
161
161
  - lib/qi.rb
162
162
  - lib/qi/action.rb
163
- - lib/qi/move.rb
164
163
  homepage: https://developer.sashite.com/specs/
165
164
  licenses:
166
165
  - MIT
@@ -179,9 +178,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
178
  version: 3.0.0
180
179
  required_rubygems_version: !ruby/object:Gem::Requirement
181
180
  requirements:
182
- - - ">"
181
+ - - ">="
183
182
  - !ruby/object:Gem::Version
184
- version: 1.3.1
183
+ version: '0'
185
184
  requirements: []
186
185
  rubygems_version: 3.2.22
187
186
  signing_key:
data/lib/qi/move.rb DELETED
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "action"
4
-
5
- module Qi
6
- # The Move abstraction.
7
- class Move
8
- # Initialize a move instance.
9
- #
10
- # @param move [Array] The move to apply.
11
- #
12
- # @example Initialize a promoted bishop move from 43 to 13
13
- # new([43, 13, "+B"])
14
- #
15
- # @see https://developer.sashite.com/specs/portable-move-notation
16
- def initialize(move)
17
- @actions = move.each_slice(4)
18
- end
19
-
20
- # Apply a move to the piece set of a position.
21
- #
22
- # @param in_hand [Array] The list of pieces in hand.
23
- # @param square [Hash] The index of each piece on the board.
24
- #
25
- # @example Apply a move to a classic Shogi problem
26
- # call(
27
- # [43, 13, "+B"],
28
- # 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],
29
- # square: {
30
- # 3 => "s",
31
- # 4 => "k",
32
- # 5 => "s",
33
- # 22 => "+P",
34
- # 43 => "+B"
35
- # }
36
- # )
37
- # # => {: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"}}
38
- #
39
- # @return [Hash] The piece set of the next position.
40
- def call(in_hand:, square:)
41
- @actions.inject(in_hand: in_hand, square: square) do |piece_set, attrs|
42
- Action.new(*attrs).call(**piece_set)
43
- end
44
- end
45
- end
46
- end