shogi-ruby 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +8 -0
- data/README.md +42 -6
- data/lib/shogi/board.rb +27 -5
- data/lib/shogi/version.rb +1 -1
- data/shogi-ruby.gemspec +2 -2
- data/test/test-board.rb +4 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1d9adb763c45ed657013e948eafbf95dcf725f5
|
4
|
+
data.tar.gz: b9de61f51fe8558c46dddc5874b0be4b5056a9de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf5a19186b114727ba3b79da84cd09d416232dfb96b4291214b1261c7c3a644f6a0e51745245c19f1d14e0559f4f06044d64f937ed1c875a503ad00a6726cc19
|
7
|
+
data.tar.gz: a6b4c96e15a308904430aecdbea5819fd5f1218209a8cf8950dcd95463af15435bea6781d28f5f97f4b76e757fc3d4b7fe761208f93cdb32d3aa7fc1b9f7877c
|
data/NEWS.md
ADDED
data/README.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
-
# Shogi Library
|
1
|
+
# Shogi Library by Pure Ruby [![Build Status](https://secure.travis-ci.org/myokoym/shogi-ruby.png?branch=master)](http://travis-ci.org/myokoym/shogi-ruby)
|
2
2
|
|
3
|
-
Ruby用の将棋ライブラリです。
|
3
|
+
Ruby用の将棋ライブラリです。
|
4
|
+
|
5
|
+
## 特徴
|
6
|
+
|
7
|
+
* Rubyのみで記述されています。
|
8
|
+
* デバッグが楽です。
|
9
|
+
* インストールが楽です。
|
10
|
+
* CSA形式に対応しています。
|
11
|
+
* コンピュータ将棋協会が推奨する標準形式です。
|
4
12
|
|
5
13
|
## 用途
|
6
14
|
### 向いていること
|
@@ -43,6 +51,32 @@ Ruby 2.0.0 or later. (and 1.9.3)
|
|
43
51
|
|
44
52
|
## Usage
|
45
53
|
|
54
|
+
### Introduction
|
55
|
+
|
56
|
+
* 使う準備
|
57
|
+
|
58
|
+
require 'shogi'
|
59
|
+
|
60
|
+
* 対局を管理するクラス
|
61
|
+
|
62
|
+
Shogi::Game
|
63
|
+
|
64
|
+
* 盤面を管理するクラス
|
65
|
+
|
66
|
+
Shogi::Board
|
67
|
+
|
68
|
+
* 局面の情報をCSA形式で取得するメソッド
|
69
|
+
|
70
|
+
Shogi::Game#to_csa
|
71
|
+
Shogi::Board#to_csa
|
72
|
+
|
73
|
+
* 駒を動かすメソッド
|
74
|
+
|
75
|
+
Shogi::Game#move
|
76
|
+
Shogi::Board#move
|
77
|
+
|
78
|
+
### Tutorial
|
79
|
+
|
46
80
|
require 'shogi'
|
47
81
|
|
48
82
|
board = Shogi::Board.new
|
@@ -143,7 +177,12 @@ Ruby 2.0.0 or later. (and 1.9.3)
|
|
143
177
|
-3122GI
|
144
178
|
+0055KA
|
145
179
|
|
146
|
-
game.at(3).
|
180
|
+
puts game.at(3).kifu
|
181
|
+
#=> +7776FU
|
182
|
+
-3334FU
|
183
|
+
+8822UM
|
184
|
+
|
185
|
+
game.at(3).show
|
147
186
|
#=> P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
|
148
187
|
P2 * -HI * * * * * +UM *
|
149
188
|
P3-FU-FU-FU-FU-FU-FU * -FU-FU
|
@@ -156,9 +195,6 @@ Ruby 2.0.0 or later. (and 1.9.3)
|
|
156
195
|
P+00KA
|
157
196
|
P-
|
158
197
|
-
|
159
|
-
+7776FU
|
160
|
-
-3334FU
|
161
|
-
+8822UM
|
162
198
|
|
163
199
|
## Contributing
|
164
200
|
|
data/lib/shogi/board.rb
CHANGED
@@ -126,6 +126,12 @@ module Shogi
|
|
126
126
|
self
|
127
127
|
end
|
128
128
|
|
129
|
+
def at(place)
|
130
|
+
array_x = to_array_x_from_shogi_x(place[0].to_i)
|
131
|
+
array_y = to_array_y_from_shogi_y(place[1].to_i)
|
132
|
+
@position[array_y][array_x]
|
133
|
+
end
|
134
|
+
|
129
135
|
def show(format=@default_format)
|
130
136
|
$stdout.puts __send__("to_#{format}")
|
131
137
|
end
|
@@ -160,8 +166,8 @@ module Shogi
|
|
160
166
|
before_cell = before_piece
|
161
167
|
before_piece = Piece.const_get(before_cell[1..2]).new
|
162
168
|
else
|
163
|
-
before_x =
|
164
|
-
before_y = csa[2].to_i
|
169
|
+
before_x = to_array_x_from_shogi_x(csa[1].to_i)
|
170
|
+
before_y = to_array_y_from_shogi_y(csa[2].to_i)
|
165
171
|
before_cell = @position[before_y][before_x]
|
166
172
|
if before_cell == ""
|
167
173
|
raise MoveError, "Before cell is blank"
|
@@ -177,7 +183,7 @@ module Shogi
|
|
177
183
|
raise MoveError, "Don't promote: #{before_cell[1..2]} -> #{csa[5..6]}"
|
178
184
|
end
|
179
185
|
|
180
|
-
after_y = csa[4].to_i
|
186
|
+
after_y = to_array_y_from_shogi_y(csa[4].to_i)
|
181
187
|
if csa[0] == "+"
|
182
188
|
unless after_y < 3 || before_y < 3
|
183
189
|
raise_movement_error("Don't promote this move: #{csa}")
|
@@ -190,8 +196,8 @@ module Shogi
|
|
190
196
|
end
|
191
197
|
end
|
192
198
|
|
193
|
-
after_x =
|
194
|
-
after_y = csa[4].to_i
|
199
|
+
after_x = to_array_x_from_shogi_x(csa[3].to_i)
|
200
|
+
after_y = to_array_y_from_shogi_y(csa[4].to_i)
|
195
201
|
after_cell = @position[after_y][after_x]
|
196
202
|
if csa[0] == after_cell[0]
|
197
203
|
raise MoveError, "Your piece on after cell: #{csa}"
|
@@ -250,5 +256,21 @@ module Shogi
|
|
250
256
|
raise MovementError, message
|
251
257
|
end
|
252
258
|
end
|
259
|
+
|
260
|
+
def to_array_x_from_shogi_x(shogi_x)
|
261
|
+
9 - shogi_x
|
262
|
+
end
|
263
|
+
|
264
|
+
def to_array_y_from_shogi_y(shogi_y)
|
265
|
+
shogi_y - 1
|
266
|
+
end
|
267
|
+
|
268
|
+
def to_shogi_x_from_array_x(array_x)
|
269
|
+
9 - array_x
|
270
|
+
end
|
271
|
+
|
272
|
+
def to_shogi_y_from_array_y(array_y)
|
273
|
+
array_y + 1
|
274
|
+
end
|
253
275
|
end
|
254
276
|
end
|
data/lib/shogi/version.rb
CHANGED
data/shogi-ruby.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Shogi::VERSION
|
9
9
|
spec.authors = ["Masafumi Yokoyama"]
|
10
10
|
spec.email = ["myokoym@gmail.com"]
|
11
|
-
spec.summary = %q{Shogi Library
|
12
|
-
spec.description = %q{Shogi library
|
11
|
+
spec.summary = %q{Shogi Library by Pure Ruby}
|
12
|
+
spec.description = %q{A Shogi library by pure Ruby. It supports CSA format.}
|
13
13
|
spec.homepage = "https://github.com/myokoym/shogi-ruby"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/test/test-board.rb
CHANGED
@@ -119,6 +119,10 @@ lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL
|
|
119
119
|
assert_equal(before_state, @board.instance_variable_get(:@position))
|
120
120
|
end
|
121
121
|
|
122
|
+
def test_at
|
123
|
+
assert_equal("-KY", @board.at("11"))
|
124
|
+
end
|
125
|
+
|
122
126
|
def test_move_csa
|
123
127
|
@board.default_format = :csa
|
124
128
|
|
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.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masafumi Yokoyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description: Shogi library
|
83
|
+
description: A Shogi library by pure Ruby. It supports CSA format.
|
84
84
|
email:
|
85
85
|
- myokoym@gmail.com
|
86
86
|
executables: []
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- .travis.yml
|
92
92
|
- Gemfile
|
93
93
|
- LICENSE.txt
|
94
|
+
- NEWS.md
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|
96
97
|
- lib/shogi.rb
|
@@ -127,10 +128,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
128
|
version: '0'
|
128
129
|
requirements: []
|
129
130
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.0.
|
131
|
+
rubygems_version: 2.0.3
|
131
132
|
signing_key:
|
132
133
|
specification_version: 4
|
133
|
-
summary: Shogi Library
|
134
|
+
summary: Shogi Library by Pure Ruby
|
134
135
|
test_files:
|
135
136
|
- test/run-test.rb
|
136
137
|
- test/test-board.rb
|