shogi-ruby 0.0.3 → 0.0.4

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: 1d5a3884fbd500566d19348e3068232b1e0b2daa
4
- data.tar.gz: 19c5fd3246ff70a0dffd7ff6ec6719bdb5605150
3
+ metadata.gz: f7ea7a70b01d669d4b55ca2a11c3149a935db714
4
+ data.tar.gz: 766861abedd8ea54df7ee9e7871fbfcf08443b23
5
5
  SHA512:
6
- metadata.gz: 3690d7afaa7f2305d4c892f98f636831f98c9c01fd96c78f1f6802b4a1318c20f5f7c19e7372401dfd869dcad1dfaf3cf694dbde9a9602b7d1c9975d96861226
7
- data.tar.gz: 419b0e66515dd7c6ed60e982a469b880e9ee2a115d02f3c63c03ee370767467bcf5dc82f06307ff7c9e8179fadf926f6891a041c48abcf76547a8230295cb3bd
6
+ metadata.gz: 560a483bed7ed230c6afdcb8fc35ca01650d690fcd33a41eb13e28ee6499f66619c6d17c56938649ab7645e78fc8fe1d4bc7fd3008f297d1eeb75392aa745e5a
7
+ data.tar.gz: 71a834cc25998693c9525633ffb2cbabd396f27b78c9b1f49a9a35aebdc8eb88ebd64bca8bb4cb57afb09eb61cd2b51d293c6714907358951f87c7dc6edb0616
data/README.md CHANGED
@@ -12,15 +12,15 @@ Ruby用の将棋ライブラリです。
12
12
 
13
13
  ## 機能
14
14
  ### できること
15
- * CSA形式で、将棋盤オブジェクトを作成、操作、表示できます。
16
- * 駒の動きが正しいかどうかチェックできます。
15
+ * CSA形式で、将棋盤オブジェクトを作成、操作、表示
16
+ * 駒の動きが正しいかどうかのチェック
17
+ * 棋譜の管理
17
18
 
18
19
  ### まだできないこと
19
20
  * 二歩チェック
20
21
  * 行きどころのない駒のチェック
21
22
  * 詰みチェック
22
- * 手番の管理
23
- * 棋譜の管理
23
+ * 手番チェック
24
24
  * USI形式との相互変換
25
25
 
26
26
  ## Installation
@@ -59,8 +59,23 @@ Ruby 2.0.0 or later. (and 1.9.3)
59
59
  P+
60
60
  P-
61
61
 
62
- board.move("+7776FU", :csa)
63
- puts board.to_csa
62
+ game = Shogi::Game.new
63
+ puts game.to_csa
64
+ #=> P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
65
+ P2 * -HI * * * * * -KA *
66
+ P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
67
+ P4 * * * * * * * * *
68
+ P5 * * * * * * * * *
69
+ P6 * * * * * * * * *
70
+ P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
71
+ P8 * +KA * * * * * +HI *
72
+ P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
73
+ P+
74
+ P-
75
+ +
76
+
77
+ game.move("+7776FU", :csa)
78
+ puts game.to_csa
64
79
  #=> P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
65
80
  P2 * -HI * * * * * -KA *
66
81
  P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
@@ -72,10 +87,11 @@ Ruby 2.0.0 or later. (and 1.9.3)
72
87
  P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
73
88
  P+
74
89
  P-
90
+ -
75
91
 
76
- board.move("-3334FU", :csa)
77
- board.move("+8822UM", :csa)
78
- puts board.to_csa
92
+ game.move("-3334FU", :csa)
93
+ game.move("+8822UM", :csa)
94
+ puts game.to_csa
79
95
  #=> P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
80
96
  P2 * -HI * * * * * +UM *
81
97
  P3-FU-FU-FU-FU-FU-FU * -FU-FU
@@ -87,11 +103,12 @@ Ruby 2.0.0 or later. (and 1.9.3)
87
103
  P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
88
104
  P+00KA
89
105
  P-
106
+ -
90
107
 
91
- board.default_format = :csa
92
- board.move("-3122GI")
93
- board.move("+0055KA")
94
- board.show
108
+ game.default_format = :csa
109
+ game.move("-3122GI")
110
+ game.move("+0055KA")
111
+ game.show
95
112
  #=> P1-KY-KE-GI-KI-OU-KI * -KE-KY
96
113
  P2 * -HI * * * * * -GI *
97
114
  P3-FU-FU-FU-FU-FU-FU * -FU-FU
@@ -103,6 +120,31 @@ Ruby 2.0.0 or later. (and 1.9.3)
103
120
  P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
104
121
  P+
105
122
  P-00KA
123
+ -
124
+
125
+ puts game.kifu
126
+ #=> +7776FU
127
+ -3334FU
128
+ +8822UM
129
+ -3122GI
130
+ +0055KA
131
+
132
+ game.at(3).show_all
133
+ #=> P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
134
+ P2 * -HI * * * * * +UM *
135
+ P3-FU-FU-FU-FU-FU-FU * -FU-FU
136
+ P4 * * * * * * -FU * *
137
+ P5 * * * * * * * * *
138
+ P6 * * +FU * * * * * *
139
+ P7+FU+FU * +FU+FU+FU+FU+FU+FU
140
+ P8 * * * * * * * +HI *
141
+ P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
142
+ P+00KA
143
+ P-
144
+ -
145
+ +7776FU
146
+ -3334FU
147
+ +8822UM
106
148
 
107
149
  ## Contributing
108
150
 
@@ -114,7 +114,7 @@ module Shogi
114
114
  end
115
115
 
116
116
  def move_from_csa(movement)
117
- $stderr.puts "warning: Shogi::Board#move_from_csa(movement) is deplicated. Use Shogi::Board#move(movement, :csa)"
117
+ $stderr.puts "warning: Shogi::Board#move_from_csa(movement) is deprecated. Use Shogi::Board#move(movement, :csa)"
118
118
  move(movement, :csa)
119
119
  end
120
120
 
@@ -2,14 +2,15 @@ module Shogi
2
2
  class Game
3
3
  attr_accessor :default_format
4
4
  attr_reader :turn
5
- def initialize(format=:csa, turn="+", kifu=[])
5
+ def initialize(format=:csa, turn="+")
6
6
  raise ArgumentError, "Undefined format: #{format}" unless /\Acsa\z/ =~ format
7
7
  raise ArgumentError, "Invalid turn: #{turn}" unless /\A[+-]\z/ =~ turn
8
8
 
9
9
  @default_format = format
10
10
  @board = Shogi::Board.new(@default_format)
11
11
  @turn = turn
12
- @kifu = kifu
12
+ @kifu = []
13
+ @states_of_the_game = [] << Marshal.dump(self)
13
14
  end
14
15
 
15
16
  def to_csa
@@ -19,9 +20,10 @@ module Shogi
19
20
  def move(movement_lines, format=@default_format)
20
21
  movement_lines.each_line do |movement|
21
22
  movement.chomp!
22
- @kifu << movement
23
23
  @board.move(movement, format)
24
+ @kifu << movement
24
25
  @turn = (@turn == "+") ? "-" : "+"
26
+ @states_of_the_game << Marshal.dump(self)
25
27
  end
26
28
  self
27
29
  end
@@ -33,5 +35,14 @@ module Shogi
33
35
  def show(format=@default_format)
34
36
  $stdout.puts __send__("to_#{format}")
35
37
  end
38
+
39
+ def show_all(format=@default_format)
40
+ show
41
+ $stdout.puts kifu
42
+ end
43
+
44
+ def at(num_of_moves)
45
+ Marshal.load(@states_of_the_game[num_of_moves])
46
+ end
36
47
  end
37
48
  end
@@ -1,3 +1,3 @@
1
1
  module Shogi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Masafumi Yokoyama"]
10
10
  spec.email = ["myokoym@gmail.com"]
11
11
  spec.summary = %q{Shogi Library for Ruby}
12
- spec.description = spec.summary
12
+ spec.description = %q{Shogi library for Ruby. It supports CSA Format.}
13
13
  spec.homepage = "https://github.com/myokoym/shogi-ruby"
14
14
  spec.license = "MIT"
15
15
 
@@ -1,4 +1,5 @@
1
1
  require "shogi/game"
2
+ require "stringio"
2
3
 
3
4
  class GameTest < Test::Unit::TestCase
4
5
  def setup
@@ -58,4 +59,85 @@ P-
58
59
  +2868HI
59
60
  EOT
60
61
  end
62
+
63
+ def test_show
64
+ @game.default_format = :csa
65
+
66
+ s = ""
67
+ io = StringIO.new(s)
68
+ $stdout = io
69
+
70
+ @game.show
71
+
72
+ $stdout = STDOUT
73
+ assert_equal(<<-EOT, s)
74
+ P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
75
+ P2 * -HI * * * * * -KA *
76
+ P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
77
+ P4 * * * * * * * * *
78
+ P5 * * * * * * * * *
79
+ P6 * * * * * * * * *
80
+ P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
81
+ P8 * +KA * * * * * +HI *
82
+ P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
83
+ P+
84
+ P-
85
+ +
86
+ EOT
87
+ end
88
+
89
+ def test_show_all
90
+ @game.default_format = :csa
91
+ @game.move("+7776FU")
92
+ @game.move("-3334FU")
93
+ @game.move("+8822UM")
94
+
95
+ s = ""
96
+ io = StringIO.new(s)
97
+ $stdout = io
98
+
99
+ @game.show_all
100
+
101
+ $stdout = STDOUT
102
+ assert_equal(<<-EOT, s)
103
+ P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
104
+ P2 * -HI * * * * * +UM *
105
+ P3-FU-FU-FU-FU-FU-FU * -FU-FU
106
+ P4 * * * * * * -FU * *
107
+ P5 * * * * * * * * *
108
+ P6 * * +FU * * * * * *
109
+ P7+FU+FU * +FU+FU+FU+FU+FU+FU
110
+ P8 * * * * * * * +HI *
111
+ P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
112
+ P+00KA
113
+ P-
114
+ -
115
+ +7776FU
116
+ -3334FU
117
+ +8822UM
118
+ EOT
119
+ end
120
+
121
+ def test_at
122
+ @game.default_format = :csa
123
+ @game.move("+7776FU")
124
+ @game.move("-3334FU")
125
+ @game.move("+8822UM")
126
+ @game.move("-3122GI")
127
+
128
+ assert_equal(<<-EOT, @game.at(3).to_csa)
129
+ P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
130
+ P2 * -HI * * * * * +UM *
131
+ P3-FU-FU-FU-FU-FU-FU * -FU-FU
132
+ P4 * * * * * * -FU * *
133
+ P5 * * * * * * * * *
134
+ P6 * * +FU * * * * * *
135
+ P7+FU+FU * +FU+FU+FU+FU+FU+FU
136
+ P8 * * * * * * * +HI *
137
+ P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
138
+ P+00KA
139
+ P-
140
+ -
141
+ EOT
142
+ end
61
143
  end
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.3
4
+ version: 0.0.4
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-04-15 00:00:00.000000000 Z
11
+ date: 2013-04-16 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 for Ruby
83
+ description: Shogi library for Ruby. It supports CSA Format.
84
84
  email:
85
85
  - myokoym@gmail.com
86
86
  executables: []