shogi-ruby 0.0.8 → 0.0.9

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
  SHA1:
3
- metadata.gz: 9d04141b8259822f9f675663b36789155a1cefdd
4
- data.tar.gz: 41710950fea3ecf1fe1f8f0a64482bf1a6082874
3
+ metadata.gz: 129ab7f9ea2e8b0576a5f13e10b62d42d3ce7ed4
4
+ data.tar.gz: 5c914717d7a5d59858dd430f01cb9af3981b59d5
5
5
  SHA512:
6
- metadata.gz: b58afe066c75e1aad5879b85b7970e3d1e7ece52c32d762d3e0d05870e920a66a539f0d44289706d5293c86e469431f14d56213138ac398f636629d77867a70d
7
- data.tar.gz: dd95ab16a0e4becef1f23cf2d8957d363886156e2280cba54459f80591a46406e7da36b5e84b77bdbae6023faa6d3679554cea720af1e476a5e8ad97edeb655e
6
+ metadata.gz: be4d6e244dc785666b37505396cf344b5f542b942b075fba215d90e852b145cc0b14194bc4c623303b83e83f1edc4528dad7cd034df0331c1df05f2a99cbae67
7
+ data.tar.gz: b2dec598efa163be2daf9b803c4d3ca371fa68245018d12199ec8a36ae633ada7f190087d6441f87bdd7aa302d0f673a6e978f0dccd3f0ea7a4552f1520a9c17
data/.travis.yml CHANGED
@@ -3,6 +3,7 @@ rvm:
3
3
  - 2.0.0
4
4
  - 2.1
5
5
  - 2.2
6
+ - 2.3.1
6
7
  - jruby-19mode
7
8
  - jruby-head
8
9
  - rbx-2
@@ -12,3 +13,5 @@ matrix:
12
13
  - rvm: jruby-head
13
14
  - rvm: rbx-2
14
15
  fast_finish: true
16
+ before_install:
17
+ - gem update bundler
data/NEWS.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.0.9: 2016-06-24
4
+
5
+ ### Changes
6
+
7
+ * Improvements
8
+ * Improved mevement error detection. [Patch by Shigeaki Matsumura]
9
+ * Implemented Nifu restriction in `move_by_csa`. [Patch by Toru YAGI]
10
+
11
+ ### Thanks
12
+
13
+ * Shigeaki Matsumura
14
+ * Toru YAGI
15
+
3
16
  ## 0.0.8: 2015-05-31
4
17
 
5
18
  ### Changes
@@ -7,6 +20,7 @@
7
20
  * Improvements
8
21
  * Supported Bundler.require (require "shogi-ruby").
9
22
  * Added Board.register and Cell.register as plugin system.
23
+ * Removed a deprecated method `move_from_csa`.
10
24
  * Fixes
11
25
  * Fixed error messages.
12
26
 
data/README.md CHANGED
@@ -31,7 +31,6 @@ Ruby用の将棋ライブラリです。
31
31
 
32
32
  ### まだできないこと
33
33
 
34
- * 二歩チェック
35
34
  * 行きどころのない駒のチェック
36
35
  * 詰みチェック
37
36
  * 手番チェック
@@ -126,13 +126,31 @@ module Shogi
126
126
  unless after_cell == ""
127
127
  raise MoveError, "A piece exists in the cell: #{csa}"
128
128
  end
129
+ if csa[5..6] == "FU"
130
+ (1..9).each do |y|
131
+ cell = @table[to_array_y_from_shogi_y(y)][after_x]
132
+ if cell[1..2] == "FU" && cell[0] == csa[0]
133
+ raise_movement_error("Your FU exists in the cell of the same column: #{csa[3]}#{y}")
134
+ end
135
+ end
136
+ end
129
137
  else
130
- if csa[0] == "+"
131
- movement_x = after_x - before_x
132
- movement_y = before_y - after_y
133
- else
134
- movement_x = before_x - after_x
135
- movement_y = after_y - before_y
138
+ sign = csa[0] == '+' ? 1 : -1
139
+ movement_x = (after_x - before_x) * sign
140
+ movement_y = (before_y - after_y) * sign
141
+
142
+ if (movement_x == 0 || movement_y == 0 || movement_x.abs == movement_y.abs) &&
143
+ [movement_x.abs, movement_y.abs].max >= 2
144
+ xs = (-(movement_x.abs-1)...0).map{|x| sign * (movement_x <=> 0) * x}
145
+ ys = (-(movement_y.abs-1)...0).map{|x| sign * (movement_y <=> 0) * x}
146
+ (xs.empty? ? [0] * ys.size : xs).zip(ys)
147
+ .map{|x, y| [csa[1].to_i + (x || 0), csa[2].to_i + (y || 0)]}
148
+ .each do |x, y|
149
+ if (1..9).include?(x) && (1..9).include?(y)
150
+ piece = @table[to_array_y_from_shogi_y(y)][to_array_x_from_shogi_x(x)]
151
+ raise_movement_error("Can't jump over a piece: #{piece}") if piece && !piece.empty?
152
+ end
153
+ end
136
154
  end
137
155
 
138
156
  unless before_piece.move?(movement_x, movement_y)
data/lib/shogi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Shogi
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/test/test-board.rb CHANGED
@@ -138,6 +138,9 @@ lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL
138
138
  assert_raise Shogi::MoveError do
139
139
  assert_false(@board.move("+2827HI"))
140
140
  end
141
+ assert_raise Shogi::MovementError do
142
+ assert_false(@board.move("+2826HI"))
143
+ end
141
144
  assert_raise Shogi::MoveError do
142
145
  assert_false(@board.move("+2625FU"))
143
146
  end
@@ -147,6 +150,12 @@ lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL
147
150
  assert_raise Shogi::MoveError do
148
151
  assert_false(@board.move("-4131KI"))
149
152
  end
153
+ assert_raise Shogi::MovementError do
154
+ assert_false(@board.move("+8855KA"))
155
+ end
156
+ assert_raise Shogi::MovementError do
157
+ assert_false(@board.move("-1115KY"))
158
+ end
150
159
 
151
160
  assert_nothing_raised do
152
161
  @board.move("+7776FU")
@@ -167,6 +176,10 @@ P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
167
176
  P+
168
177
  P-
169
178
  EOT
179
+
180
+ assert_raise Shogi::MovementError do
181
+ assert_false(@board.move("+8833UM").move("-2233KA").move("+0016FU"))
182
+ end
170
183
  end
171
184
 
172
185
  def test_move_csa_chain
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shogi-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Yokoyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-31 00:00:00.000000000 Z
11
+ date: 2016-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.2.2
137
+ rubygems_version: 2.5.1
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Shogi Library by Pure Ruby