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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +12 -0
  3. data/.github/workflows/ruby.yml +58 -0
  4. data/.gitignore +2 -2
  5. data/.rubocop.yml +9 -144
  6. data/Gemfile.lock +70 -0
  7. data/README.md +26 -22
  8. data/Rakefile +1 -0
  9. data/chess.gemspec +8 -5
  10. data/docs/Chess.html +157 -0
  11. data/docs/Chess/BadNotationError.html +237 -0
  12. data/docs/Chess/Board.html +1759 -0
  13. data/docs/Chess/CGame.html +2296 -0
  14. data/docs/Chess/Game.html +1277 -0
  15. data/docs/Chess/Gnuchess.html +366 -0
  16. data/docs/Chess/IllegalMoveError.html +137 -0
  17. data/docs/Chess/InvalidFenFormatError.html +237 -0
  18. data/docs/Chess/InvalidPgnFormatError.html +217 -0
  19. data/docs/Chess/Pgn.html +1477 -0
  20. data/docs/Chess/UTF8Notation.html +270 -0
  21. data/docs/_index.html +217 -0
  22. data/docs/class_list.html +51 -0
  23. data/docs/css/common.css +1 -0
  24. data/docs/css/full_list.css +58 -0
  25. data/docs/css/style.css +497 -0
  26. data/docs/file.README.html +116 -0
  27. data/docs/file_list.html +56 -0
  28. data/docs/frames.html +17 -0
  29. data/docs/index.html +116 -0
  30. data/docs/js/app.js +314 -0
  31. data/docs/js/full_list.js +216 -0
  32. data/docs/js/jquery.js +4 -0
  33. data/docs/method_list.html +531 -0
  34. data/docs/top-level-namespace.html +110 -0
  35. data/ext/chess.c +1 -1
  36. data/ext/common.h +7 -3
  37. data/ext/extconf.rb +1 -1
  38. data/lib/chess/game.rb +53 -67
  39. data/lib/chess/gnuchess.rb +49 -53
  40. data/lib/chess/pgn.rb +10 -12
  41. data/lib/chess/utf8_notation.rb +3 -0
  42. data/lib/chess/version.rb +1 -1
  43. data/test/test_big_pgn_collection.rb +1 -1
  44. data/test/test_checkmate.rb +4 -4
  45. data/test/test_errors.rb +22 -0
  46. data/test/test_fifty_rule_move.rb +2 -2
  47. data/test/test_game.rb +82 -0
  48. data/test/test_helper.rb +15 -0
  49. data/test/test_insufficient_material.rb +4 -4
  50. data/test/test_move_generator.rb +3 -2
  51. data/test/test_pgn.rb +35 -0
  52. data/test/test_pgn_collection.rb +2 -2
  53. data/test/test_stalemate.rb +1 -1
  54. data/test/test_threefold_repetition.rb +1 -1
  55. metadata +112 -10
@@ -0,0 +1,2296 @@
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::CGame
8
+
9
+ &mdash; 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::CGame";
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 (C)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../Chess.html" title="Chess (module)">Chess</a></span></span>
41
+ &raquo;
42
+ <span class="title">CGame</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::CGame
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+ <dl>
70
+ <dt>Inherits:</dt>
71
+ <dd>
72
+ <span class="inheritName">Object</span>
73
+
74
+ <ul class="fullTree">
75
+ <li>Object</li>
76
+
77
+ <li class="next">Chess::CGame</li>
78
+
79
+ </ul>
80
+ <a href="#" class="inheritanceTree">show all</a>
81
+
82
+ </dd>
83
+ </dl>
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+ <dl>
96
+ <dt>Defined in:</dt>
97
+ <dd>ext/chess.c<span class="defines">,<br />
98
+ ext/chess.c</span>
99
+ </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 collection of boards of a single chess game.</p>
108
+
109
+
110
+ </div>
111
+ </div>
112
+ <div class="tags">
113
+
114
+
115
+ </div><div id="subclasses">
116
+ <h2>Direct Known Subclasses</h2>
117
+ <p class="children"><span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span></p>
118
+ </div>
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+ <h2>
128
+ Instance Method Summary
129
+ <small><a href="#" class="summary_toggle">collapse</a></small>
130
+ </h2>
131
+
132
+ <ul class="summary">
133
+
134
+ <li class="public ">
135
+ <span class="summary_signature">
136
+
137
+ <a href="#[]-instance_method" title="#[] (instance method)">#<strong>[]</strong>(n) &#x21d2; Board </a>
138
+
139
+
140
+
141
+ </span>
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+ <span class="summary_desc"><div class='inline'>
152
+ <p>Returns the <code>n</code>-th <span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span> of the <span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span> or <code>nil</code> if the <code>n</code>-th <span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span> does not exist.</p>
153
+ </div></span>
154
+
155
+ </li>
156
+
157
+
158
+ <li class="public ">
159
+ <span class="summary_signature">
160
+
161
+ <a href="#coord_moves-instance_method" title="#coord_moves (instance method)">#<strong>coord_moves</strong> &#x21d2; Array&lt;String&gt; </a>
162
+
163
+
164
+
165
+ </span>
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+ <span class="summary_desc"><div class='inline'>
176
+ <p>Returns the array with all moves done in coordinate chess notation <em>(es: b1c3)</em>.</p>
177
+ </div></span>
178
+
179
+ </li>
180
+
181
+
182
+ <li class="public ">
183
+ <span class="summary_signature">
184
+
185
+ <a href="#current-instance_method" title="#current (instance method)">#<strong>current</strong> &#x21d2; Board </a>
186
+
187
+
188
+
189
+ (also: #board)
190
+
191
+ </span>
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+ <span class="summary_desc"><div class='inline'>
202
+ <p>Returns the current <span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span> of the <span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span> (the current chess position of the game).</p>
203
+ </div></span>
204
+
205
+ </li>
206
+
207
+
208
+ <li class="public ">
209
+ <span class="summary_signature">
210
+
211
+ <a href="#draw-instance_method" title="#draw (instance method)">#<strong>draw</strong> &#x21d2; nil </a>
212
+
213
+
214
+
215
+ </span>
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+ <span class="summary_desc"><div class='inline'>
226
+ <p>The game result is set to draw.</p>
227
+ </div></span>
228
+
229
+ </li>
230
+
231
+
232
+ <li class="public ">
233
+ <span class="summary_signature">
234
+
235
+ <a href="#each-instance_method" title="#each (instance method)">#<strong>each</strong> {|board, move, coord_move, index| ... } &#x21d2; Game, Array&lt;String&gt; </a>
236
+
237
+
238
+
239
+ </span>
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+ <span class="summary_desc"><div class='inline'>
250
+ <p>Cycle the <span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span>.</p>
251
+ </div></span>
252
+
253
+ </li>
254
+
255
+
256
+ <li class="public ">
257
+ <span class="summary_signature">
258
+
259
+ <a href="#full_moves-instance_method" title="#full_moves (instance method)">#<strong>full_moves</strong> &#x21d2; Object </a>
260
+
261
+
262
+
263
+ </span>
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+ <span class="summary_desc"><div class='inline'></div></span>
274
+
275
+ </li>
276
+
277
+
278
+ <li class="public ">
279
+ <span class="summary_signature">
280
+
281
+ <a href="#move-instance_method" title="#move (instance method)">#<strong>move</strong>(piece, disambiguating, to_coord, promote_in) &#x21d2; String </a>
282
+
283
+
284
+
285
+ </span>
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+ <span class="summary_desc"><div class='inline'>
296
+ <p>Make a move.</p>
297
+ </div></span>
298
+
299
+ </li>
300
+
301
+
302
+ <li class="public ">
303
+ <span class="summary_signature">
304
+
305
+ <a href="#move2-instance_method" title="#move2 (instance method)">#<strong>move2</strong>(from, to, promote_in) &#x21d2; String </a>
306
+
307
+
308
+
309
+ </span>
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+ <span class="summary_desc"><div class='inline'>
320
+ <p>Make a move.</p>
321
+ </div></span>
322
+
323
+ </li>
324
+
325
+
326
+ <li class="public ">
327
+ <span class="summary_signature">
328
+
329
+ <a href="#move3-instance_method" title="#move3 (instance method)">#<strong>move3</strong>(from, to, promote_in) &#x21d2; String </a>
330
+
331
+
332
+
333
+ </span>
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+ <span class="summary_desc"><div class='inline'>
344
+ <p>Make a move.</p>
345
+ </div></span>
346
+
347
+ </li>
348
+
349
+
350
+ <li class="public ">
351
+ <span class="summary_signature">
352
+
353
+ <a href="#moves-instance_method" title="#moves (instance method)">#<strong>moves</strong> &#x21d2; Array&lt;String&gt; </a>
354
+
355
+
356
+
357
+ </span>
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+ <span class="summary_desc"><div class='inline'>
368
+ <p>Returns the array with all moves done <em>(es: Nc3)</em>.</p>
369
+ </div></span>
370
+
371
+ </li>
372
+
373
+
374
+ <li class="public ">
375
+ <span class="summary_signature">
376
+
377
+ <a href="#resign-instance_method" title="#resign (instance method)">#<strong>resign</strong>(color) &#x21d2; nil </a>
378
+
379
+
380
+
381
+ </span>
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+ <span class="summary_desc"><div class='inline'>
392
+ <p>The game result is set to &#39;1-0&#39; if <code>color</code> is <em>black</em>, otherwise is set to &#39;0-1&#39; if color is <em>white</em>.</p>
393
+ </div></span>
394
+
395
+ </li>
396
+
397
+
398
+ <li class="public ">
399
+ <span class="summary_signature">
400
+
401
+ <a href="#result-instance_method" title="#result (instance method)">#<strong>result</strong> &#x21d2; String </a>
402
+
403
+
404
+
405
+ </span>
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+
414
+
415
+ <span class="summary_desc"><div class='inline'>
416
+ <p>Returns the result of the game.</p>
417
+ </div></span>
418
+
419
+ </li>
420
+
421
+
422
+ <li class="public ">
423
+ <span class="summary_signature">
424
+
425
+ <a href="#rollback!-instance_method" title="#rollback! (instance method)">#<strong>rollback!</strong> &#x21d2; Game </a>
426
+
427
+
428
+
429
+ </span>
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+ <span class="summary_desc"><div class='inline'>
440
+ <p>Rollback last move.</p>
441
+ </div></span>
442
+
443
+ </li>
444
+
445
+
446
+ <li class="public ">
447
+ <span class="summary_signature">
448
+
449
+ <a href="#set_fen!-instance_method" title="#set_fen! (instance method)">#<strong>set_fen!</strong>(fen) &#x21d2; Game </a>
450
+
451
+
452
+
453
+ </span>
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+ <span class="summary_desc"><div class='inline'>
464
+ <p>Set the game position by FEN string.</p>
465
+ </div></span>
466
+
467
+ </li>
468
+
469
+
470
+ <li class="public ">
471
+ <span class="summary_signature">
472
+
473
+ <a href="#size-instance_method" title="#size (instance method)">#<strong>size</strong> &#x21d2; Integer </a>
474
+
475
+
476
+
477
+ </span>
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+ <span class="summary_desc"><div class='inline'>
488
+ <p>Returns the number of moves done.</p>
489
+ </div></span>
490
+
491
+ </li>
492
+
493
+
494
+ <li class="public ">
495
+ <span class="summary_signature">
496
+
497
+ <a href="#threefold_repetition%3F-instance_method" title="#threefold_repetition? (instance method)">#<strong>threefold_repetition?</strong> &#x21d2; Boolean </a>
498
+
499
+
500
+
501
+ </span>
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+ <span class="summary_desc"><div class='inline'>
512
+ <p>Returns <code>true</code> if a player can claim draw by the threefold repetition rule, <code>false</code> otherwise.</p>
513
+ </div></span>
514
+
515
+ </li>
516
+
517
+
518
+ <li class="public ">
519
+ <span class="summary_signature">
520
+
521
+ <a href="#to_s-instance_method" title="#to_s (instance method)">#<strong>to_s</strong> &#x21d2; String </a>
522
+
523
+
524
+
525
+ </span>
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+ <span class="summary_desc"><div class='inline'>
536
+ <p>Current <span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span> to string.</p>
537
+ </div></span>
538
+
539
+ </li>
540
+
541
+
542
+ </ul>
543
+
544
+
545
+
546
+
547
+ <div id="instance_method_details" class="method_details_list">
548
+ <h2>Instance Method Details</h2>
549
+
550
+
551
+ <div class="method_details first">
552
+ <h3 class="signature first" id="[]-instance_method">
553
+
554
+ #<strong>[]</strong>(n) &#x21d2; <tt><span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span></tt>
555
+
556
+
557
+
558
+
559
+
560
+ </h3><div class="docstring">
561
+ <div class="discussion">
562
+
563
+
564
+ </div>
565
+ </div>
566
+ <div class="tags">
567
+
568
+ <div class="docstring">
569
+ <div class="discussion">
570
+
571
+ <p>Returns the <code>n</code>-th <span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span> of the <span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span> or <code>nil</code> if the <code>n</code>-th <span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span> does not exist.</p>
572
+
573
+
574
+ </div>
575
+ </div>
576
+ <div class="tags">
577
+
578
+ <p class="tag_title">Returns:</p>
579
+ <ul class="return">
580
+
581
+ <li>
582
+
583
+
584
+ <span class='type'>(<tt><span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span></tt>)</span>
585
+
586
+
587
+
588
+ </li>
589
+
590
+ </ul>
591
+
592
+ </div>
593
+
594
+
595
+ </div><table class="source_code">
596
+ <tr>
597
+ <td>
598
+ <pre class="lines">
599
+
600
+
601
+ 210
602
+ 211
603
+ 212
604
+ 213
605
+ 214
606
+ 215
607
+ 216
608
+ 217
609
+ 218
610
+ 219
611
+ 220</pre>
612
+ </td>
613
+ <td>
614
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 210</span>
615
+
616
+ VALUE
617
+ game_boards (VALUE self, VALUE index)
618
+ {
619
+ Game *g;
620
+ Data_Get_Struct (self, Game, g);
621
+ int n = FIX2INT (index);
622
+ Board *board = get_board (g, n);
623
+ if (board)
624
+ return Data_Wrap_Struct (board_klass, 0, 0, board);
625
+ return Qnil;
626
+ }</pre>
627
+ </td>
628
+ </tr>
629
+ </table>
630
+ </div>
631
+
632
+ <div class="method_details ">
633
+ <h3 class="signature " id="coord_moves-instance_method">
634
+
635
+ #<strong>coord_moves</strong> &#x21d2; <tt>Array&lt;String&gt;</tt>
636
+
637
+
638
+
639
+
640
+
641
+ </h3><div class="docstring">
642
+ <div class="discussion">
643
+
644
+
645
+ </div>
646
+ </div>
647
+ <div class="tags">
648
+
649
+ <div class="docstring">
650
+ <div class="discussion">
651
+
652
+ <p>Returns the array with all moves done in coordinate chess notation <em>(es: b1c3)</em>.</p>
653
+
654
+
655
+ </div>
656
+ </div>
657
+ <div class="tags">
658
+
659
+ <p class="tag_title">Returns:</p>
660
+ <ul class="return">
661
+
662
+ <li>
663
+
664
+
665
+ <span class='type'>(<tt>Array&lt;String&gt;</tt>)</span>
666
+
667
+
668
+
669
+ </li>
670
+
671
+ </ul>
672
+
673
+ </div>
674
+
675
+
676
+ </div><table class="source_code">
677
+ <tr>
678
+ <td>
679
+ <pre class="lines">
680
+
681
+
682
+ 258
683
+ 259
684
+ 260
685
+ 261
686
+ 262
687
+ 263
688
+ 264
689
+ 265
690
+ 266
691
+ 267</pre>
692
+ </td>
693
+ <td>
694
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 258</span>
695
+
696
+ VALUE
697
+ game_coord_moves (VALUE self)
698
+ {
699
+ Game *g;
700
+ Data_Get_Struct (self, Game, g);
701
+ VALUE moves = rb_ary_new ();
702
+ for (int i = 0; i &lt; g-&gt;current; i++)
703
+ rb_ary_push (moves, rb_str_new2 (g-&gt;coord_moves[i]));
704
+ return moves;
705
+ }</pre>
706
+ </td>
707
+ </tr>
708
+ </table>
709
+ </div>
710
+
711
+ <div class="method_details ">
712
+ <h3 class="signature " id="current-instance_method">
713
+
714
+ #<strong>current</strong> &#x21d2; <tt><span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span></tt>
715
+
716
+
717
+
718
+ <span class="aliases">Also known as:
719
+ <span class="names"><span id='board-instance_method'>board</span></span>
720
+ </span>
721
+
722
+
723
+
724
+ </h3><div class="docstring">
725
+ <div class="discussion">
726
+
727
+
728
+ </div>
729
+ </div>
730
+ <div class="tags">
731
+
732
+ <div class="docstring">
733
+ <div class="discussion">
734
+
735
+ <p>Returns the current <span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span> of the <span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span> (the current chess position of the game).</p>
736
+
737
+
738
+ </div>
739
+ </div>
740
+ <div class="tags">
741
+
742
+ <p class="tag_title">Returns:</p>
743
+ <ul class="return">
744
+
745
+ <li>
746
+
747
+
748
+ <span class='type'>(<tt><span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span></tt>)</span>
749
+
750
+
751
+
752
+ </li>
753
+
754
+ </ul>
755
+
756
+ </div>
757
+
758
+
759
+ </div><table class="source_code">
760
+ <tr>
761
+ <td>
762
+ <pre class="lines">
763
+
764
+
765
+ 228
766
+ 229
767
+ 230
768
+ 231
769
+ 232
770
+ 233
771
+ 234</pre>
772
+ </td>
773
+ <td>
774
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 228</span>
775
+
776
+ VALUE
777
+ game_current_board (VALUE self)
778
+ {
779
+ Game *g;
780
+ Data_Get_Struct (self, Game, g);
781
+ return game_boards (self, INT2FIX (g-&gt;current-1));
782
+ }</pre>
783
+ </td>
784
+ </tr>
785
+ </table>
786
+ </div>
787
+
788
+ <div class="method_details ">
789
+ <h3 class="signature " id="draw-instance_method">
790
+
791
+ #<strong>draw</strong> &#x21d2; <tt>nil</tt>
792
+
793
+
794
+
795
+
796
+
797
+ </h3><div class="docstring">
798
+ <div class="discussion">
799
+
800
+
801
+ </div>
802
+ </div>
803
+ <div class="tags">
804
+
805
+ <div class="docstring">
806
+ <div class="discussion">
807
+
808
+ <p>The game result is set to draw.</p>
809
+
810
+
811
+ </div>
812
+ </div>
813
+ <div class="tags">
814
+
815
+ <p class="tag_title">Returns:</p>
816
+ <ul class="return">
817
+
818
+ <li>
819
+
820
+
821
+ <span class='type'>(<tt>nil</tt>)</span>
822
+
823
+
824
+
825
+ </li>
826
+
827
+ </ul>
828
+
829
+ </div>
830
+
831
+
832
+ </div><table class="source_code">
833
+ <tr>
834
+ <td>
835
+ <pre class="lines">
836
+
837
+
838
+ 195
839
+ 196
840
+ 197
841
+ 198
842
+ 199
843
+ 200
844
+ 201
845
+ 202</pre>
846
+ </td>
847
+ <td>
848
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 195</span>
849
+
850
+ VALUE
851
+ game_draw (VALUE self)
852
+ {
853
+ Game *g;
854
+ Data_Get_Struct (self, Game, g);
855
+ g-&gt;result = DRAW;
856
+ return Qnil;
857
+ }</pre>
858
+ </td>
859
+ </tr>
860
+ </table>
861
+ </div>
862
+
863
+ <div class="method_details ">
864
+ <h3 class="signature " id="each-instance_method">
865
+
866
+ #<strong>each</strong> {|board, move, coord_move, index| ... } &#x21d2; <tt><span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span></tt>, <tt>Array&lt;String&gt;</tt>
867
+
868
+
869
+
870
+
871
+
872
+ </h3><div class="docstring">
873
+ <div class="discussion">
874
+
875
+
876
+ </div>
877
+ </div>
878
+ <div class="tags">
879
+
880
+ <div class="docstring">
881
+ <div class="discussion">
882
+
883
+ <p>Cycle the <span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span>.</p>
884
+
885
+
886
+ </div>
887
+ </div>
888
+ <div class="tags">
889
+
890
+ <p class="tag_title">Yields:</p>
891
+ <ul class="yield">
892
+
893
+ <li>
894
+
895
+
896
+ <span class='type'>(<tt><span class='object_link'><a href="#board-instance_method" title="Chess::CGame#board (method)">board</a></span></tt>, <tt><span class='object_link'><a href="#move-instance_method" title="Chess::CGame#move (method)">move</a></span></tt>, <tt>coord_move</tt>, <tt>index</tt>)</span>
897
+
898
+
899
+
900
+ &mdash;
901
+ <div class='inline'>
902
+ <p>Calls <code>block</code> once for each <span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span> in <code>self</code>, passing that <code>board</code>, <code>move</code>, <code>coord_move</code> and <code>index</code> as parameters.</p>
903
+ </div>
904
+
905
+ </li>
906
+
907
+ </ul>
908
+ <p class="tag_title">Returns:</p>
909
+ <ul class="return">
910
+
911
+ <li>
912
+
913
+
914
+ <span class='type'>(<tt><span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span></tt>)</span>
915
+
916
+
917
+
918
+ &mdash;
919
+ <div class='inline'>
920
+ <p>Returns <code>self</code> if a block is given.</p>
921
+ </div>
922
+
923
+ </li>
924
+
925
+ <li>
926
+
927
+
928
+ <span class='type'>(<tt>Array&lt;String&gt;</tt>)</span>
929
+
930
+
931
+
932
+ &mdash;
933
+ <div class='inline'>
934
+ <p>Returns the array of game moves if no block is given.</p>
935
+ </div>
936
+
937
+ </li>
938
+
939
+ </ul>
940
+
941
+ </div>
942
+
943
+
944
+ </div><table class="source_code">
945
+ <tr>
946
+ <td>
947
+ <pre class="lines">
948
+
949
+
950
+ 339
951
+ 340
952
+ 341
953
+ 342
954
+ 343
955
+ 344
956
+ 345
957
+ 346
958
+ 347
959
+ 348
960
+ 349
961
+ 350
962
+ 351
963
+ 352
964
+ 353</pre>
965
+ </td>
966
+ <td>
967
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 339</span>
968
+
969
+ VALUE
970
+ game_each (VALUE self)
971
+ {
972
+ if (!rb_block_given_p ())
973
+ return game_moves(self);
974
+ Game *g;
975
+ Data_Get_Struct (self, Game, g);
976
+ for (int i = 0; i &lt; g-&gt;current; i++)
977
+ rb_yield_values (4,
978
+ Data_Wrap_Struct (board_klass, 0, 0, get_board (g, i)),
979
+ rb_str_new2 (g-&gt;moves[i]),
980
+ rb_str_new2 (g-&gt;coord_moves[i]),
981
+ INT2FIX (i));
982
+ return self;
983
+ }</pre>
984
+ </td>
985
+ </tr>
986
+ </table>
987
+ </div>
988
+
989
+ <div class="method_details ">
990
+ <h3 class="signature " id="full_moves-instance_method">
991
+
992
+ #<strong>full_moves</strong> &#x21d2; <tt>Object</tt>
993
+
994
+
995
+
996
+
997
+
998
+ </h3><div class="docstring">
999
+ <div class="discussion">
1000
+
1001
+
1002
+ </div>
1003
+ </div>
1004
+ <div class="tags">
1005
+
1006
+ <div class="docstring">
1007
+ <div class="discussion">
1008
+ <div class="note deprecated"><strong>Deprecated.</strong> <div class='inline'>
1009
+ <p>Use <span class='object_link'><a href="#coord_moves-instance_method" title="Chess::CGame#coord_moves (method)">#coord_moves</a></span> instead.</p>
1010
+ </div></div>
1011
+
1012
+
1013
+ </div>
1014
+ </div>
1015
+ <div class="tags">
1016
+
1017
+
1018
+ </div>
1019
+
1020
+
1021
+ </div><table class="source_code">
1022
+ <tr>
1023
+ <td>
1024
+ <pre class="lines">
1025
+
1026
+
1027
+ 273
1028
+ 274
1029
+ 275
1030
+ 276
1031
+ 277
1032
+ 278</pre>
1033
+ </td>
1034
+ <td>
1035
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 273</span>
1036
+
1037
+ VALUE
1038
+ game_full_moves (VALUE self)
1039
+ {
1040
+ printf (&quot;DEPRECATION WARNING: `full_moves` is deprecated and will be removed, please use `coord_moves` to get the array with all moves done in coordinate chess notation.\n&quot;);
1041
+ return game_coord_moves (self);
1042
+ }</pre>
1043
+ </td>
1044
+ </tr>
1045
+ </table>
1046
+ </div>
1047
+
1048
+ <div class="method_details ">
1049
+ <h3 class="signature " id="move-instance_method">
1050
+
1051
+ #<strong>move</strong>(piece, disambiguating, to_coord, promote_in) &#x21d2; <tt>String</tt>
1052
+
1053
+
1054
+
1055
+
1056
+
1057
+ </h3><div class="docstring">
1058
+ <div class="discussion">
1059
+
1060
+
1061
+ </div>
1062
+ </div>
1063
+ <div class="tags">
1064
+
1065
+ <div class="docstring">
1066
+ <div class="discussion">
1067
+
1068
+ <div class="note notetag">
1069
+ <strong>Note:</strong>
1070
+ <div class='inline'>
1071
+ <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="Game.html" title="Chess::Game (class)">Game</a></span>.</p>
1072
+ </div>
1073
+ </div>
1074
+
1075
+
1076
+ <p>Make a move.</p>
1077
+
1078
+
1079
+ </div>
1080
+ </div>
1081
+ <div class="tags">
1082
+ <p class="tag_title">Parameters:</p>
1083
+ <ul class="param">
1084
+
1085
+ <li>
1086
+
1087
+ <span class='name'>piece</span>
1088
+
1089
+
1090
+ <span class='type'>(<tt>String</tt>)</span>
1091
+
1092
+
1093
+
1094
+ &mdash;
1095
+ <div class='inline'>
1096
+ <p>The character of the moving piece <em>(&#39;P&#39;, &#39;R&#39;, &#39;N&#39;, &#39;B&#39;, &#39;Q&#39;, &#39;K&#39;)</em>.</p>
1097
+ </div>
1098
+
1099
+ </li>
1100
+
1101
+ <li>
1102
+
1103
+ <span class='name'>disambiguating</span>
1104
+
1105
+
1106
+ <span class='type'>(<tt>String</tt>)</span>
1107
+
1108
+
1109
+
1110
+ &mdash;
1111
+ <div class='inline'>
1112
+ <p>When two (or more) identical pieces can move to the same square, the moving piece is uniquely identified by specifying the piece&#39;s letter, followed by (in descending order of preference):</p>
1113
+ <ul><li>
1114
+ <p>the file of departure (if they differ);</p>
1115
+ </li><li>
1116
+ <p>the rank of departure (if the files are the same but the ranks differ);</p>
1117
+ </li><li>
1118
+ <p>both the rank and file (if neither alone is sufficient to identify the piece—which occurs only in rare cases where one or more pawns have promoted, resulting in a player having three or more identical pieces able to reach the same square). Keep <code>nil</code> if no needed.</p>
1119
+ </li></ul>
1120
+ </div>
1121
+
1122
+ </li>
1123
+
1124
+ <li>
1125
+
1126
+ <span class='name'>to_coord</span>
1127
+
1128
+
1129
+ <span class='type'>(<tt>String</tt>)</span>
1130
+
1131
+
1132
+
1133
+ &mdash;
1134
+ <div class='inline'>
1135
+ <p>The square where the moving piece will <em>(&#39;a1&#39;, &#39;a2&#39;, … , &#39;h7&#39;, &#39;h8&#39;)</em>.</p>
1136
+ </div>
1137
+
1138
+ </li>
1139
+
1140
+ <li>
1141
+
1142
+ <span class='name'>promote_in</span>
1143
+
1144
+
1145
+ <span class='type'>(<tt>String</tt>)</span>
1146
+
1147
+
1148
+
1149
+ &mdash;
1150
+ <div class='inline'>
1151
+ <p>The character of promotion piece <em>(&#39;R&#39;, &#39;N&#39;, &#39;B&#39;, &#39;Q&#39;)</em>. If not <code>nil</code> and no promotion occured raise an <span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span>. If <code>nil</code>, <em>&#39;Q&#39;</em> is the default.</p>
1152
+ </div>
1153
+
1154
+ </li>
1155
+
1156
+ </ul>
1157
+
1158
+ <p class="tag_title">Returns:</p>
1159
+ <ul class="return">
1160
+
1161
+ <li>
1162
+
1163
+
1164
+ <span class='type'>(<tt>String</tt>)</span>
1165
+
1166
+
1167
+
1168
+ &mdash;
1169
+ <div class='inline'>
1170
+ <p>Returns a string that represents the short algebraic chess notation of the move.</p>
1171
+ </div>
1172
+
1173
+ </li>
1174
+
1175
+ </ul>
1176
+ <p class="tag_title">Raises:</p>
1177
+ <ul class="raise">
1178
+
1179
+ <li>
1180
+
1181
+
1182
+ <span class='type'>(<tt><span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span></tt>)</span>
1183
+
1184
+
1185
+
1186
+ </li>
1187
+
1188
+ </ul>
1189
+
1190
+ </div>
1191
+
1192
+
1193
+ </div><table class="source_code">
1194
+ <tr>
1195
+ <td>
1196
+ <pre class="lines">
1197
+
1198
+
1199
+ 71
1200
+ 72
1201
+ 73
1202
+ 74
1203
+ 75
1204
+ 76
1205
+ 77
1206
+ 78
1207
+ 79
1208
+ 80
1209
+ 81
1210
+ 82
1211
+ 83
1212
+ 84
1213
+ 85
1214
+ 86
1215
+ 87
1216
+ 88
1217
+ 89</pre>
1218
+ </td>
1219
+ <td>
1220
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 71</span>
1221
+
1222
+ VALUE
1223
+ game_move (VALUE self, VALUE rb_piece, VALUE rb_disambiguating, VALUE rb_to_coord, VALUE rb_promote_in)
1224
+ {
1225
+ Game *g;
1226
+ Data_Get_Struct (self, Game, g);
1227
+ Board *board = current_board (g);
1228
+ char piece = StringValuePtr (rb_piece)[0];
1229
+ char *disambiguating = rb_disambiguating == Qnil ? NULL : StringValuePtr (rb_disambiguating);
1230
+ char *to_coord = StringValuePtr (rb_to_coord);
1231
+ char promote_in = rb_promote_in == Qnil ? &#39;\0&#39; : StringValuePtr (rb_promote_in)[0];
1232
+ int from, to;
1233
+ if (
1234
+ get_coord (board, piece, disambiguating, to_coord, promote_in, &amp;from, &amp;to) &amp;&amp;
1235
+ apply_move (g, from, to, promote_in)
1236
+ )
1237
+ return rb_str_new2 (current_move (g));
1238
+ else
1239
+ rb_raise (illegal_move_error, &quot;Illegal move&quot;);
1240
+ }</pre>
1241
+ </td>
1242
+ </tr>
1243
+ </table>
1244
+ </div>
1245
+
1246
+ <div class="method_details ">
1247
+ <h3 class="signature " id="move2-instance_method">
1248
+
1249
+ #<strong>move2</strong>(from, to, promote_in) &#x21d2; <tt>String</tt>
1250
+
1251
+
1252
+
1253
+
1254
+
1255
+ </h3><div class="docstring">
1256
+ <div class="discussion">
1257
+
1258
+
1259
+ </div>
1260
+ </div>
1261
+ <div class="tags">
1262
+
1263
+ <div class="docstring">
1264
+ <div class="discussion">
1265
+
1266
+ <div class="note notetag">
1267
+ <strong>Note:</strong>
1268
+ <div class='inline'>
1269
+ <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="Game.html" title="Chess::Game (class)">Game</a></span>.</p>
1270
+ </div>
1271
+ </div>
1272
+
1273
+
1274
+ <p>Make a move.</p>
1275
+
1276
+
1277
+ </div>
1278
+ </div>
1279
+ <div class="tags">
1280
+ <p class="tag_title">Parameters:</p>
1281
+ <ul class="param">
1282
+
1283
+ <li>
1284
+
1285
+ <span class='name'>from</span>
1286
+
1287
+
1288
+ <span class='type'>(<tt>String</tt>)</span>
1289
+
1290
+
1291
+
1292
+ &mdash;
1293
+ <div class='inline'>
1294
+ <p>The 2 character string representing the starting square of the moving piece <em>(&#39;a1&#39;, &#39;a2&#39;, … , &#39;h7&#39;, &#39;h8&#39;)</em>.</p>
1295
+ </div>
1296
+
1297
+ </li>
1298
+
1299
+ <li>
1300
+
1301
+ <span class='name'>to</span>
1302
+
1303
+
1304
+ <span class='type'>(<tt>String</tt>)</span>
1305
+
1306
+
1307
+
1308
+ &mdash;
1309
+ <div class='inline'>
1310
+ <p>The 2 character string representing the ending square of the moving piece <em>(&#39;a1&#39;, &#39;a2&#39;, … , &#39;h7&#39;, &#39;h8&#39;)</em>.</p>
1311
+ </div>
1312
+
1313
+ </li>
1314
+
1315
+ <li>
1316
+
1317
+ <span class='name'>promote_in</span>
1318
+
1319
+
1320
+ <span class='type'>(<tt>String</tt>)</span>
1321
+
1322
+
1323
+
1324
+ &mdash;
1325
+ <div class='inline'>
1326
+ <p>The character of promotion piece <em>(&#39;R&#39;, &#39;N&#39;, &#39;B&#39;, &#39;Q&#39;)</em>. If not <code>nil</code> and no promotion occured raise an <span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span>. If <code>nil</code>, <em>&#39;Q&#39;</em> is the default.</p>
1327
+ </div>
1328
+
1329
+ </li>
1330
+
1331
+ </ul>
1332
+
1333
+ <p class="tag_title">Returns:</p>
1334
+ <ul class="return">
1335
+
1336
+ <li>
1337
+
1338
+
1339
+ <span class='type'>(<tt>String</tt>)</span>
1340
+
1341
+
1342
+
1343
+ &mdash;
1344
+ <div class='inline'>
1345
+ <p>Returns a string that represents the short algebraic chess notation of the move.</p>
1346
+ </div>
1347
+
1348
+ </li>
1349
+
1350
+ </ul>
1351
+ <p class="tag_title">Raises:</p>
1352
+ <ul class="raise">
1353
+
1354
+ <li>
1355
+
1356
+
1357
+ <span class='type'>(<tt><span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span></tt>)</span>
1358
+
1359
+
1360
+
1361
+ </li>
1362
+
1363
+ </ul>
1364
+
1365
+ </div>
1366
+
1367
+
1368
+ </div><table class="source_code">
1369
+ <tr>
1370
+ <td>
1371
+ <pre class="lines">
1372
+
1373
+
1374
+ 106
1375
+ 107
1376
+ 108
1377
+ 109
1378
+ 110
1379
+ 111
1380
+ 112
1381
+ 113
1382
+ 114
1383
+ 115
1384
+ 116
1385
+ 117
1386
+ 118
1387
+ 119</pre>
1388
+ </td>
1389
+ <td>
1390
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 106</span>
1391
+
1392
+ VALUE
1393
+ game_move2 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
1394
+ {
1395
+ Game *g;
1396
+ Data_Get_Struct (self, Game, g);
1397
+ Board *board = current_board (g);
1398
+ int from = coord_to_square (StringValuePtr (rb_from));
1399
+ int to = coord_to_square (StringValuePtr (rb_to));
1400
+ char promote_in = rb_promote_in == Qnil ? &#39;\0&#39; : StringValuePtr (rb_promote_in)[0];
1401
+ if (pseudo_legal_move (board, from, to) &amp;&amp; apply_move (g, from, to, promote_in))
1402
+ return rb_str_new2 (current_move (g));
1403
+ else
1404
+ rb_raise (illegal_move_error, &quot;Illegal move&quot;);
1405
+ }</pre>
1406
+ </td>
1407
+ </tr>
1408
+ </table>
1409
+ </div>
1410
+
1411
+ <div class="method_details ">
1412
+ <h3 class="signature " id="move3-instance_method">
1413
+
1414
+ #<strong>move3</strong>(from, to, promote_in) &#x21d2; <tt>String</tt>
1415
+
1416
+
1417
+
1418
+
1419
+
1420
+ </h3><div class="docstring">
1421
+ <div class="discussion">
1422
+
1423
+
1424
+ </div>
1425
+ </div>
1426
+ <div class="tags">
1427
+
1428
+ <div class="docstring">
1429
+ <div class="discussion">
1430
+
1431
+ <div class="note notetag">
1432
+ <strong>Note:</strong>
1433
+ <div class='inline'>
1434
+ <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="Game.html" title="Chess::Game (class)">Game</a></span>.</p>
1435
+ </div>
1436
+ </div>
1437
+
1438
+
1439
+ <p>Make a move. Each square on the chessboard is represented by an integer according to the following scheme:</p>
1440
+
1441
+ <pre class="code"><code class="">8 | 56 57 58 59 60 61 62 63
1442
+ 7 | 48 49 50 51 52 53 54 55
1443
+ 6 | 40 41 42 43 44 45 46 47
1444
+ 5 | 32 33 34 35 36 37 38 39
1445
+ 4 | 24 25 26 27 28 29 30 31
1446
+ 3 | 16 17 18 19 20 21 22 23
1447
+ 2 | 8 9 10 11 12 13 14 15
1448
+ 1 | 0 1 2 3 4 5 6 7
1449
+ +-------------------------
1450
+ a b c d e f g h
1451
+ </code></pre>
1452
+
1453
+
1454
+ </div>
1455
+ </div>
1456
+ <div class="tags">
1457
+ <p class="tag_title">Parameters:</p>
1458
+ <ul class="param">
1459
+
1460
+ <li>
1461
+
1462
+ <span class='name'>from</span>
1463
+
1464
+
1465
+ <span class='type'>(<tt>Integer</tt>)</span>
1466
+
1467
+
1468
+
1469
+ &mdash;
1470
+ <div class='inline'>
1471
+ <p>The integer representing the starting square of the moving piece.</p>
1472
+ </div>
1473
+
1474
+ </li>
1475
+
1476
+ <li>
1477
+
1478
+ <span class='name'>to</span>
1479
+
1480
+
1481
+ <span class='type'>(<tt>Integer</tt>)</span>
1482
+
1483
+
1484
+
1485
+ &mdash;
1486
+ <div class='inline'>
1487
+ <p>The integer representing the ending square of the moving piece.</p>
1488
+ </div>
1489
+
1490
+ </li>
1491
+
1492
+ <li>
1493
+
1494
+ <span class='name'>promote_in</span>
1495
+
1496
+
1497
+ <span class='type'>(<tt>String</tt>)</span>
1498
+
1499
+
1500
+
1501
+ &mdash;
1502
+ <div class='inline'>
1503
+ <p>The character of promotion piece <em>(&#39;R&#39;, &#39;N&#39;, &#39;B&#39;, &#39;Q&#39;)</em>. If not <code>nil</code> and no promotion occured raise an <span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span>. If <code>nil</code>, <em>&#39;Q&#39;</em> is the default.</p>
1504
+ </div>
1505
+
1506
+ </li>
1507
+
1508
+ </ul>
1509
+
1510
+ <p class="tag_title">Returns:</p>
1511
+ <ul class="return">
1512
+
1513
+ <li>
1514
+
1515
+
1516
+ <span class='type'>(<tt>String</tt>)</span>
1517
+
1518
+
1519
+
1520
+ &mdash;
1521
+ <div class='inline'>
1522
+ <p>Returns a string that represents the short algebraic chess notation of the move.</p>
1523
+ </div>
1524
+
1525
+ </li>
1526
+
1527
+ </ul>
1528
+ <p class="tag_title">Raises:</p>
1529
+ <ul class="raise">
1530
+
1531
+ <li>
1532
+
1533
+
1534
+ <span class='type'>(<tt><span class='object_link'><a href="IllegalMoveError.html" title="Chess::IllegalMoveError (class)">IllegalMoveError</a></span></tt>)</span>
1535
+
1536
+
1537
+
1538
+ </li>
1539
+
1540
+ </ul>
1541
+
1542
+ </div>
1543
+
1544
+
1545
+ </div><table class="source_code">
1546
+ <tr>
1547
+ <td>
1548
+ <pre class="lines">
1549
+
1550
+
1551
+ 150
1552
+ 151
1553
+ 152
1554
+ 153
1555
+ 154
1556
+ 155
1557
+ 156
1558
+ 157
1559
+ 158
1560
+ 159
1561
+ 160
1562
+ 161
1563
+ 162
1564
+ 163</pre>
1565
+ </td>
1566
+ <td>
1567
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 150</span>
1568
+
1569
+ VALUE
1570
+ game_move3 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
1571
+ {
1572
+ Game *g;
1573
+ Data_Get_Struct (self, Game, g);
1574
+ Board *board = current_board (g);
1575
+ int from = FIX2INT (rb_from);
1576
+ int to = FIX2INT (rb_to);
1577
+ char promote_in = rb_promote_in == Qnil ? &#39;\0&#39; : StringValuePtr (rb_promote_in)[0];
1578
+ if (pseudo_legal_move (board, from, to) &amp;&amp; apply_move (g, from, to, promote_in))
1579
+ return rb_str_new2 (current_move (g));
1580
+ else
1581
+ rb_raise (illegal_move_error, &quot;Illegal move&quot;);
1582
+ }</pre>
1583
+ </td>
1584
+ </tr>
1585
+ </table>
1586
+ </div>
1587
+
1588
+ <div class="method_details ">
1589
+ <h3 class="signature " id="moves-instance_method">
1590
+
1591
+ #<strong>moves</strong> &#x21d2; <tt>Array&lt;String&gt;</tt>
1592
+
1593
+
1594
+
1595
+
1596
+
1597
+ </h3><div class="docstring">
1598
+ <div class="discussion">
1599
+
1600
+
1601
+ </div>
1602
+ </div>
1603
+ <div class="tags">
1604
+
1605
+ <div class="docstring">
1606
+ <div class="discussion">
1607
+
1608
+ <p>Returns the array with all moves done <em>(es: Nc3)</em>.</p>
1609
+
1610
+
1611
+ </div>
1612
+ </div>
1613
+ <div class="tags">
1614
+
1615
+ <p class="tag_title">Returns:</p>
1616
+ <ul class="return">
1617
+
1618
+ <li>
1619
+
1620
+
1621
+ <span class='type'>(<tt>Array&lt;String&gt;</tt>)</span>
1622
+
1623
+
1624
+
1625
+ </li>
1626
+
1627
+ </ul>
1628
+
1629
+ </div>
1630
+
1631
+
1632
+ </div><table class="source_code">
1633
+ <tr>
1634
+ <td>
1635
+ <pre class="lines">
1636
+
1637
+
1638
+ 241
1639
+ 242
1640
+ 243
1641
+ 244
1642
+ 245
1643
+ 246
1644
+ 247
1645
+ 248
1646
+ 249
1647
+ 250</pre>
1648
+ </td>
1649
+ <td>
1650
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 241</span>
1651
+
1652
+ VALUE
1653
+ game_moves (VALUE self)
1654
+ {
1655
+ Game *g;
1656
+ Data_Get_Struct (self, Game, g);
1657
+ VALUE moves = rb_ary_new ();
1658
+ for (int i = 0; i &lt; g-&gt;current; i++)
1659
+ rb_ary_push (moves, rb_str_new2 (g-&gt;moves[i]));
1660
+ return moves;
1661
+ }</pre>
1662
+ </td>
1663
+ </tr>
1664
+ </table>
1665
+ </div>
1666
+
1667
+ <div class="method_details ">
1668
+ <h3 class="signature " id="resign-instance_method">
1669
+
1670
+ #<strong>resign</strong>(color) &#x21d2; <tt>nil</tt>
1671
+
1672
+
1673
+
1674
+
1675
+
1676
+ </h3><div class="docstring">
1677
+ <div class="discussion">
1678
+
1679
+
1680
+ </div>
1681
+ </div>
1682
+ <div class="tags">
1683
+
1684
+ <div class="docstring">
1685
+ <div class="discussion">
1686
+
1687
+ <p>The game result is set to &#39;1-0&#39; if <code>color</code> is <em>black</em>, otherwise is set to &#39;0-1&#39; if color is <em>white</em>.</p>
1688
+
1689
+
1690
+ </div>
1691
+ </div>
1692
+ <div class="tags">
1693
+ <p class="tag_title">Parameters:</p>
1694
+ <ul class="param">
1695
+
1696
+ <li>
1697
+
1698
+ <span class='name'>color</span>
1699
+
1700
+
1701
+ <span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
1702
+
1703
+
1704
+
1705
+ &mdash;
1706
+ <div class='inline'>
1707
+ <p>The color of the player who resigns the game; it can be <code>:white</code> or <code>:black</code>.</p>
1708
+ </div>
1709
+
1710
+ </li>
1711
+
1712
+ </ul>
1713
+
1714
+ <p class="tag_title">Returns:</p>
1715
+ <ul class="return">
1716
+
1717
+ <li>
1718
+
1719
+
1720
+ <span class='type'>(<tt>nil</tt>)</span>
1721
+
1722
+
1723
+
1724
+ </li>
1725
+
1726
+ </ul>
1727
+
1728
+ </div>
1729
+
1730
+
1731
+ </div><table class="source_code">
1732
+ <tr>
1733
+ <td>
1734
+ <pre class="lines">
1735
+
1736
+
1737
+ 173
1738
+ 174
1739
+ 175
1740
+ 176
1741
+ 177
1742
+ 178
1743
+ 179
1744
+ 180
1745
+ 181
1746
+ 182
1747
+ 183
1748
+ 184
1749
+ 185
1750
+ 186
1751
+ 187
1752
+ 188</pre>
1753
+ </td>
1754
+ <td>
1755
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 173</span>
1756
+
1757
+ VALUE
1758
+ game_resign (VALUE self, VALUE color)
1759
+ {
1760
+ Game *g;
1761
+ Data_Get_Struct (self, Game, g);
1762
+ const char *c;
1763
+ if (TYPE (color) == T_SYMBOL)
1764
+ c = rb_id2name (SYM2ID (color));
1765
+ else
1766
+ c = StringValuePtr (color);
1767
+ if (strcmp (c, &quot;black&quot;) == 0)
1768
+ g-&gt;result = WHITE_WON;
1769
+ else if (strcmp (c, &quot;white&quot;) == 0)
1770
+ g-&gt;result = BLACK_WON;
1771
+ return Qnil;
1772
+ }</pre>
1773
+ </td>
1774
+ </tr>
1775
+ </table>
1776
+ </div>
1777
+
1778
+ <div class="method_details ">
1779
+ <h3 class="signature " id="result-instance_method">
1780
+
1781
+ #<strong>result</strong> &#x21d2; <tt>String</tt>
1782
+
1783
+
1784
+
1785
+
1786
+
1787
+ </h3><div class="docstring">
1788
+ <div class="discussion">
1789
+
1790
+
1791
+ </div>
1792
+ </div>
1793
+ <div class="tags">
1794
+
1795
+ <div class="docstring">
1796
+ <div class="discussion">
1797
+
1798
+ <p>Returns the result of the game.</p>
1799
+
1800
+
1801
+ </div>
1802
+ </div>
1803
+ <div class="tags">
1804
+
1805
+ <p class="tag_title">Returns:</p>
1806
+ <ul class="return">
1807
+
1808
+ <li>
1809
+
1810
+
1811
+ <span class='type'>(<tt>String</tt>)</span>
1812
+
1813
+
1814
+
1815
+ &mdash;
1816
+ <div class='inline'>
1817
+ <p>Returns the result of the game:</p>
1818
+ <ul><li>
1819
+ <p><code>*</code>: game in progress;</p>
1820
+ </li><li>
1821
+ <p><code>1-0</code>: white won;</p>
1822
+ </li><li>
1823
+ <p><code>0-1</code>: black won;</p>
1824
+ </li><li>
1825
+ <p><code>1/2-1/2</code>: draw.</p>
1826
+ </li></ul>
1827
+ </div>
1828
+
1829
+ </li>
1830
+
1831
+ </ul>
1832
+
1833
+ </div>
1834
+
1835
+
1836
+ </div><table class="source_code">
1837
+ <tr>
1838
+ <td>
1839
+ <pre class="lines">
1840
+
1841
+
1842
+ 306
1843
+ 307
1844
+ 308
1845
+ 309
1846
+ 310
1847
+ 311
1848
+ 312
1849
+ 313
1850
+ 314
1851
+ 315</pre>
1852
+ </td>
1853
+ <td>
1854
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 306</span>
1855
+
1856
+ VALUE
1857
+ game_result (VALUE self)
1858
+ {
1859
+ Game *g;
1860
+ Data_Get_Struct (self, Game, g);
1861
+ char *result = result_to_s (g-&gt;result);
1862
+ VALUE rb_result = rb_str_new2 (result);
1863
+ free (result);
1864
+ return rb_result;
1865
+ }</pre>
1866
+ </td>
1867
+ </tr>
1868
+ </table>
1869
+ </div>
1870
+
1871
+ <div class="method_details ">
1872
+ <h3 class="signature " id="rollback!-instance_method">
1873
+
1874
+ #<strong>rollback!</strong> &#x21d2; <tt><span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span></tt>
1875
+
1876
+
1877
+
1878
+
1879
+
1880
+ </h3><div class="docstring">
1881
+ <div class="discussion">
1882
+
1883
+
1884
+ </div>
1885
+ </div>
1886
+ <div class="tags">
1887
+
1888
+ <div class="docstring">
1889
+ <div class="discussion">
1890
+
1891
+ <p>Rollback last move.</p>
1892
+
1893
+
1894
+ </div>
1895
+ </div>
1896
+ <div class="tags">
1897
+
1898
+ <p class="tag_title">Returns:</p>
1899
+ <ul class="return">
1900
+
1901
+ <li>
1902
+
1903
+
1904
+ <span class='type'>(<tt><span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span></tt>)</span>
1905
+
1906
+
1907
+
1908
+ &mdash;
1909
+ <div class='inline'>
1910
+ <p>Returns <code>self</code> with last move cancelled.</p>
1911
+ </div>
1912
+
1913
+ </li>
1914
+
1915
+ </ul>
1916
+
1917
+ </div>
1918
+
1919
+
1920
+ </div><table class="source_code">
1921
+ <tr>
1922
+ <td>
1923
+ <pre class="lines">
1924
+
1925
+
1926
+ 360
1927
+ 361
1928
+ 362
1929
+ 363
1930
+ 364
1931
+ 365
1932
+ 366
1933
+ 367</pre>
1934
+ </td>
1935
+ <td>
1936
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 360</span>
1937
+
1938
+ VALUE
1939
+ game_rollback (VALUE self)
1940
+ {
1941
+ Game *g;
1942
+ Data_Get_Struct (self, Game, g);
1943
+ rollback (g);
1944
+ return self;
1945
+ }</pre>
1946
+ </td>
1947
+ </tr>
1948
+ </table>
1949
+ </div>
1950
+
1951
+ <div class="method_details ">
1952
+ <h3 class="signature " id="set_fen!-instance_method">
1953
+
1954
+ #<strong>set_fen!</strong>(fen) &#x21d2; <tt><span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span></tt>
1955
+
1956
+
1957
+
1958
+
1959
+
1960
+ </h3><div class="docstring">
1961
+ <div class="discussion">
1962
+
1963
+
1964
+ </div>
1965
+ </div>
1966
+ <div class="tags">
1967
+
1968
+ <div class="docstring">
1969
+ <div class="discussion">
1970
+
1971
+ <p>Set the game position by FEN string.</p>
1972
+
1973
+
1974
+ </div>
1975
+ </div>
1976
+ <div class="tags">
1977
+ <p class="tag_title">Parameters:</p>
1978
+ <ul class="param">
1979
+
1980
+ <li>
1981
+
1982
+ <span class='name'>fen</span>
1983
+
1984
+
1985
+ <span class='type'>(<tt>String</tt>)</span>
1986
+
1987
+
1988
+
1989
+ &mdash;
1990
+ <div class='inline'>
1991
+ <p>The FEN (Forsyth–Edwards Notation) string notation used to set the game position.</p>
1992
+ </div>
1993
+
1994
+ </li>
1995
+
1996
+ </ul>
1997
+
1998
+ <p class="tag_title">Returns:</p>
1999
+ <ul class="return">
2000
+
2001
+ <li>
2002
+
2003
+
2004
+ <span class='type'>(<tt><span class='object_link'><a href="Game.html" title="Chess::Game (class)">Game</a></span></tt>)</span>
2005
+
2006
+
2007
+
2008
+ &mdash;
2009
+ <div class='inline'>
2010
+ <p>Returns <code>self</code> with position of the pieces corresponding to the FEN string.</p>
2011
+ </div>
2012
+
2013
+ </li>
2014
+
2015
+ </ul>
2016
+
2017
+ </div>
2018
+
2019
+
2020
+ </div><table class="source_code">
2021
+ <tr>
2022
+ <td>
2023
+ <pre class="lines">
2024
+
2025
+
2026
+ 36
2027
+ 37
2028
+ 38
2029
+ 39
2030
+ 40
2031
+ 41
2032
+ 42
2033
+ 43</pre>
2034
+ </td>
2035
+ <td>
2036
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 36</span>
2037
+
2038
+ VALUE
2039
+ game_set_fen (VALUE self, VALUE fen)
2040
+ {
2041
+ Game *g;
2042
+ Data_Get_Struct (self, Game, g);
2043
+ set_fen (g, StringValuePtr (fen));
2044
+ return self;
2045
+ }</pre>
2046
+ </td>
2047
+ </tr>
2048
+ </table>
2049
+ </div>
2050
+
2051
+ <div class="method_details ">
2052
+ <h3 class="signature " id="size-instance_method">
2053
+
2054
+ #<strong>size</strong> &#x21d2; <tt>Integer</tt>
2055
+
2056
+
2057
+
2058
+
2059
+
2060
+ </h3><div class="docstring">
2061
+ <div class="discussion">
2062
+
2063
+
2064
+ </div>
2065
+ </div>
2066
+ <div class="tags">
2067
+
2068
+ <div class="docstring">
2069
+ <div class="discussion">
2070
+
2071
+ <p>Returns the number of moves done.</p>
2072
+
2073
+
2074
+ </div>
2075
+ </div>
2076
+ <div class="tags">
2077
+
2078
+ <p class="tag_title">Returns:</p>
2079
+ <ul class="return">
2080
+
2081
+ <li>
2082
+
2083
+
2084
+ <span class='type'>(<tt>Integer</tt>)</span>
2085
+
2086
+
2087
+
2088
+ </li>
2089
+
2090
+ </ul>
2091
+
2092
+ </div>
2093
+
2094
+
2095
+ </div><table class="source_code">
2096
+ <tr>
2097
+ <td>
2098
+ <pre class="lines">
2099
+
2100
+
2101
+ 322
2102
+ 323
2103
+ 324
2104
+ 325
2105
+ 326
2106
+ 327
2107
+ 328</pre>
2108
+ </td>
2109
+ <td>
2110
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 322</span>
2111
+
2112
+ VALUE
2113
+ game_size (VALUE self)
2114
+ {
2115
+ Game *g;
2116
+ Data_Get_Struct (self, Game, g);
2117
+ return INT2FIX (g-&gt;current);
2118
+ }</pre>
2119
+ </td>
2120
+ </tr>
2121
+ </table>
2122
+ </div>
2123
+
2124
+ <div class="method_details ">
2125
+ <h3 class="signature " id="threefold_repetition?-instance_method">
2126
+
2127
+ #<strong>threefold_repetition?</strong> &#x21d2; <tt>Boolean</tt>
2128
+
2129
+
2130
+
2131
+
2132
+
2133
+ </h3><div class="docstring">
2134
+ <div class="discussion">
2135
+
2136
+
2137
+ </div>
2138
+ </div>
2139
+ <div class="tags">
2140
+
2141
+ <div class="docstring">
2142
+ <div class="discussion">
2143
+
2144
+ <p>Returns <code>true</code> if a player can claim draw by the threefold repetition rule, <code>false</code> otherwise.</p>
2145
+
2146
+
2147
+ </div>
2148
+ </div>
2149
+ <div class="tags">
2150
+
2151
+
2152
+ </div>
2153
+
2154
+ <p class="tag_title">Returns:</p>
2155
+ <ul class="return">
2156
+
2157
+ <li>
2158
+
2159
+
2160
+ <span class='type'>(<tt>Boolean</tt>)</span>
2161
+
2162
+
2163
+
2164
+ </li>
2165
+
2166
+ </ul>
2167
+
2168
+ </div><table class="source_code">
2169
+ <tr>
2170
+ <td>
2171
+ <pre class="lines">
2172
+
2173
+
2174
+ 285
2175
+ 286
2176
+ 287
2177
+ 288
2178
+ 289
2179
+ 290
2180
+ 291
2181
+ 292
2182
+ 293
2183
+ 294</pre>
2184
+ </td>
2185
+ <td>
2186
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 285</span>
2187
+
2188
+ VALUE
2189
+ game_threefold_repetition (VALUE self)
2190
+ {
2191
+ Game *g;
2192
+ Data_Get_Struct (self, Game, g);
2193
+ if (threefold_repetition (g))
2194
+ return Qtrue;
2195
+ else
2196
+ return Qfalse;
2197
+ }</pre>
2198
+ </td>
2199
+ </tr>
2200
+ </table>
2201
+ </div>
2202
+
2203
+ <div class="method_details ">
2204
+ <h3 class="signature " id="to_s-instance_method">
2205
+
2206
+ #<strong>to_s</strong> &#x21d2; <tt>String</tt>
2207
+
2208
+
2209
+
2210
+
2211
+
2212
+ </h3><div class="docstring">
2213
+ <div class="discussion">
2214
+
2215
+
2216
+ </div>
2217
+ </div>
2218
+ <div class="tags">
2219
+
2220
+ <div class="docstring">
2221
+ <div class="discussion">
2222
+
2223
+ <p>Current <span class='object_link'><a href="Board.html" title="Chess::Board (class)">Board</a></span> to string.</p>
2224
+
2225
+
2226
+ </div>
2227
+ </div>
2228
+ <div class="tags">
2229
+
2230
+ <p class="tag_title">Returns:</p>
2231
+ <ul class="return">
2232
+
2233
+ <li>
2234
+
2235
+
2236
+ <span class='type'>(<tt>String</tt>)</span>
2237
+
2238
+
2239
+
2240
+ </li>
2241
+
2242
+ </ul>
2243
+
2244
+ </div>
2245
+
2246
+
2247
+ </div><table class="source_code">
2248
+ <tr>
2249
+ <td>
2250
+ <pre class="lines">
2251
+
2252
+
2253
+ 374
2254
+ 375
2255
+ 376
2256
+ 377
2257
+ 378
2258
+ 379
2259
+ 380
2260
+ 381
2261
+ 382
2262
+ 383
2263
+ 384</pre>
2264
+ </td>
2265
+ <td>
2266
+ <pre class="code"><span class="info file"># File 'ext/chess.c', line 374</span>
2267
+
2268
+ VALUE
2269
+ game_to_s (VALUE self)
2270
+ {
2271
+ Game *g;
2272
+ Data_Get_Struct (self, Game, g);
2273
+ Board *b = get_board (g, g-&gt;current-1);
2274
+ char *s = print_board (b);
2275
+ VALUE rb_s = rb_str_new2 (s);
2276
+ free (s);
2277
+ return rb_s;
2278
+ }</pre>
2279
+ </td>
2280
+ </tr>
2281
+ </table>
2282
+ </div>
2283
+
2284
+ </div>
2285
+
2286
+ </div>
2287
+
2288
+ <div id="footer">
2289
+ Generated on Thu Jan 28 17:31:41 2021 by
2290
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
2291
+ 0.9.26 (ruby-2.6.1).
2292
+ </div>
2293
+
2294
+ </div>
2295
+ </body>
2296
+ </html>