qi 6.0.0 → 6.1.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/LICENSE.md +1 -1
  3. data/README.md +83 -8
  4. data/lib/qi/position.rb +27 -2
  5. metadata +2 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea547ce94942f087213cf6a85465a231347e2cbd1805b5be7ebbe108d5cdd304
4
- data.tar.gz: '00529deb18f2658355d4bf8dd6955e3bf4469047164b872dea91ff3ea61f1841'
3
+ metadata.gz: cee3167f3c32021191d7cb31829437f5d33c186314d8ebdeb6ce271ca25f9651
4
+ data.tar.gz: 2802d9e46a694d78d476251e2a194a2de725fc984e5181ff48a9c6cd9512a0e9
5
5
  SHA512:
6
- metadata.gz: d46dd80b15e18ba16a3c4ea6c9d8a479e9f2f044e5b776c34c5152e80903c9e4aa806ee603c448334fdc10fcea995a710b33b30488ebf199a1c56e559065e95b
7
- data.tar.gz: f905c0750db19eda558dae0e8bcab054f180f4f21997f6896426330d64f10404c8cc63b08557a4e9c0d5fd264861fe3e933a6b23be3d418851f31abe1787481d
6
+ metadata.gz: 34dd51e3c9179833ccebcbee0a99df78144e4a6867b30f2d9b404b166bc6f5fb039ee922b939056e2f07b80588271e94e627765622cc0e65434c1fefd402a120
7
+ data.tar.gz: bfbe4d8074dcf3c5a196c257f1126e29dcde90bbd0af4221a67a58cd94e93893cccd065ec058c5d3016c2fa5f39946d074f203532e9c13294459195544821b85
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2020 Cyril Kato
3
+ Copyright (c) 2015-2020 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
@@ -1,6 +1,6 @@
1
- # Qi
1
+ # <span lang="zh"><ruby>棋<rt>Qi</rt></ruby></span>.rb
2
2
 
3
- [![Build Status](https://api.travis-ci.org/sashite/qi.rb.svg?branch=master)][travis]
3
+ [![Build Status](https://travis-ci.org/sashite/qi.rb.svg?branch=master)](https://travis-ci.org/sashite/qi.rb)
4
4
  [![Gem Version](https://badge.fury.io/rb/qi.svg)][gem]
5
5
  [![Inline docs](https://inch-ci.org/github/sashite/qi.rb.svg?branch=master)][inchpages]
6
6
  [![Documentation](https://img.shields.io/:yard-docs-38c800.svg)][rubydoc]
@@ -23,14 +23,14 @@ Or install it yourself as:
23
23
 
24
24
  $ gem install qi
25
25
 
26
- ## Example
26
+ ## Examples
27
27
 
28
28
  Let's replay [The Shortest Possible Game of Shogi](https://userpages.monmouth.com/~colonel/shortshogi.html):
29
29
 
30
30
  ```ruby
31
31
  require 'qi'
32
32
 
33
- shogi_starting_position = Qi::Position.new(
33
+ starting_position = Qi::Position.new(
34
34
  'l', 'n', 's', 'g', 'k', 'g', 's', 'n', 'l',
35
35
  nil, 'r', nil, nil, nil, nil, nil, 'b', nil,
36
36
  'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p',
@@ -42,6 +42,20 @@ shogi_starting_position = Qi::Position.new(
42
42
  'L', 'N', 'S', 'G', 'K', 'G', 'S', 'N', 'L'
43
43
  )
44
44
 
45
+ starting_position.topside_in_hand_pieces # => []
46
+ starting_position.squares # => ["l", "n", "s", "g", "k", "g", "s", "n", "l",
47
+ # nil, "r", nil, nil, nil, nil, nil, "b", nil,
48
+ # "p", "p", "p", "p", "p", "p", "p", "p", "p",
49
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
50
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
51
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
52
+ # "P", "P", "P", "P", "P", "P", "P", "P", "P",
53
+ # nil, "B", nil, nil, nil, nil, nil, "R", nil,
54
+ # "L", "N", "S", "G", "K", "G", "S", "N", "L"]
55
+ starting_position.bottomside_in_hand_pieces # => []
56
+ starting_position.in_hand_pieces # => []
57
+ starting_position.turn_to_topside? # => false
58
+
45
59
  moves = [
46
60
  [ 56, 47, 'P' ],
47
61
  [ 3, 11, 'g' ],
@@ -52,12 +66,11 @@ moves = [
52
66
  [ nil, 13, 'G' ]
53
67
  ]
54
68
 
55
- last_position = moves.reduce(shogi_starting_position) do |position, move|
69
+ last_position = moves.reduce(starting_position) do |position, move|
56
70
  position.call(move)
57
71
  end
58
72
 
59
73
  last_position.topside_in_hand_pieces # => []
60
-
61
74
  last_position.squares # => ["l", "n", "s", "k", nil, nil, "s", "n", "l",
62
75
  # nil, "r", "g", nil, "G", "+B", nil, "b", nil,
63
76
  # "p", "p", "p", "p", "p", "p", nil, "p", "p",
@@ -67,8 +80,71 @@ last_position.squares # => ["l", "n", "s", "k", nil, nil, "s", "n", "l",
67
80
  # "P", "P", nil, "P", "P", "P", "P", "P", "P",
68
81
  # nil, nil, nil, nil, nil, nil, nil, "R", nil,
69
82
  # "L", "N", "S", "G", "K", "G", "S", "N", "L"]
70
-
71
83
  last_position.bottomside_in_hand_pieces # => ["P"]
84
+ last_position.in_hand_pieces # => []
85
+ last_position.turn_to_topside? # => true
86
+ ```
87
+
88
+ Another example with Xiangqi's Short Double Cannons Checkmate:
89
+
90
+ ```ruby
91
+ require 'qi'
92
+
93
+ starting_position = Qi::Position.new(
94
+ '車', '馬', '象', '士', '將', '士', '象', '馬', '車',
95
+ nil, nil, nil, nil, nil, nil, nil, nil, nil,
96
+ nil, '砲', nil, nil, nil, nil, nil, '砲', nil,
97
+ '卒', nil, '卒', nil, '卒', nil, '卒', nil, '卒',
98
+ nil, nil, nil, nil, nil, nil, nil, nil, nil,
99
+ nil, nil, nil, nil, nil, nil, nil, nil, nil,
100
+ '兵', nil, '兵', nil, '兵', nil, '兵', nil, '兵',
101
+ nil, '炮', nil, nil, nil, nil, nil, '炮', nil,
102
+ nil, nil, nil, nil, nil, nil, nil, nil, nil,
103
+ '俥', '傌', '相', '仕', '帥', '仕', '相', '傌', '俥'
104
+ )
105
+
106
+ starting_position.topside_in_hand_pieces # => []
107
+ starting_position.squares # => ["車", "馬", "象", "士", "將", "士", "象", "馬", "車",
108
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
109
+ # nil, "砲", nil, nil, nil, nil, nil, "砲", nil,
110
+ # "卒", nil, "卒", nil, "卒", nil, "卒", nil, "卒",
111
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
112
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
113
+ # "兵", nil, "兵", nil, "兵", nil, "兵", nil, "兵",
114
+ # nil, "炮", nil, nil, nil, nil, nil, "炮", nil,
115
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
116
+ # "俥", "傌", "相", "仕", "帥", "仕", "相", "傌", "俥"]
117
+ starting_position.bottomside_in_hand_pieces # => []
118
+ starting_position.in_hand_pieces # => []
119
+ starting_position.turn_to_topside? # => false
120
+
121
+ moves = [
122
+ [ 64, 67, '炮' ],
123
+ [ 25, 22, '砲' ],
124
+ [ 70, 52, '炮' ],
125
+ [ 19, 55, '砲' ],
126
+ [ 67, 31, '炮' ],
127
+ [ 22, 58, '砲' ],
128
+ [ 52, 49, '炮' ]
129
+ ]
130
+
131
+ last_position = moves.reduce(starting_position) do |position, move|
132
+ position.call(move)
133
+ end
134
+
135
+ last_position.topside_in_hand_pieces # => []
136
+ last_position.squares # => ["車", "馬", "象", "士", "將", "士", "象", "馬", "車",
137
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
138
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
139
+ # "卒", nil, "卒", nil, "炮", nil, "卒", nil, "卒",
140
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
141
+ # nil, nil, nil, nil, "炮", nil, nil, nil, nil,
142
+ # "兵", "砲", "兵", nil, "砲", nil, "兵", nil, "兵",
143
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
144
+ # nil, nil, nil, nil, nil, nil, nil, nil, nil,
145
+ # "俥", "傌", "相", "仕", "帥", "仕", "相", "傌", "俥"]
146
+ last_position.bottomside_in_hand_pieces # => []
147
+ last_position.in_hand_pieces # => []
72
148
  last_position.turn_to_topside? # => true
73
149
  ```
74
150
 
@@ -83,6 +159,5 @@ The `qi` gem is maintained by [Sashite](https://sashite.com/).
83
159
  With some [lines of code](https://github.com/sashite/), let's share the beauty of Chinese, Japanese and Western cultures through the game of chess!
84
160
 
85
161
  [gem]: https://rubygems.org/gems/qi
86
- [travis]: https://travis-ci.org/sashite/qi.rb
87
162
  [inchpages]: https://inch-ci.org/github/sashite/qi.rb
88
163
  [rubydoc]: https://rubydoc.info/gems/qi/frames
@@ -5,10 +5,27 @@ module Qi
5
5
  #
6
6
  # @see https://developer.sashite.com/specs/portable-chess-notation
7
7
  class Position
8
- attr_reader :squares, :bottomside_in_hand_pieces, :topside_in_hand_pieces
8
+ # The list of squares of on the board.
9
+ #
10
+ # @!attribute [r] squares
11
+ # @return [Array] The list of squares.
12
+ attr_reader :squares
13
+
14
+ # The list of pieces in hand owned by the bottomside player.
15
+ #
16
+ # @!attribute [r] bottomside_in_hand_pieces
17
+ # @return [Array] The list of bottomside's pieces in hand.
18
+ attr_reader :bottomside_in_hand_pieces
19
+
20
+ # The list of pieces in hand owned by the topside player.
21
+ #
22
+ # @!attribute [r] topside_in_hand_pieces
23
+ # @return [Array] The list of topside's pieces in hand.
24
+ attr_reader :topside_in_hand_pieces
9
25
 
10
26
  # Initialize a position.
11
27
  #
28
+ # @param squares [Array] The list of squares of on the board.
12
29
  # @param is_turn_to_topside [Boolean] The player who must play.
13
30
  # @param bottomside_in_hand_pieces [Array] The list of bottom-side's pieces in hand.
14
31
  # @param topside_in_hand_pieces [Array] The list of top-side's pieces in hand.
@@ -79,7 +96,15 @@ module Qi
79
96
  topside_in_hand_pieces: updated_topside_in_hand_pieces)
80
97
  end
81
98
 
82
- # The player who must play.
99
+ # The list of pieces in hand owned by the current player.
100
+ #
101
+ # @return [Array] Topside's pieces in hand if turn to topside, bottomside's
102
+ # ones otherwise.
103
+ def in_hand_pieces
104
+ turn_to_topside? ? topside_in_hand_pieces : bottomside_in_hand_pieces
105
+ end
106
+
107
+ # The side who must play.
83
108
  #
84
109
  # @return [Boolean] True if it is turn to topside, false otherwise.
85
110
  def turn_to_topside?
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.0.0
4
+ version: 6.1.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-07-09 00:00:00.000000000 Z
11
+ date: 2020-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brutal
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '='
60
- - !ruby/object:Gem::Version
61
- version: 0.86.0
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '='
67
- - !ruby/object:Gem::Version
68
- version: 0.86.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rubocop-performance
71
57
  requirement: !ruby/object:Gem::Requirement