qi 9.0.0.beta2 → 10.0.0.beta1

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: f66c9affa38d8e5dadfc596d5df81b47839187830d834600d624558d3643077e
4
- data.tar.gz: fd345a4baeacbf22a0a898731dc26b19063727190a497a6d4cf779ca6275bf96
3
+ metadata.gz: 3aa8e642b758585848e8313040632928a9e4f2f3054850f8fd5357891bbc1e85
4
+ data.tar.gz: 644e686cd59a9a61ce7405441d57c36dd38cec638d45814c2d2a4aa8cf7c6c29
5
5
  SHA512:
6
- metadata.gz: f5ef7c30f20b03fb3a6712c8b14824b1878a0f706159973b9d5c0c6270092042e12a4ecc50254e99f8d6107466367f58d530d77489370b3a54437e8f31bf42bb
7
- data.tar.gz: 9364870e925d1769e5c9d233bcc8acb626a0a9d70d62725eafda311a926bd6ed398cb5e0efbff71a09ca659bcfc5e67037126ee4c4cffaa7b79e2687dcc1f470
6
+ metadata.gz: b796b912f5bd07395d2a90166e10e9109d717ee3e873e546f50117438a341ea0e485b2daa2121b37af58ab2be594935d3cd3f126eed01ecacd44f457faf0740e
7
+ data.tar.gz: 0ed78551692a98212c3de8293216bde978c745a8502db6d890dbc4c40f991045014736c0c1b8ba75d3ae96d7e012f50a3cfefd1dcbc8b9e4e09dc54fcac0f4a4
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ # The MIT License
2
2
 
3
- Copyright (c) 2015-2021 Sashite
3
+ Copyright (c) 2015-2023 Sashite
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -6,20 +6,20 @@
6
6
  [![RuboCop](https://github.com/sashite/qi.rb/workflows/RuboCop/badge.svg?branch=main)](https://github.com/sashite/qi.rb/actions?query=workflow%3Arubocop+branch%3Amain)
7
7
  [![License](https://img.shields.io/github/license/sashite/qi.rb?label=License&logo=github)](https://github.com/sashite/qi.rb/raw/main/LICENSE.md)
8
8
 
9
- > `Qi` () is an abstraction for updating positions of chess variants (including Chess, Janggi, Markruk, Shogi, Xiangqi), with a move.
9
+ > `Qi` (Chinese: 棋; pinyin: _qí_) is an abstraction that could help to update positions for games like Shogi.
10
10
 
11
11
  ## Installation
12
12
 
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", ">= 10.0.0.beta1"
17
17
  ```
18
18
 
19
19
  And then execute:
20
20
 
21
21
  ```sh
22
- bundle
22
+ bundle install
23
23
  ```
24
24
 
25
25
  Or install it yourself as:
@@ -28,23 +28,18 @@ Or install it yourself as:
28
28
  gem install qi --pre
29
29
  ```
30
30
 
31
- ## Examples
31
+ ## Example
32
32
 
33
33
  ```ruby
34
34
  require "qi"
35
35
 
36
- Qi.call(
37
- [43, 13, "+B"],
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
- square: {
40
- 3 => "s",
41
- 4 => "k",
42
- 5 => "s",
43
- 22 => "+P",
44
- 43 => "+B"
45
- }
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"]}
36
+ captures = %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]
37
+ squares = { "3": "s", "4": "k", "5": "s", "22": "+P", "43": "+B" }
38
+
39
+ captures, squares = Qi(*captures, **squares).call("43": nil, "13": "+B")
40
+
41
+ captures # => ["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
+ squares # => {:"3"=>"s", :"4"=>"k", :"5"=>"s", :"22"=>"+P", :"13"=>"+B"}
48
43
  ```
49
44
 
50
45
  ## License
data/lib/kernel.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ # shareable_constant_value: none
3
+
4
+ # warn_indent: true
5
+
6
+ require_relative File.join("qi", "action")
7
+
8
+ # The Kernel module.
9
+ module Kernel
10
+ # Abstraction to build positions.
11
+ #
12
+ # @return [Array] An action to change the position.
13
+ #
14
+ # @api public
15
+ def Qi(*captures, **squares)
16
+ ::Qi::Action.new(*captures, **squares)
17
+ end
18
+ end
data/lib/qi/action.rb CHANGED
@@ -3,59 +3,45 @@
3
3
  module Qi
4
4
  # The Action abstraction.
5
5
  class Action
6
- # Initialize an action instance.
7
- #
8
- # @param src_square_id [Integer, nil] The source square ID.
9
- # @param dst_square_id [Integer] The target square ID.
10
- # @param moved_piece_name [String] The moved piece name.
11
- # @param captured_piece_name [String, nil] The captured piece name.
12
- #
13
- # @example Initialize a promoted bishop action from 43 to 13
14
- # new(43, 13, "+B", nil)
15
- #
16
- # @see https://developer.sashite.com/specs/portable-action-notation
17
- def initialize(src_square_id, dst_square_id, moved_piece_name, captured_piece_name = nil)
18
- @src_square_id = src_square_id
19
- @dst_square_id = dst_square_id
20
- @moved_piece_name = moved_piece_name
21
- @captured_piece_name = captured_piece_name
6
+ CAPTURE_CHAR = "&"
7
+ DROP_CHAR = "*"
8
+
9
+ # Action initializer.
10
+ def initialize(*captures, **squares)
11
+ @captures = captures
12
+ @squares = squares
22
13
  end
23
14
 
24
15
  # Commit an action to the position.
25
16
  #
26
- # @param in_hand [Array] The list of pieces in hand.
27
- # @param square [Hash] The index of each piece on the board.
28
- #
29
- # @example Commit a Shogi action to the piece set of a position
30
- # call(
31
- # 43, 13, "+B", nil,
32
- # 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],
33
- # square: {
34
- # 3 => "s",
35
- # 4 => "k",
36
- # 5 => "s",
37
- # 22 => "+P",
38
- # 43 => "+B"
39
- # }
40
- # )
41
- # # => {: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"}}
42
- #
43
- # @return [Hash] The next piece set.
44
- def call(in_hand:, square:)
45
- in_hand = in_hand.dup
46
- square = square.dup
47
-
48
- if @src_square_id.nil?
49
- piece_in_hand_id = in_hand.index(@moved_piece_name)
50
- in_hand.delete_at(piece_in_hand_id) unless piece_in_hand_id.nil?
51
- else
52
- square.delete(@src_square_id)
17
+ # @return [Array] An action to change the position.
18
+ def call(**diffs)
19
+ captures = @captures
20
+ squares = @squares
21
+
22
+ diffs.each do |k, v|
23
+ case String(k)
24
+ when CAPTURE_CHAR
25
+ captures = capture(v, *captures)
26
+ when DROP_CHAR
27
+ captures = drop(v, *captures)
28
+ else
29
+ squares = squares.merge(k => v)
30
+ end
53
31
  end
54
32
 
55
- square[@dst_square_id] = @moved_piece_name
56
- in_hand.push(@captured_piece_name) unless @captured_piece_name.nil?
33
+ [captures, squares.compact]
34
+ end
35
+
36
+ private
37
+
38
+ def capture(item, *items)
39
+ [item] + items
40
+ end
57
41
 
58
- { in_hand: in_hand, square: square }
42
+ def drop(item, *items)
43
+ items.delete_at(items.index(item))
44
+ items
59
45
  end
60
46
  end
61
47
  end
data/lib/qi.rb CHANGED
@@ -1,48 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative File.join("qi", "move")
3
+ require_relative "kernel"
4
4
 
5
5
  # The Qi abstraction.
6
- #
7
- # @example Apply a move to a classic Shogi problem
8
- # Qi.call(
9
- # [43, 13, "+B"],
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
- # square: {
12
- # 3 => "s",
13
- # 4 => "k",
14
- # 5 => "s",
15
- # 22 => "+P",
16
- # 43 => "+B"
17
- # }
18
- # )
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
6
  module Qi
21
- # Apply a move to the position.
22
- #
23
- # @param move [Array] The move to play.
24
- # @param in_hand [Array] The list of pieces in hand.
25
- # @param square [Hash] The index of each piece on the board.
26
- #
27
- # @see https://developer.sashite.com/specs/portable-chess-notation
28
- # @see https://developer.sashite.com/specs/portable-move-notation
29
- #
30
- # @example Apply a move to a classic Shogi problem
31
- # call(
32
- # [43, 13, "+B"],
33
- # 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
- # square: {
35
- # 3 => "s",
36
- # 4 => "k",
37
- # 5 => "s",
38
- # 22 => "+P",
39
- # 43 => "+B"
40
- # }
41
- # )
42
- # # => {: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
- #
44
- # @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)
47
- end
48
7
  end
metadata CHANGED
@@ -1,17 +1,31 @@
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: 10.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-13 00:00:00.000000000 Z
11
+ date: 2023-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brutal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.0.beta4
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.0.beta4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -25,7 +39,7 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: bundler
42
+ name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -39,7 +53,7 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: byebug
56
+ name: rubocop
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -53,7 +67,7 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rake
70
+ name: rubocop-gitlab-security
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -150,7 +164,7 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
153
- description: Instantiate PCN's positions and apply PMN's moves.
167
+ description: An abstraction that could help to update positions for games like Shogi.
154
168
  email: contact@cyril.email
155
169
  executables: []
156
170
  extensions: []
@@ -158,17 +172,15 @@ extra_rdoc_files: []
158
172
  files:
159
173
  - LICENSE.md
160
174
  - README.md
175
+ - lib/kernel.rb
161
176
  - lib/qi.rb
162
177
  - lib/qi/action.rb
163
- - lib/qi/move.rb
164
- homepage: https://developer.sashite.com/specs/
178
+ homepage: https://github.com/sashite/qi.rb
165
179
  licenses:
166
180
  - MIT
167
181
  metadata:
168
- bug_tracker_uri: https://github.com/sashite/qi.rb/issues
169
- documentation_uri: https://rubydoc.info/gems/qi/index
170
- source_code_uri: https://github.com/sashite/qi.rb
171
- post_install_message:
182
+ rubygems_mfa_required: 'true'
183
+ post_install_message:
172
184
  rdoc_options: []
173
185
  require_paths:
174
186
  - lib
@@ -176,15 +188,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
188
  requirements:
177
189
  - - ">="
178
190
  - !ruby/object:Gem::Version
179
- version: 3.0.0
191
+ version: 3.2.0
180
192
  required_rubygems_version: !ruby/object:Gem::Requirement
181
193
  requirements:
182
194
  - - ">"
183
195
  - !ruby/object:Gem::Version
184
196
  version: 1.3.1
185
197
  requirements: []
186
- rubygems_version: 3.2.22
187
- signing_key:
198
+ rubygems_version: 3.4.1
199
+ signing_key:
188
200
  specification_version: 4
189
- summary: Update positions with a move.
201
+ summary: An abstraction that could help to update positions for games like Shogi.
190
202
  test_files: []
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