qi 9.0.0 → 10.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +2 -2
- data/README.md +11 -16
- data/lib/kernel.rb +18 -0
- data/lib/qi/action.rb +32 -46
- data/lib/qi.rb +1 -47
- metadata +31 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aa8e642b758585848e8313040632928a9e4f2f3054850f8fd5357891bbc1e85
|
4
|
+
data.tar.gz: 644e686cd59a9a61ce7405441d57c36dd38cec638d45814c2d2a4aa8cf7c6c29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b796b912f5bd07395d2a90166e10e9109d717ee3e873e546f50117438a341ea0e485b2daa2121b37af58ab2be594935d3cd3f126eed01ecacd44f457faf0740e
|
7
|
+
data.tar.gz: 0ed78551692a98212c3de8293216bde978c745a8502db6d890dbc4c40f991045014736c0c1b8ba75d3ae96d7e012f50a3cfefd1dcbc8b9e4e09dc54fcac0f4a4
|
data/LICENSE.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
The MIT License
|
1
|
+
# The MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2015-
|
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,26 +6,26 @@
|
|
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` (
|
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"
|
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:
|
26
26
|
|
27
27
|
```sh
|
28
|
-
gem install qi
|
28
|
+
gem install qi --pre
|
29
29
|
```
|
30
30
|
|
31
31
|
## Example
|
@@ -33,18 +33,13 @@ gem install qi
|
|
33
33
|
```ruby
|
34
34
|
require "qi"
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
22 => "+P",
|
44
|
-
43 => "+B"
|
45
|
-
}
|
46
|
-
)
|
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"}}
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
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
|
-
# @
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
56
|
-
|
33
|
+
[captures, squares.compact]
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def capture(item, *items)
|
39
|
+
[item] + items
|
40
|
+
end
|
57
41
|
|
58
|
-
|
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,53 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
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 an action to the position.
|
22
|
-
#
|
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.
|
27
|
-
# @param in_hand [Array] The list of pieces in hand.
|
28
|
-
# @param square [Hash] The index of each piece on the board.
|
29
|
-
#
|
30
|
-
# @see https://developer.sashite.com/specs/portable-chess-notation
|
31
|
-
# @see https://developer.sashite.com/specs/portable-move-notation
|
32
|
-
#
|
33
|
-
# @example Apply a move to a classic Shogi problem
|
34
|
-
# call(
|
35
|
-
# 43,
|
36
|
-
# 13,
|
37
|
-
# "+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
|
-
# # => {: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
|
-
#
|
49
|
-
# @return [Hash] The piece set of the next position.
|
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)
|
52
|
-
end
|
53
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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,16 +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
|
-
homepage: https://
|
178
|
+
homepage: https://github.com/sashite/qi.rb
|
164
179
|
licenses:
|
165
180
|
- MIT
|
166
181
|
metadata:
|
167
|
-
|
168
|
-
|
169
|
-
source_code_uri: https://github.com/sashite/qi.rb
|
170
|
-
post_install_message:
|
182
|
+
rubygems_mfa_required: 'true'
|
183
|
+
post_install_message:
|
171
184
|
rdoc_options: []
|
172
185
|
require_paths:
|
173
186
|
- lib
|
@@ -175,15 +188,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
175
188
|
requirements:
|
176
189
|
- - ">="
|
177
190
|
- !ruby/object:Gem::Version
|
178
|
-
version: 3.
|
191
|
+
version: 3.2.0
|
179
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
193
|
requirements:
|
181
|
-
- - "
|
194
|
+
- - ">"
|
182
195
|
- !ruby/object:Gem::Version
|
183
|
-
version:
|
196
|
+
version: 1.3.1
|
184
197
|
requirements: []
|
185
|
-
rubygems_version: 3.
|
186
|
-
signing_key:
|
198
|
+
rubygems_version: 3.4.1
|
199
|
+
signing_key:
|
187
200
|
specification_version: 4
|
188
|
-
summary:
|
201
|
+
summary: An abstraction that could help to update positions for games like Shogi.
|
189
202
|
test_files: []
|