chess 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +12 -0
- data/.github/workflows/ruby.yml +58 -0
- data/.gitignore +2 -2
- data/.rubocop.yml +9 -144
- data/Gemfile.lock +70 -0
- data/README.md +26 -22
- data/Rakefile +1 -0
- data/chess.gemspec +8 -5
- data/docs/Chess.html +157 -0
- data/docs/Chess/BadNotationError.html +237 -0
- data/docs/Chess/Board.html +1759 -0
- data/docs/Chess/CGame.html +2296 -0
- data/docs/Chess/Game.html +1277 -0
- data/docs/Chess/Gnuchess.html +366 -0
- data/docs/Chess/IllegalMoveError.html +137 -0
- data/docs/Chess/InvalidFenFormatError.html +237 -0
- data/docs/Chess/InvalidPgnFormatError.html +217 -0
- data/docs/Chess/Pgn.html +1477 -0
- data/docs/Chess/UTF8Notation.html +270 -0
- data/docs/_index.html +217 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.README.html +116 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +116 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +531 -0
- data/docs/top-level-namespace.html +110 -0
- data/ext/chess.c +1 -1
- data/ext/common.h +7 -3
- data/ext/extconf.rb +1 -1
- data/lib/chess/game.rb +53 -67
- data/lib/chess/gnuchess.rb +49 -53
- data/lib/chess/pgn.rb +10 -12
- data/lib/chess/utf8_notation.rb +3 -0
- data/lib/chess/version.rb +1 -1
- data/test/test_big_pgn_collection.rb +1 -1
- data/test/test_checkmate.rb +4 -4
- data/test/test_errors.rb +22 -0
- data/test/test_fifty_rule_move.rb +2 -2
- data/test/test_game.rb +82 -0
- data/test/test_helper.rb +15 -0
- data/test/test_insufficient_material.rb +4 -4
- data/test/test_move_generator.rb +3 -2
- data/test/test_pgn.rb +35 -0
- data/test/test_pgn_collection.rb +2 -2
- data/test/test_stalemate.rb +1 -1
- data/test/test_threefold_repetition.rb +1 -1
- metadata +112 -10
@@ -0,0 +1,1277 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Class: Chess::Game
|
8
|
+
|
9
|
+
— Chess
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "Chess::Game";
|
19
|
+
relpath = '../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../_index.html">Index (G)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../Chess.html" title="Chess (module)">Chess</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">Game</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Class: Chess::Game
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
<dl>
|
70
|
+
<dt>Inherits:</dt>
|
71
|
+
<dd>
|
72
|
+
<span class="inheritName"><span class='object_link'><a href="CGame.html" title="Chess::CGame (class)">CGame</a></span></span>
|
73
|
+
|
74
|
+
<ul class="fullTree">
|
75
|
+
<li>Object</li>
|
76
|
+
|
77
|
+
<li class="next"><span class='object_link'><a href="CGame.html" title="Chess::CGame (class)">CGame</a></span></li>
|
78
|
+
|
79
|
+
<li class="next">Chess::Game</li>
|
80
|
+
|
81
|
+
</ul>
|
82
|
+
<a href="#" class="inheritanceTree">show all</a>
|
83
|
+
|
84
|
+
</dd>
|
85
|
+
</dl>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
<dl>
|
98
|
+
<dt>Defined in:</dt>
|
99
|
+
<dd>lib/chess/game.rb</dd>
|
100
|
+
</dl>
|
101
|
+
|
102
|
+
</div>
|
103
|
+
|
104
|
+
<h2>Overview</h2><div class="docstring">
|
105
|
+
<div class="discussion">
|
106
|
+
|
107
|
+
<p>This class rappresents a chess game.</p>
|
108
|
+
|
109
|
+
|
110
|
+
</div>
|
111
|
+
</div>
|
112
|
+
<div class="tags">
|
113
|
+
|
114
|
+
|
115
|
+
</div>
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
<h2>
|
124
|
+
Class Method Summary
|
125
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
126
|
+
</h2>
|
127
|
+
|
128
|
+
<ul class="summary">
|
129
|
+
|
130
|
+
<li class="public ">
|
131
|
+
<span class="summary_signature">
|
132
|
+
|
133
|
+
<a href="#load_fen-class_method" title="load_fen (class method)">.<strong>load_fen</strong>(fen) ⇒ Game </a>
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
</span>
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
<span class="summary_desc"><div class='inline'>
|
148
|
+
<p>Creates a new game from a FEN string.</p>
|
149
|
+
</div></span>
|
150
|
+
|
151
|
+
</li>
|
152
|
+
|
153
|
+
|
154
|
+
<li class="public ">
|
155
|
+
<span class="summary_signature">
|
156
|
+
|
157
|
+
<a href="#load_pgn-class_method" title="load_pgn (class method)">.<strong>load_pgn</strong>(file) ⇒ Game </a>
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
</span>
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
<span class="summary_desc"><div class='inline'>
|
172
|
+
<p>Creates a new game from a file in PGN format.</p>
|
173
|
+
</div></span>
|
174
|
+
|
175
|
+
</li>
|
176
|
+
|
177
|
+
|
178
|
+
</ul>
|
179
|
+
|
180
|
+
<h2>
|
181
|
+
Instance Method Summary
|
182
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
183
|
+
</h2>
|
184
|
+
|
185
|
+
<ul class="summary">
|
186
|
+
|
187
|
+
<li class="public ">
|
188
|
+
<span class="summary_signature">
|
189
|
+
|
190
|
+
<a href="#active_player-instance_method" title="#active_player (instance method)">#<strong>active_player</strong> ⇒ Symbol </a>
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
</span>
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
<span class="summary_desc"><div class='inline'>
|
205
|
+
<p>Returns <code>:white</code> if the active player is the white player, <code>:black</code> otherwise.</p>
|
206
|
+
</div></span>
|
207
|
+
|
208
|
+
</li>
|
209
|
+
|
210
|
+
|
211
|
+
<li class="public ">
|
212
|
+
<span class="summary_signature">
|
213
|
+
|
214
|
+
<a href="#inactive_player-instance_method" title="#inactive_player (instance method)">#<strong>inactive_player</strong> ⇒ Symbol </a>
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
</span>
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
<span class="summary_desc"><div class='inline'>
|
229
|
+
<p>Returns <code>:white</code> if the inactive player is the white player, <code>:black</code> otherwise.</p>
|
230
|
+
</div></span>
|
231
|
+
|
232
|
+
</li>
|
233
|
+
|
234
|
+
|
235
|
+
<li class="public ">
|
236
|
+
<span class="summary_signature">
|
237
|
+
|
238
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(moves = []) ⇒ Game </a>
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
</span>
|
243
|
+
|
244
|
+
|
245
|
+
<span class="note title constructor">constructor</span>
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
<span class="summary_desc"><div class='inline'>
|
255
|
+
<p>A new instance of Game.</p>
|
256
|
+
</div></span>
|
257
|
+
|
258
|
+
</li>
|
259
|
+
|
260
|
+
|
261
|
+
<li class="public ">
|
262
|
+
<span class="summary_signature">
|
263
|
+
|
264
|
+
<a href="#move-instance_method" title="#move (instance method)">#<strong>move</strong>(notation) ⇒ String </a>
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
(also: #move=, #<<)
|
269
|
+
|
270
|
+
</span>
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
<span class="summary_desc"><div class='inline'>
|
281
|
+
<p>Make a move.</p>
|
282
|
+
</div></span>
|
283
|
+
|
284
|
+
</li>
|
285
|
+
|
286
|
+
|
287
|
+
<li class="public ">
|
288
|
+
<span class="summary_signature">
|
289
|
+
|
290
|
+
<a href="#moves=-instance_method" title="#moves= (instance method)">#<strong>moves=</strong>(moves) ⇒ Object </a>
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
</span>
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
<span class="summary_desc"><div class='inline'>
|
305
|
+
<p>Make the array of moves.</p>
|
306
|
+
</div></span>
|
307
|
+
|
308
|
+
</li>
|
309
|
+
|
310
|
+
|
311
|
+
<li class="public ">
|
312
|
+
<span class="summary_signature">
|
313
|
+
|
314
|
+
<a href="#over%3F-instance_method" title="#over? (instance method)">#<strong>over?</strong> ⇒ Boolean </a>
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
</span>
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
<span class="summary_desc"><div class='inline'>
|
329
|
+
<p>Returns <code>true</code> if the game is over.</p>
|
330
|
+
</div></span>
|
331
|
+
|
332
|
+
</li>
|
333
|
+
|
334
|
+
|
335
|
+
<li class="public ">
|
336
|
+
<span class="summary_signature">
|
337
|
+
|
338
|
+
<a href="#pgn-instance_method" title="#pgn (instance method)">#<strong>pgn</strong> ⇒ Chess::Pgn </a>
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
</span>
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
<span class="summary_desc"><div class='inline'>
|
353
|
+
<p>Returns the PGN rappresenting the game.</p>
|
354
|
+
</div></span>
|
355
|
+
|
356
|
+
</li>
|
357
|
+
|
358
|
+
|
359
|
+
<li class="public ">
|
360
|
+
<span class="summary_signature">
|
361
|
+
|
362
|
+
<a href="#status-instance_method" title="#status (instance method)">#<strong>status</strong> ⇒ Symbol </a>
|
363
|
+
|
364
|
+
|
365
|
+
|
366
|
+
</span>
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
<span class="summary_desc"><div class='inline'>
|
377
|
+
<p>Returns the status of the game.</p>
|
378
|
+
</div></span>
|
379
|
+
|
380
|
+
</li>
|
381
|
+
|
382
|
+
|
383
|
+
</ul>
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
<h3 class="inherited">Methods inherited from <span class='object_link'><a href="CGame.html" title="Chess::CGame (class)">CGame</a></span></h3>
|
396
|
+
<p class="inherited"><span class='object_link'><a href="CGame.html#[]-instance_method" title="Chess::CGame#[] (method)">#[]</a></span>, <span class='object_link'><a href="CGame.html#coord_moves-instance_method" title="Chess::CGame#coord_moves (method)">#coord_moves</a></span>, <span class='object_link'><a href="CGame.html#current-instance_method" title="Chess::CGame#current (method)">#current</a></span>, <span class='object_link'><a href="CGame.html#draw-instance_method" title="Chess::CGame#draw (method)">#draw</a></span>, <span class='object_link'><a href="CGame.html#each-instance_method" title="Chess::CGame#each (method)">#each</a></span>, <span class='object_link'><a href="CGame.html#full_moves-instance_method" title="Chess::CGame#full_moves (method)">#full_moves</a></span>, <span class='object_link'><a href="CGame.html#move2-instance_method" title="Chess::CGame#move2 (method)">#move2</a></span>, <span class='object_link'><a href="CGame.html#move3-instance_method" title="Chess::CGame#move3 (method)">#move3</a></span>, <span class='object_link'><a href="CGame.html#moves-instance_method" title="Chess::CGame#moves (method)">#moves</a></span>, <span class='object_link'><a href="CGame.html#resign-instance_method" title="Chess::CGame#resign (method)">#resign</a></span>, <span class='object_link'><a href="CGame.html#result-instance_method" title="Chess::CGame#result (method)">#result</a></span>, <span class='object_link'><a href="CGame.html#rollback!-instance_method" title="Chess::CGame#rollback! (method)">#rollback!</a></span>, <span class='object_link'><a href="CGame.html#set_fen!-instance_method" title="Chess::CGame#set_fen! (method)">#set_fen!</a></span>, <span class='object_link'><a href="CGame.html#size-instance_method" title="Chess::CGame#size (method)">#size</a></span>, <span class='object_link'><a href="CGame.html#threefold_repetition%3F-instance_method" title="Chess::CGame#threefold_repetition? (method)">#threefold_repetition?</a></span>, <span class='object_link'><a href="CGame.html#to_s-instance_method" title="Chess::CGame#to_s (method)">#to_s</a></span></p>
|
397
|
+
<div id="constructor_details" class="method_details_list">
|
398
|
+
<h2>Constructor Details</h2>
|
399
|
+
|
400
|
+
<div class="method_details first">
|
401
|
+
<h3 class="signature first" id="initialize-instance_method">
|
402
|
+
|
403
|
+
#<strong>initialize</strong>(moves = []) ⇒ <tt><span class='object_link'><a href="" title="Chess::Game (class)">Game</a></span></tt>
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
</h3><div class="docstring">
|
410
|
+
<div class="discussion">
|
411
|
+
|
412
|
+
<p>Returns a new instance of Game.</p>
|
413
|
+
|
414
|
+
|
415
|
+
</div>
|
416
|
+
</div>
|
417
|
+
<div class="tags">
|
418
|
+
<p class="tag_title">Parameters:</p>
|
419
|
+
<ul class="param">
|
420
|
+
|
421
|
+
<li>
|
422
|
+
|
423
|
+
<span class='name'>moves</span>
|
424
|
+
|
425
|
+
|
426
|
+
<span class='type'>(<tt>Array<String></tt>)</span>
|
427
|
+
|
428
|
+
|
429
|
+
<em class="default">(defaults to: <tt>[]</tt>)</em>
|
430
|
+
|
431
|
+
|
432
|
+
—
|
433
|
+
<div class='inline'>
|
434
|
+
<p>If an array of moves is provided, the moves will be performed.</p>
|
435
|
+
</div>
|
436
|
+
|
437
|
+
</li>
|
438
|
+
|
439
|
+
</ul>
|
440
|
+
|
441
|
+
<p class="tag_title">Raises:</p>
|
442
|
+
<ul class="raise">
|
443
|
+
|
444
|
+
<li>
|
445
|
+
|
446
|
+
|
447
|
+
<span class='type'>(<tt><span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span></tt>)</span>
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
</li>
|
452
|
+
|
453
|
+
<li>
|
454
|
+
|
455
|
+
|
456
|
+
<span class='type'>(<tt><span class='object_link'><a href="BadNotationError.html" title="Chess::BadNotationError (class)">BadNotationError</a></span></tt>)</span>
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
</li>
|
461
|
+
|
462
|
+
</ul>
|
463
|
+
|
464
|
+
</div><table class="source_code">
|
465
|
+
<tr>
|
466
|
+
<td>
|
467
|
+
<pre class="lines">
|
468
|
+
|
469
|
+
|
470
|
+
9
|
471
|
+
10
|
472
|
+
11
|
473
|
+
12</pre>
|
474
|
+
</td>
|
475
|
+
<td>
|
476
|
+
<pre class="code"><span class="info file"># File 'lib/chess/game.rb', line 9</span>
|
477
|
+
|
478
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_moves'>moves</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
479
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
480
|
+
<span class='id identifier rubyid_moves'>moves</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='op'>|</span> <span class='id identifier rubyid_move'>move</span><span class='lparen'>(</span><span class='id identifier rubyid_m'>m</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
481
|
+
<span class='kw'>end</span></pre>
|
482
|
+
</td>
|
483
|
+
</tr>
|
484
|
+
</table>
|
485
|
+
</div>
|
486
|
+
|
487
|
+
</div>
|
488
|
+
|
489
|
+
|
490
|
+
<div id="class_method_details" class="method_details_list">
|
491
|
+
<h2>Class Method Details</h2>
|
492
|
+
|
493
|
+
|
494
|
+
<div class="method_details first">
|
495
|
+
<h3 class="signature first" id="load_fen-class_method">
|
496
|
+
|
497
|
+
.<strong>load_fen</strong>(fen) ⇒ <tt><span class='object_link'><a href="" title="Chess::Game (class)">Game</a></span></tt>
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
</h3><div class="docstring">
|
504
|
+
<div class="discussion">
|
505
|
+
|
506
|
+
<div class="note notetag">
|
507
|
+
<strong>Note:</strong>
|
508
|
+
<div class='inline'>
|
509
|
+
<p>This game do not have history before the FEN placement.</p>
|
510
|
+
</div>
|
511
|
+
</div>
|
512
|
+
|
513
|
+
|
514
|
+
<p>Creates a new game from a FEN string.</p>
|
515
|
+
|
516
|
+
|
517
|
+
</div>
|
518
|
+
</div>
|
519
|
+
<div class="tags">
|
520
|
+
<p class="tag_title">Parameters:</p>
|
521
|
+
<ul class="param">
|
522
|
+
|
523
|
+
<li>
|
524
|
+
|
525
|
+
<span class='name'>fen</span>
|
526
|
+
|
527
|
+
|
528
|
+
<span class='type'>(<tt>String</tt>)</span>
|
529
|
+
|
530
|
+
|
531
|
+
|
532
|
+
—
|
533
|
+
<div class='inline'>
|
534
|
+
<p>The FEN string to laod.</p>
|
535
|
+
</div>
|
536
|
+
|
537
|
+
</li>
|
538
|
+
|
539
|
+
</ul>
|
540
|
+
|
541
|
+
<p class="tag_title">Returns:</p>
|
542
|
+
<ul class="return">
|
543
|
+
|
544
|
+
<li>
|
545
|
+
|
546
|
+
|
547
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Chess::Game (class)">Game</a></span></tt>)</span>
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
</li>
|
552
|
+
|
553
|
+
</ul>
|
554
|
+
<p class="tag_title">Raises:</p>
|
555
|
+
<ul class="raise">
|
556
|
+
|
557
|
+
<li>
|
558
|
+
|
559
|
+
|
560
|
+
<span class='type'>(<tt><span class='object_link'><a href="InvalidFenFormatError.html" title="Chess::InvalidFenFormatError (class)">InvalidFenFormatError</a></span></tt>)</span>
|
561
|
+
|
562
|
+
|
563
|
+
|
564
|
+
</li>
|
565
|
+
|
566
|
+
</ul>
|
567
|
+
|
568
|
+
</div><table class="source_code">
|
569
|
+
<tr>
|
570
|
+
<td>
|
571
|
+
<pre class="lines">
|
572
|
+
|
573
|
+
|
574
|
+
42
|
575
|
+
43
|
576
|
+
44
|
577
|
+
45
|
578
|
+
46
|
579
|
+
47
|
580
|
+
48</pre>
|
581
|
+
</td>
|
582
|
+
<td>
|
583
|
+
<pre class="code"><span class="info file"># File 'lib/chess/game.rb', line 42</span>
|
584
|
+
|
585
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_load_fen'>load_fen</span><span class='lparen'>(</span><span class='id identifier rubyid_fen'>fen</span><span class='rparen'>)</span>
|
586
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="InvalidFenFormatError.html" title="Chess::InvalidFenFormatError (class)">InvalidFenFormatError</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="InvalidFenFormatError.html#initialize-instance_method" title="Chess::InvalidFenFormatError#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_fen'>fen</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^((?:[PRNBQKprnbqk1-8]{1,8}\/){7}[RNBQKPrnbqkp1-8]{1,8})\s(w|b)\s(K?Q?k?q?|-)\s([a-h][1-8]|-)\s(\d+)\s(\d+)$</span><span class='regexp_end'>/</span></span><span class='period'>.</span><span class='id identifier rubyid_match?'>match?</span><span class='lparen'>(</span><span class='id identifier rubyid_fen'>fen</span><span class='rparen'>)</span>
|
587
|
+
|
588
|
+
<span class='id identifier rubyid_game'>game</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Chess.html" title="Chess (module)">Chess</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="" title="Chess::Game (class)">Game</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="#initialize-instance_method" title="Chess::Game#initialize (method)">new</a></span></span>
|
589
|
+
<span class='id identifier rubyid_game'>game</span><span class='period'>.</span><span class='id identifier rubyid_set_fen!'>set_fen!</span><span class='lparen'>(</span><span class='id identifier rubyid_fen'>fen</span><span class='rparen'>)</span>
|
590
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_game'>game</span>
|
591
|
+
<span class='kw'>end</span></pre>
|
592
|
+
</td>
|
593
|
+
</tr>
|
594
|
+
</table>
|
595
|
+
</div>
|
596
|
+
|
597
|
+
<div class="method_details ">
|
598
|
+
<h3 class="signature " id="load_pgn-class_method">
|
599
|
+
|
600
|
+
.<strong>load_pgn</strong>(file) ⇒ <tt><span class='object_link'><a href="" title="Chess::Game (class)">Game</a></span></tt>
|
601
|
+
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
|
606
|
+
</h3><div class="docstring">
|
607
|
+
<div class="discussion">
|
608
|
+
|
609
|
+
<p>Creates a new game from a file in PGN format.</p>
|
610
|
+
|
611
|
+
|
612
|
+
</div>
|
613
|
+
</div>
|
614
|
+
<div class="tags">
|
615
|
+
<p class="tag_title">Parameters:</p>
|
616
|
+
<ul class="param">
|
617
|
+
|
618
|
+
<li>
|
619
|
+
|
620
|
+
<span class='name'>file</span>
|
621
|
+
|
622
|
+
|
623
|
+
<span class='type'>(<tt>String</tt>)</span>
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
—
|
628
|
+
<div class='inline'>
|
629
|
+
<p>The path of the PGN to laod.</p>
|
630
|
+
</div>
|
631
|
+
|
632
|
+
</li>
|
633
|
+
|
634
|
+
</ul>
|
635
|
+
|
636
|
+
<p class="tag_title">Returns:</p>
|
637
|
+
<ul class="return">
|
638
|
+
|
639
|
+
<li>
|
640
|
+
|
641
|
+
|
642
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Chess::Game (class)">Game</a></span></tt>)</span>
|
643
|
+
|
644
|
+
|
645
|
+
|
646
|
+
</li>
|
647
|
+
|
648
|
+
</ul>
|
649
|
+
<p class="tag_title">Raises:</p>
|
650
|
+
<ul class="raise">
|
651
|
+
|
652
|
+
<li>
|
653
|
+
|
654
|
+
|
655
|
+
<span class='type'>(<tt><span class='object_link'><a href="InvalidPgnFormatError.html" title="Chess::InvalidPgnFormatError (class)">InvalidPgnFormatError</a></span></tt>)</span>
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
</li>
|
660
|
+
|
661
|
+
<li>
|
662
|
+
|
663
|
+
|
664
|
+
<span class='type'>(<tt><span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span></tt>)</span>
|
665
|
+
|
666
|
+
|
667
|
+
|
668
|
+
</li>
|
669
|
+
|
670
|
+
<li>
|
671
|
+
|
672
|
+
|
673
|
+
<span class='type'>(<tt><span class='object_link'><a href="BadNotationError.html" title="Chess::BadNotationError (class)">BadNotationError</a></span></tt>)</span>
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
</li>
|
678
|
+
|
679
|
+
</ul>
|
680
|
+
|
681
|
+
</div><table class="source_code">
|
682
|
+
<tr>
|
683
|
+
<td>
|
684
|
+
<pre class="lines">
|
685
|
+
|
686
|
+
|
687
|
+
20
|
688
|
+
21
|
689
|
+
22
|
690
|
+
23
|
691
|
+
24
|
692
|
+
25
|
693
|
+
26
|
694
|
+
27
|
695
|
+
28
|
696
|
+
29
|
697
|
+
30
|
698
|
+
31
|
699
|
+
32
|
700
|
+
33
|
701
|
+
34
|
702
|
+
35</pre>
|
703
|
+
</td>
|
704
|
+
<td>
|
705
|
+
<pre class="code"><span class="info file"># File 'lib/chess/game.rb', line 20</span>
|
706
|
+
|
707
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_load_pgn'>load_pgn</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='rparen'>)</span>
|
708
|
+
<span class='id identifier rubyid_pgn'>pgn</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Chess.html" title="Chess (module)">Chess</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Pgn.html" title="Chess::Pgn (class)">Pgn</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Pgn.html#initialize-instance_method" title="Chess::Pgn#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='rparen'>)</span>
|
709
|
+
<span class='id identifier rubyid_game'>game</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Chess.html" title="Chess (module)">Chess</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="" title="Chess::Game (class)">Game</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="#initialize-instance_method" title="Chess::Game#initialize (method)">new</a></span></span>
|
710
|
+
<span class='id identifier rubyid_pgn'>pgn</span><span class='period'>.</span><span class='id identifier rubyid_moves'>moves</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='op'>|</span> <span class='id identifier rubyid_game'>game</span><span class='period'>.</span><span class='id identifier rubyid_move'>move</span><span class='lparen'>(</span><span class='id identifier rubyid_m'>m</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
711
|
+
<span class='kw'>unless</span> <span class='id identifier rubyid_game'>game</span><span class='period'>.</span><span class='id identifier rubyid_over?'>over?</span>
|
712
|
+
<span class='kw'>case</span> <span class='id identifier rubyid_pgn'>pgn</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span>
|
713
|
+
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1-0</span><span class='tstring_end'>'</span></span>
|
714
|
+
<span class='id identifier rubyid_game'>game</span><span class='period'>.</span><span class='id identifier rubyid_resign'>resign</span><span class='lparen'>(</span><span class='symbol'>:black</span><span class='rparen'>)</span>
|
715
|
+
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>0-1</span><span class='tstring_end'>'</span></span>
|
716
|
+
<span class='id identifier rubyid_game'>game</span><span class='period'>.</span><span class='id identifier rubyid_resign'>resign</span><span class='lparen'>(</span><span class='symbol'>:white</span><span class='rparen'>)</span>
|
717
|
+
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1/2-1/2</span><span class='tstring_end'>'</span></span>
|
718
|
+
<span class='id identifier rubyid_game'>game</span><span class='period'>.</span><span class='id identifier rubyid_draw'>draw</span>
|
719
|
+
<span class='kw'>end</span>
|
720
|
+
<span class='kw'>end</span>
|
721
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_game'>game</span>
|
722
|
+
<span class='kw'>end</span></pre>
|
723
|
+
</td>
|
724
|
+
</tr>
|
725
|
+
</table>
|
726
|
+
</div>
|
727
|
+
|
728
|
+
</div>
|
729
|
+
|
730
|
+
<div id="instance_method_details" class="method_details_list">
|
731
|
+
<h2>Instance Method Details</h2>
|
732
|
+
|
733
|
+
|
734
|
+
<div class="method_details first">
|
735
|
+
<h3 class="signature first" id="active_player-instance_method">
|
736
|
+
|
737
|
+
#<strong>active_player</strong> ⇒ <tt>Symbol</tt>
|
738
|
+
|
739
|
+
|
740
|
+
|
741
|
+
|
742
|
+
|
743
|
+
</h3><div class="docstring">
|
744
|
+
<div class="discussion">
|
745
|
+
|
746
|
+
<p>Returns <code>:white</code> if the active player is the white player, <code>:black</code> otherwise.</p>
|
747
|
+
|
748
|
+
|
749
|
+
</div>
|
750
|
+
</div>
|
751
|
+
<div class="tags">
|
752
|
+
|
753
|
+
<p class="tag_title">Returns:</p>
|
754
|
+
<ul class="return">
|
755
|
+
|
756
|
+
<li>
|
757
|
+
|
758
|
+
|
759
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
760
|
+
|
761
|
+
|
762
|
+
|
763
|
+
</li>
|
764
|
+
|
765
|
+
</ul>
|
766
|
+
|
767
|
+
</div><table class="source_code">
|
768
|
+
<tr>
|
769
|
+
<td>
|
770
|
+
<pre class="lines">
|
771
|
+
|
772
|
+
|
773
|
+
85
|
774
|
+
86
|
775
|
+
87</pre>
|
776
|
+
</td>
|
777
|
+
<td>
|
778
|
+
<pre class="code"><span class="info file"># File 'lib/chess/game.rb', line 85</span>
|
779
|
+
|
780
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_active_player'>active_player</span>
|
781
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_board'>board</span><span class='period'>.</span><span class='id identifier rubyid_active_color'>active_color</span> <span class='op'>?</span> <span class='symbol'>:black</span> <span class='op'>:</span> <span class='symbol'>:white</span>
|
782
|
+
<span class='kw'>end</span></pre>
|
783
|
+
</td>
|
784
|
+
</tr>
|
785
|
+
</table>
|
786
|
+
</div>
|
787
|
+
|
788
|
+
<div class="method_details ">
|
789
|
+
<h3 class="signature " id="inactive_player-instance_method">
|
790
|
+
|
791
|
+
#<strong>inactive_player</strong> ⇒ <tt>Symbol</tt>
|
792
|
+
|
793
|
+
|
794
|
+
|
795
|
+
|
796
|
+
|
797
|
+
</h3><div class="docstring">
|
798
|
+
<div class="discussion">
|
799
|
+
|
800
|
+
<p>Returns <code>:white</code> if the inactive player is the white player, <code>:black</code> otherwise.</p>
|
801
|
+
|
802
|
+
|
803
|
+
</div>
|
804
|
+
</div>
|
805
|
+
<div class="tags">
|
806
|
+
|
807
|
+
<p class="tag_title">Returns:</p>
|
808
|
+
<ul class="return">
|
809
|
+
|
810
|
+
<li>
|
811
|
+
|
812
|
+
|
813
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
814
|
+
|
815
|
+
|
816
|
+
|
817
|
+
</li>
|
818
|
+
|
819
|
+
</ul>
|
820
|
+
|
821
|
+
</div><table class="source_code">
|
822
|
+
<tr>
|
823
|
+
<td>
|
824
|
+
<pre class="lines">
|
825
|
+
|
826
|
+
|
827
|
+
92
|
828
|
+
93
|
829
|
+
94</pre>
|
830
|
+
</td>
|
831
|
+
<td>
|
832
|
+
<pre class="code"><span class="info file"># File 'lib/chess/game.rb', line 92</span>
|
833
|
+
|
834
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_inactive_player'>inactive_player</span>
|
835
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_board'>board</span><span class='period'>.</span><span class='id identifier rubyid_active_color'>active_color</span> <span class='op'>?</span> <span class='symbol'>:white</span> <span class='op'>:</span> <span class='symbol'>:black</span>
|
836
|
+
<span class='kw'>end</span></pre>
|
837
|
+
</td>
|
838
|
+
</tr>
|
839
|
+
</table>
|
840
|
+
</div>
|
841
|
+
|
842
|
+
<div class="method_details ">
|
843
|
+
<h3 class="signature " id="move-instance_method">
|
844
|
+
|
845
|
+
#<strong>move</strong>(notation) ⇒ <tt>String</tt>
|
846
|
+
|
847
|
+
|
848
|
+
|
849
|
+
<span class="aliases">Also known as:
|
850
|
+
<span class="names"><span id='move=-instance_method'>move=</span>, <span id='<<-instance_method'><<</span></span>
|
851
|
+
</span>
|
852
|
+
|
853
|
+
|
854
|
+
|
855
|
+
</h3><div class="docstring">
|
856
|
+
<div class="discussion">
|
857
|
+
|
858
|
+
<div class="note notetag">
|
859
|
+
<strong>Note:</strong>
|
860
|
+
<div class='inline'>
|
861
|
+
<p>This add a new <span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span> in the <span class='object_link'><a href="" title="Chess::Game (class)">Chess::Game</a></span>.</p>
|
862
|
+
</div>
|
863
|
+
</div>
|
864
|
+
|
865
|
+
|
866
|
+
<p>Make a move.</p>
|
867
|
+
|
868
|
+
|
869
|
+
</div>
|
870
|
+
</div>
|
871
|
+
<div class="tags">
|
872
|
+
<p class="tag_title">Parameters:</p>
|
873
|
+
<ul class="param">
|
874
|
+
|
875
|
+
<li>
|
876
|
+
|
877
|
+
<span class='name'>notation</span>
|
878
|
+
|
879
|
+
|
880
|
+
<span class='type'>(<tt>String</tt>)</span>
|
881
|
+
|
882
|
+
|
883
|
+
|
884
|
+
—
|
885
|
+
<div class='inline'>
|
886
|
+
<p>Represents the short algebraic chess notation string of the move. <code>notation</code> can be also <em>from_square</em> plus <em>to_square</em> <em>('e2e4', …, 'b1c3')</em> (coordinate chess notation).</p>
|
887
|
+
</div>
|
888
|
+
|
889
|
+
</li>
|
890
|
+
|
891
|
+
</ul>
|
892
|
+
|
893
|
+
<p class="tag_title">Returns:</p>
|
894
|
+
<ul class="return">
|
895
|
+
|
896
|
+
<li>
|
897
|
+
|
898
|
+
|
899
|
+
<span class='type'>(<tt>String</tt>)</span>
|
900
|
+
|
901
|
+
|
902
|
+
|
903
|
+
—
|
904
|
+
<div class='inline'>
|
905
|
+
<p>Returns a string that represents the short algebraic chess notation of the move.</p>
|
906
|
+
</div>
|
907
|
+
|
908
|
+
</li>
|
909
|
+
|
910
|
+
</ul>
|
911
|
+
<p class="tag_title">Raises:</p>
|
912
|
+
<ul class="raise">
|
913
|
+
|
914
|
+
<li>
|
915
|
+
|
916
|
+
|
917
|
+
<span class='type'>(<tt><span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span></tt>)</span>
|
918
|
+
|
919
|
+
|
920
|
+
|
921
|
+
—
|
922
|
+
<div class='inline'>
|
923
|
+
<p>if the move is illegal.</p>
|
924
|
+
</div>
|
925
|
+
|
926
|
+
</li>
|
927
|
+
|
928
|
+
<li>
|
929
|
+
|
930
|
+
|
931
|
+
<span class='type'>(<tt><span class='object_link'><a href="BadNotationError.html" title="Chess::BadNotationError (class)">BadNotationError</a></span></tt>)</span>
|
932
|
+
|
933
|
+
|
934
|
+
|
935
|
+
—
|
936
|
+
<div class='inline'>
|
937
|
+
<p>if the short algebraic chess notation is malformed.</p>
|
938
|
+
</div>
|
939
|
+
|
940
|
+
</li>
|
941
|
+
|
942
|
+
</ul>
|
943
|
+
|
944
|
+
</div><table class="source_code">
|
945
|
+
<tr>
|
946
|
+
<td>
|
947
|
+
<pre class="lines">
|
948
|
+
|
949
|
+
|
950
|
+
61
|
951
|
+
62
|
952
|
+
63
|
953
|
+
64
|
954
|
+
65
|
955
|
+
66
|
956
|
+
67
|
957
|
+
68
|
958
|
+
69
|
959
|
+
70
|
960
|
+
71
|
961
|
+
72</pre>
|
962
|
+
</td>
|
963
|
+
<td>
|
964
|
+
<pre class="code"><span class="info file"># File 'lib/chess/game.rb', line 61</span>
|
965
|
+
|
966
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_move'>move</span><span class='lparen'>(</span><span class='id identifier rubyid_notation'>notation</span><span class='rparen'>)</span>
|
967
|
+
<span class='id identifier rubyid_expand'>expand</span> <span class='op'>=</span> <span class='id identifier rubyid_expand_move'>expand_move</span><span class='lparen'>(</span><span class='id identifier rubyid_notation'>notation</span><span class='rparen'>)</span>
|
968
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_expand'>expand</span><span class='lbracket'>[</span><span class='symbol'>:from</span><span class='rbracket'>]</span>
|
969
|
+
<span class='id identifier rubyid_move2'>move2</span><span class='lparen'>(</span><span class='id identifier rubyid_expand'>expand</span><span class='lbracket'>[</span><span class='symbol'>:from</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_expand'>expand</span><span class='lbracket'>[</span><span class='symbol'>:to</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_expand'>expand</span><span class='lbracket'>[</span><span class='symbol'>:promotion</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
970
|
+
<span class='kw'>else</span>
|
971
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_expand'>expand</span><span class='lbracket'>[</span><span class='symbol'>:name</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_expand'>expand</span><span class='lbracket'>[</span><span class='symbol'>:dis</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_expand'>expand</span><span class='lbracket'>[</span><span class='symbol'>:to</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_expand'>expand</span><span class='lbracket'>[</span><span class='symbol'>:promotion</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
972
|
+
<span class='kw'>end</span>
|
973
|
+
<span class='kw'>rescue</span> <span class='const'><span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span></span>
|
974
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Illegal move '</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_notation'>notation</span><span class='embexpr_end'>}</span><span class='tstring_content'>'\nStatus: </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_status'>status</span><span class='embexpr_end'>}</span><span class='tstring_content'>\nPlayer turn </span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_active_player'>active_player</span><span class='embexpr_end'>}</span><span class='tstring_content'>\n</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>DEBUG</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
|
975
|
+
|
976
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Illegal move '</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_notation'>notation</span><span class='embexpr_end'>}</span><span class='tstring_content'>'</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
977
|
+
<span class='kw'>end</span></pre>
|
978
|
+
</td>
|
979
|
+
</tr>
|
980
|
+
</table>
|
981
|
+
</div>
|
982
|
+
|
983
|
+
<div class="method_details ">
|
984
|
+
<h3 class="signature " id="moves=-instance_method">
|
985
|
+
|
986
|
+
#<strong>moves=</strong>(moves) ⇒ <tt>Object</tt>
|
987
|
+
|
988
|
+
|
989
|
+
|
990
|
+
|
991
|
+
|
992
|
+
</h3><div class="docstring">
|
993
|
+
<div class="discussion">
|
994
|
+
|
995
|
+
<p>Make the array of moves.</p>
|
996
|
+
|
997
|
+
|
998
|
+
</div>
|
999
|
+
</div>
|
1000
|
+
<div class="tags">
|
1001
|
+
<p class="tag_title">Parameters:</p>
|
1002
|
+
<ul class="param">
|
1003
|
+
|
1004
|
+
<li>
|
1005
|
+
|
1006
|
+
<span class='name'>moves</span>
|
1007
|
+
|
1008
|
+
|
1009
|
+
<span class='type'>(<tt>Array<String></tt>)</span>
|
1010
|
+
|
1011
|
+
|
1012
|
+
|
1013
|
+
—
|
1014
|
+
<div class='inline'>
|
1015
|
+
<p>The array of moves to performe.</p>
|
1016
|
+
</div>
|
1017
|
+
|
1018
|
+
</li>
|
1019
|
+
|
1020
|
+
</ul>
|
1021
|
+
|
1022
|
+
|
1023
|
+
</div><table class="source_code">
|
1024
|
+
<tr>
|
1025
|
+
<td>
|
1026
|
+
<pre class="lines">
|
1027
|
+
|
1028
|
+
|
1029
|
+
78
|
1030
|
+
79
|
1031
|
+
80</pre>
|
1032
|
+
</td>
|
1033
|
+
<td>
|
1034
|
+
<pre class="code"><span class="info file"># File 'lib/chess/game.rb', line 78</span>
|
1035
|
+
|
1036
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_moves='>moves=</span><span class='lparen'>(</span><span class='id identifier rubyid_moves'>moves</span><span class='rparen'>)</span>
|
1037
|
+
<span class='id identifier rubyid_moves'>moves</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='op'>|</span> <span class='id identifier rubyid_move'>move</span><span class='lparen'>(</span><span class='id identifier rubyid_m'>m</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1038
|
+
<span class='kw'>end</span></pre>
|
1039
|
+
</td>
|
1040
|
+
</tr>
|
1041
|
+
</table>
|
1042
|
+
</div>
|
1043
|
+
|
1044
|
+
<div class="method_details ">
|
1045
|
+
<h3 class="signature " id="over?-instance_method">
|
1046
|
+
|
1047
|
+
#<strong>over?</strong> ⇒ <tt>Boolean</tt>
|
1048
|
+
|
1049
|
+
|
1050
|
+
|
1051
|
+
|
1052
|
+
|
1053
|
+
</h3><div class="docstring">
|
1054
|
+
<div class="discussion">
|
1055
|
+
|
1056
|
+
<p>Returns <code>true</code> if the game is over.</p>
|
1057
|
+
|
1058
|
+
|
1059
|
+
</div>
|
1060
|
+
</div>
|
1061
|
+
<div class="tags">
|
1062
|
+
|
1063
|
+
<p class="tag_title">Returns:</p>
|
1064
|
+
<ul class="return">
|
1065
|
+
|
1066
|
+
<li>
|
1067
|
+
|
1068
|
+
|
1069
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
1070
|
+
|
1071
|
+
|
1072
|
+
|
1073
|
+
</li>
|
1074
|
+
|
1075
|
+
</ul>
|
1076
|
+
|
1077
|
+
</div><table class="source_code">
|
1078
|
+
<tr>
|
1079
|
+
<td>
|
1080
|
+
<pre class="lines">
|
1081
|
+
|
1082
|
+
|
1083
|
+
131
|
1084
|
+
132
|
1085
|
+
133</pre>
|
1086
|
+
</td>
|
1087
|
+
<td>
|
1088
|
+
<pre class="code"><span class="info file"># File 'lib/chess/game.rb', line 131</span>
|
1089
|
+
|
1090
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_over?'>over?</span>
|
1091
|
+
<span class='kw'>return</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span> <span class='op'>!=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>*</span><span class='tstring_end'>'</span></span>
|
1092
|
+
<span class='kw'>end</span></pre>
|
1093
|
+
</td>
|
1094
|
+
</tr>
|
1095
|
+
</table>
|
1096
|
+
</div>
|
1097
|
+
|
1098
|
+
<div class="method_details ">
|
1099
|
+
<h3 class="signature " id="pgn-instance_method">
|
1100
|
+
|
1101
|
+
#<strong>pgn</strong> ⇒ <tt><span class='object_link'><a href="Pgn.html" title="Chess::Pgn (class)">Chess::Pgn</a></span></tt>
|
1102
|
+
|
1103
|
+
|
1104
|
+
|
1105
|
+
|
1106
|
+
|
1107
|
+
</h3><div class="docstring">
|
1108
|
+
<div class="discussion">
|
1109
|
+
|
1110
|
+
<p>Returns the PGN rappresenting the game.</p>
|
1111
|
+
|
1112
|
+
|
1113
|
+
</div>
|
1114
|
+
</div>
|
1115
|
+
<div class="tags">
|
1116
|
+
|
1117
|
+
<p class="tag_title">Returns:</p>
|
1118
|
+
<ul class="return">
|
1119
|
+
|
1120
|
+
<li>
|
1121
|
+
|
1122
|
+
|
1123
|
+
<span class='type'>(<tt><span class='object_link'><a href="Pgn.html" title="Chess::Pgn (class)">Chess::Pgn</a></span></tt>)</span>
|
1124
|
+
|
1125
|
+
|
1126
|
+
|
1127
|
+
</li>
|
1128
|
+
|
1129
|
+
</ul>
|
1130
|
+
|
1131
|
+
</div><table class="source_code">
|
1132
|
+
<tr>
|
1133
|
+
<td>
|
1134
|
+
<pre class="lines">
|
1135
|
+
|
1136
|
+
|
1137
|
+
137
|
1138
|
+
138
|
1139
|
+
139
|
1140
|
+
140
|
1141
|
+
141
|
1142
|
+
142</pre>
|
1143
|
+
</td>
|
1144
|
+
<td>
|
1145
|
+
<pre class="code"><span class="info file"># File 'lib/chess/game.rb', line 137</span>
|
1146
|
+
|
1147
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_pgn'>pgn</span>
|
1148
|
+
<span class='id identifier rubyid_pgn'>pgn</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Chess.html" title="Chess (module)">Chess</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Pgn.html" title="Chess::Pgn (class)">Pgn</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Pgn.html#initialize-instance_method" title="Chess::Pgn#initialize (method)">new</a></span></span>
|
1149
|
+
<span class='id identifier rubyid_pgn'>pgn</span><span class='period'>.</span><span class='id identifier rubyid_moves'>moves</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_moves'>moves</span>
|
1150
|
+
<span class='id identifier rubyid_pgn'>pgn</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span>
|
1151
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_pgn'>pgn</span>
|
1152
|
+
<span class='kw'>end</span></pre>
|
1153
|
+
</td>
|
1154
|
+
</tr>
|
1155
|
+
</table>
|
1156
|
+
</div>
|
1157
|
+
|
1158
|
+
<div class="method_details ">
|
1159
|
+
<h3 class="signature " id="status-instance_method">
|
1160
|
+
|
1161
|
+
#<strong>status</strong> ⇒ <tt>Symbol</tt>
|
1162
|
+
|
1163
|
+
|
1164
|
+
|
1165
|
+
|
1166
|
+
|
1167
|
+
</h3><div class="docstring">
|
1168
|
+
<div class="discussion">
|
1169
|
+
|
1170
|
+
<p>Returns the status of the game. Possible states are:</p>
|
1171
|
+
<ul><li>
|
1172
|
+
<p><code>in_progress</code>: the game is in progress.</p>
|
1173
|
+
</li><li>
|
1174
|
+
<p><code>white_won</code>: white player has won with a checkmate.</p>
|
1175
|
+
</li><li>
|
1176
|
+
<p><code>black_won</code>: black player has won with a checkmate.</p>
|
1177
|
+
</li><li>
|
1178
|
+
<p><code>white_won_resign</code>: white player has won for resign.</p>
|
1179
|
+
</li><li>
|
1180
|
+
<p><code>black_won_resign</code>: black player has won for resign.</p>
|
1181
|
+
</li><li>
|
1182
|
+
<p><code>stalemate</code>: draw for stalemate.</p>
|
1183
|
+
</li><li>
|
1184
|
+
<p><code>insufficient_material</code>: draw for insufficient material to checkmate.</p>
|
1185
|
+
</li><li>
|
1186
|
+
<p><code>fifty_move_rule</code>: draw for fifty-move rule.</p>
|
1187
|
+
</li><li>
|
1188
|
+
<p><code>threefold_repetition</code>: draw for threefold repetition.</p>
|
1189
|
+
</li></ul>
|
1190
|
+
|
1191
|
+
|
1192
|
+
</div>
|
1193
|
+
</div>
|
1194
|
+
<div class="tags">
|
1195
|
+
|
1196
|
+
<p class="tag_title">Returns:</p>
|
1197
|
+
<ul class="return">
|
1198
|
+
|
1199
|
+
<li>
|
1200
|
+
|
1201
|
+
|
1202
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
1203
|
+
|
1204
|
+
|
1205
|
+
|
1206
|
+
</li>
|
1207
|
+
|
1208
|
+
</ul>
|
1209
|
+
|
1210
|
+
</div><table class="source_code">
|
1211
|
+
<tr>
|
1212
|
+
<td>
|
1213
|
+
<pre class="lines">
|
1214
|
+
|
1215
|
+
|
1216
|
+
109
|
1217
|
+
110
|
1218
|
+
111
|
1219
|
+
112
|
1220
|
+
113
|
1221
|
+
114
|
1222
|
+
115
|
1223
|
+
116
|
1224
|
+
117
|
1225
|
+
118
|
1226
|
+
119
|
1227
|
+
120
|
1228
|
+
121
|
1229
|
+
122
|
1230
|
+
123
|
1231
|
+
124
|
1232
|
+
125
|
1233
|
+
126
|
1234
|
+
127
|
1235
|
+
128</pre>
|
1236
|
+
</td>
|
1237
|
+
<td>
|
1238
|
+
<pre class="code"><span class="info file"># File 'lib/chess/game.rb', line 109</span>
|
1239
|
+
|
1240
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_status'>status</span>
|
1241
|
+
<span class='kw'>case</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span>
|
1242
|
+
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>*</span><span class='tstring_end'>'</span></span>
|
1243
|
+
<span class='kw'>return</span> <span class='symbol'>:in_progress</span>
|
1244
|
+
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1-0</span><span class='tstring_end'>'</span></span>
|
1245
|
+
<span class='kw'>return</span> <span class='symbol'>:white_won</span> <span class='kw'>if</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_board'>board</span><span class='period'>.</span><span class='id identifier rubyid_checkmate?'>checkmate?</span>
|
1246
|
+
|
1247
|
+
<span class='kw'>return</span> <span class='symbol'>:white_won_resign</span>
|
1248
|
+
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>0-1</span><span class='tstring_end'>'</span></span>
|
1249
|
+
<span class='kw'>return</span> <span class='symbol'>:black_won</span> <span class='kw'>if</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_board'>board</span><span class='period'>.</span><span class='id identifier rubyid_checkmate?'>checkmate?</span>
|
1250
|
+
|
1251
|
+
<span class='kw'>return</span> <span class='symbol'>:black_won_resign</span>
|
1252
|
+
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1/2-1/2</span><span class='tstring_end'>'</span></span>
|
1253
|
+
<span class='kw'>return</span> <span class='symbol'>:stalemate</span> <span class='kw'>if</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_board'>board</span><span class='period'>.</span><span class='id identifier rubyid_stalemate?'>stalemate?</span>
|
1254
|
+
<span class='kw'>return</span> <span class='symbol'>:insufficient_material</span> <span class='kw'>if</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_board'>board</span><span class='period'>.</span><span class='id identifier rubyid_insufficient_material?'>insufficient_material?</span>
|
1255
|
+
<span class='kw'>return</span> <span class='symbol'>:fifty_move_rule</span> <span class='kw'>if</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_board'>board</span><span class='period'>.</span><span class='id identifier rubyid_fifty_move_rule?'>fifty_move_rule?</span>
|
1256
|
+
|
1257
|
+
<span class='kw'>return</span> <span class='symbol'>:threefold_repetition</span> <span class='kw'>if</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_threefold_repetition?'>threefold_repetition?</span>
|
1258
|
+
<span class='kw'>end</span>
|
1259
|
+
<span class='kw'>end</span></pre>
|
1260
|
+
</td>
|
1261
|
+
</tr>
|
1262
|
+
</table>
|
1263
|
+
</div>
|
1264
|
+
|
1265
|
+
</div>
|
1266
|
+
|
1267
|
+
</div>
|
1268
|
+
|
1269
|
+
<div id="footer">
|
1270
|
+
Generated on Thu Jan 28 17:31:40 2021 by
|
1271
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1272
|
+
0.9.26 (ruby-2.6.1).
|
1273
|
+
</div>
|
1274
|
+
|
1275
|
+
</div>
|
1276
|
+
</body>
|
1277
|
+
</html>
|