chess 0.1.3 → 0.1.4

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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/README.md +44 -0
  4. data/Rakefile +6 -7
  5. data/chess.gemspec +1 -1
  6. data/ext/bitboard.c +24 -0
  7. data/ext/board.c +78 -24
  8. data/ext/board.h +4 -2
  9. data/ext/chess.c +216 -196
  10. data/ext/chess.h +1 -0
  11. data/ext/common.c +10 -0
  12. data/ext/game.c +33 -16
  13. data/ext/special.c +14 -11
  14. data/ext/special.h +1 -2
  15. data/lib/chess/exceptions.rb +7 -10
  16. data/lib/chess/game.rb +66 -50
  17. data/lib/chess/gnuchess.rb +19 -25
  18. data/lib/chess/pgn.rb +49 -9
  19. data/lib/chess/utf8_notation.rb +11 -9
  20. data/lib/chess/version.rb +1 -1
  21. data/test/pgn_collection/illegal/0001.pgn +18 -0
  22. data/test/pgn_collection/illegal/0002.pgn +17 -0
  23. data/test/pgn_collection/illegal/0003.pgn +13 -0
  24. data/test/pgn_collection/illegal/0004.pgn +15 -0
  25. data/test/pgn_collection/illegal/0005.pgn +16 -0
  26. data/test/pgn_collection/invalid/0001.pgn +20 -0
  27. data/test/pgn_collection/invalid/0002.pgn +16 -0
  28. data/test/pgn_collection/invalid/0003.pgn +13 -0
  29. data/test/pgn_collection/invalid/0004.pgn +15 -0
  30. data/test/pgn_collection/valid/0001.pgn +6 -7
  31. data/test/pgn_collection/valid/0002.pgn +8 -9
  32. data/test/pgn_collection/valid/0005.pgn +7 -8
  33. data/test/pgn_collection/valid/0009.pgn +14 -15
  34. data/test/pgn_collection/valid/0010.pgn +6 -7
  35. data/test/pgn_collection/valid/0011.pgn +5 -6
  36. data/test/pgn_collection/valid/0012.pgn +0 -1
  37. data/test/pgn_collection/valid/0013.pgn +5 -6
  38. data/test/pgn_collection/valid/0014.pgn +6 -7
  39. data/test/pgn_collection/valid/0020.pgn +6 -7
  40. data/test/pgn_collection/valid/0021.pgn +15 -16
  41. data/test/pgn_collection/valid/0971.pgn +22 -14
  42. data/test/test_big_pgn_collection.rb +12 -5
  43. data/test/test_helper.rb +1 -1
  44. data/test/test_illegal_moves.rb +14 -0
  45. data/test/test_insufficient_material.rb +13 -1
  46. data/test/test_particular_situations.rb +14 -0
  47. data/test/test_pgn.rb +24 -0
  48. data/test/test_pgn_collection.rb +1 -4
  49. metadata +30 -63
  50. data/README.rdoc +0 -44
  51. data/doc/Chess.html +0 -112
  52. data/doc/Chess/BadNotationError.html +0 -107
  53. data/doc/Chess/Board.html +0 -700
  54. data/doc/Chess/CGame.html +0 -1004
  55. data/doc/Chess/Game.html +0 -684
  56. data/doc/Chess/Gnuchess.html +0 -215
  57. data/doc/Chess/IllegalMoveError.html +0 -105
  58. data/doc/Chess/InvalidFenFormatError.html +0 -105
  59. data/doc/Chess/InvalidPgnFormatError.html +0 -105
  60. data/doc/Chess/Pgn.html +0 -309
  61. data/doc/Chess/UTF8Notation.html +0 -174
  62. data/doc/README_rdoc.html +0 -143
  63. data/doc/created.rid +0 -15
  64. data/doc/css/fonts.css +0 -167
  65. data/doc/css/rdoc.css +0 -590
  66. data/doc/fonts/Lato-Light.ttf +0 -0
  67. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  68. data/doc/fonts/Lato-Regular.ttf +0 -0
  69. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  70. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  71. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  72. data/doc/images/add.png +0 -0
  73. data/doc/images/arrow_up.png +0 -0
  74. data/doc/images/brick.png +0 -0
  75. data/doc/images/brick_link.png +0 -0
  76. data/doc/images/bug.png +0 -0
  77. data/doc/images/bullet_black.png +0 -0
  78. data/doc/images/bullet_toggle_minus.png +0 -0
  79. data/doc/images/bullet_toggle_plus.png +0 -0
  80. data/doc/images/date.png +0 -0
  81. data/doc/images/delete.png +0 -0
  82. data/doc/images/find.png +0 -0
  83. data/doc/images/loadingAnimation.gif +0 -0
  84. data/doc/images/macFFBgHack.png +0 -0
  85. data/doc/images/package.png +0 -0
  86. data/doc/images/page_green.png +0 -0
  87. data/doc/images/page_white_text.png +0 -0
  88. data/doc/images/page_white_width.png +0 -0
  89. data/doc/images/plugin.png +0 -0
  90. data/doc/images/ruby.png +0 -0
  91. data/doc/images/tag_blue.png +0 -0
  92. data/doc/images/tag_green.png +0 -0
  93. data/doc/images/transparent.png +0 -0
  94. data/doc/images/wrench.png +0 -0
  95. data/doc/images/wrench_orange.png +0 -0
  96. data/doc/images/zoom.png +0 -0
  97. data/doc/index.html +0 -160
  98. data/doc/js/darkfish.js +0 -161
  99. data/doc/js/jquery.js +0 -4
  100. data/doc/js/navigation.js +0 -142
  101. data/doc/js/navigation.js.gz +0 -0
  102. data/doc/js/search.js +0 -109
  103. data/doc/js/search_index.js +0 -1
  104. data/doc/js/search_index.js.gz +0 -0
  105. data/doc/js/searcher.js +0 -229
  106. data/doc/js/searcher.js.gz +0 -0
  107. data/doc/table_of_contents.html +0 -331
data/doc/Chess/CGame.html DELETED
@@ -1,1004 +0,0 @@
1
- <!DOCTYPE html>
2
-
3
- <html>
4
- <head>
5
- <meta charset="UTF-8">
6
-
7
- <title>class Chess::CGame - Chess</title>
8
-
9
- <script type="text/javascript">
10
- var rdoc_rel_prefix = "../";
11
- var index_rel_prefix = "../";
12
- </script>
13
-
14
- <script src="../js/jquery.js"></script>
15
- <script src="../js/darkfish.js"></script>
16
-
17
- <link href="../css/fonts.css" rel="stylesheet">
18
- <link href="../css/rdoc.css" rel="stylesheet">
19
-
20
-
21
-
22
- <body id="top" role="document" class="class">
23
- <nav role="navigation">
24
- <div id="project-navigation">
25
- <div id="home-section" role="region" title="Quick navigation" class="nav-section">
26
- <h2>
27
- <a href="../index.html" rel="home">Home</a>
28
- </h2>
29
-
30
- <div id="table-of-contents-navigation">
31
- <a href="../table_of_contents.html#pages">Pages</a>
32
- <a href="../table_of_contents.html#classes">Classes</a>
33
- <a href="../table_of_contents.html#methods">Methods</a>
34
- </div>
35
- </div>
36
-
37
- <div id="search-section" role="search" class="project-section initially-hidden">
38
- <form action="#" method="get" accept-charset="utf-8">
39
- <div id="search-field-wrapper">
40
- <input id="search-field" role="combobox" aria-label="Search"
41
- aria-autocomplete="list" aria-controls="search-results"
42
- type="text" name="search" placeholder="Search" spellcheck="false"
43
- title="Type to search, Up and Down to navigate, Enter to load">
44
- </div>
45
-
46
- <ul id="search-results" aria-label="Search Results"
47
- aria-busy="false" aria-expanded="false"
48
- aria-atomic="false" class="initially-hidden"></ul>
49
- </form>
50
- </div>
51
-
52
- </div>
53
-
54
-
55
-
56
- <div id="class-metadata">
57
-
58
- <div id="parent-class-section" class="nav-section">
59
- <h3>Parent</h3>
60
-
61
-
62
- <p class="link">Object
63
-
64
- </div>
65
-
66
-
67
-
68
- <!-- Method Quickref -->
69
- <div id="method-list-section" class="nav-section">
70
- <h3>Methods</h3>
71
-
72
- <ul class="link-list" role="directory">
73
-
74
- <li ><a href="#method-i-5B-5D">#[]</a>
75
-
76
- <li ><a href="#method-i-board">#board</a>
77
-
78
- <li ><a href="#method-i-coord_moves">#coord_moves</a>
79
-
80
- <li ><a href="#method-i-current">#current</a>
81
-
82
- <li ><a href="#method-i-draw">#draw</a>
83
-
84
- <li ><a href="#method-i-each">#each</a>
85
-
86
- <li ><a href="#method-i-move">#move</a>
87
-
88
- <li ><a href="#method-i-move2">#move2</a>
89
-
90
- <li ><a href="#method-i-move3">#move3</a>
91
-
92
- <li ><a href="#method-i-moves">#moves</a>
93
-
94
- <li ><a href="#method-i-resign">#resign</a>
95
-
96
- <li ><a href="#method-i-result">#result</a>
97
-
98
- <li ><a href="#method-i-rollback-21">#rollback!</a>
99
-
100
- <li ><a href="#method-i-set_fen-21">#set_fen!</a>
101
-
102
- <li ><a href="#method-i-size">#size</a>
103
-
104
- <li ><a href="#method-i-threefold_repetition-3F">#threefold_repetition?</a>
105
-
106
- <li ><a href="#method-i-to_s">#to_s</a>
107
-
108
- </ul>
109
- </div>
110
-
111
- </div>
112
- </nav>
113
-
114
- <main role="main" aria-labelledby="class-Chess::CGame">
115
- <h1 id="class-Chess::CGame" class="class">
116
- class Chess::CGame
117
- </h1>
118
-
119
- <section class="description">
120
-
121
- <p>This class rappresents a collection of boards of a single chess game.</p>
122
-
123
- </section>
124
-
125
-
126
-
127
-
128
- <section id="5Buntitled-5D" class="documentation-section">
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
- <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
139
- <header>
140
- <h3>Public Instance Methods</h3>
141
- </header>
142
-
143
-
144
- <div id="method-i-5B-5D" class="method-detail ">
145
-
146
-
147
- <div class="method-heading">
148
- <span class="method-callseq">
149
- [n]
150
- </span>
151
-
152
- <span class="method-click-advice">click to toggle source</span>
153
-
154
- </div>
155
-
156
-
157
-
158
- <div class="method-description">
159
-
160
- <p>Returns the <code>n</code>-th <a href="Board.html">Board</a> of the <a
161
- href="Game.html">Game</a> or <code>nil</code> if the <code>n</code>-th <a
162
- href="Board.html">Board</a> does not exist.</p>
163
-
164
-
165
-
166
-
167
- <div class="method-source-code" id="5B-5D-source">
168
- <pre>VALUE
169
- game_boards (VALUE self, VALUE index)
170
- {
171
- Game *g;
172
- Data_Get_Struct (self, Game, g);
173
- int n = FIX2INT (index);
174
- Board *board = get_board (g, n);
175
- if (board)
176
- return Data_Wrap_Struct (board_klass, 0, 0, board);
177
- return Qnil;
178
- }</pre>
179
- </div>
180
-
181
- </div>
182
-
183
-
184
-
185
-
186
- </div>
187
-
188
-
189
- <div id="method-i-board" class="method-detail method-alias">
190
-
191
- <div class="method-heading">
192
- <span class="method-name">board</span><span
193
- class="method-args">()</span>
194
-
195
- </div>
196
-
197
-
198
- <div class="method-description">
199
-
200
-
201
-
202
-
203
-
204
-
205
- </div>
206
-
207
-
208
-
209
-
210
- <div class="aliases">
211
- Alias for: <a href="CGame.html#method-i-current">current</a>
212
- </div>
213
-
214
- </div>
215
-
216
-
217
- <div id="method-i-coord_moves" class="method-detail ">
218
-
219
-
220
- <div class="method-heading">
221
- <span class="method-callseq">
222
- coord_moves
223
- </span>
224
-
225
- <span class="method-click-advice">click to toggle source</span>
226
-
227
- </div>
228
-
229
-
230
-
231
- <div class="method-description">
232
-
233
- <p>Returns the array with all moves done in coordinate chess notation <em>(es:
234
- b1c3)</em>.</p>
235
-
236
-
237
-
238
-
239
- <div class="method-source-code" id="coord_moves-source">
240
- <pre>VALUE
241
- game_coord_moves (VALUE self)
242
- {
243
- Game *g;
244
- Data_Get_Struct (self, Game, g);
245
- VALUE moves = rb_ary_new ();
246
- for (int i = 0; i &lt; g-&gt;current; i++)
247
- rb_ary_push (moves, rb_str_new2 (g-&gt;coord_moves[i]));
248
- return moves;
249
- }</pre>
250
- </div>
251
-
252
- </div>
253
-
254
-
255
-
256
-
257
- </div>
258
-
259
-
260
- <div id="method-i-current" class="method-detail ">
261
-
262
-
263
- <div class="method-heading">
264
- <span class="method-callseq">
265
- current
266
- </span>
267
-
268
- <span class="method-click-advice">click to toggle source</span>
269
-
270
- </div>
271
-
272
-
273
-
274
- <div class="method-description">
275
-
276
- <p>Returns the current <a href="Board.html">Board</a> of the <a
277
- href="Game.html">Game</a> (the current chess position of the game).</p>
278
-
279
-
280
-
281
-
282
- <div class="method-source-code" id="current-source">
283
- <pre>VALUE
284
- game_current_board (VALUE self)
285
- {
286
- Game *g;
287
- Data_Get_Struct (self, Game, g);
288
- return game_boards (self, INT2FIX (g-&gt;current-1));
289
- }</pre>
290
- </div>
291
-
292
- </div>
293
-
294
-
295
- <div class="aliases">
296
- Also aliased as: <a href="CGame.html#method-i-board">board</a>
297
- </div>
298
-
299
-
300
-
301
- </div>
302
-
303
-
304
- <div id="method-i-draw" class="method-detail ">
305
-
306
-
307
- <div class="method-heading">
308
- <span class="method-callseq">
309
- draw
310
- </span>
311
-
312
- <span class="method-click-advice">click to toggle source</span>
313
-
314
- </div>
315
-
316
-
317
-
318
- <div class="method-description">
319
-
320
- <p>The game result is set to draw.</p>
321
-
322
-
323
-
324
-
325
- <div class="method-source-code" id="draw-source">
326
- <pre>VALUE
327
- game_draw (VALUE self)
328
- {
329
- Game *g;
330
- Data_Get_Struct (self, Game, g);
331
- g-&gt;result = DRAW;
332
- return Qnil;
333
- }</pre>
334
- </div>
335
-
336
- </div>
337
-
338
-
339
-
340
-
341
- </div>
342
-
343
-
344
- <div id="method-i-each" class="method-detail ">
345
-
346
-
347
- <div class="method-heading">
348
- <span class="method-callseq">
349
- each { |board, move, coord_move, index| block }
350
- </span>
351
-
352
- <span class="method-click-advice">click to toggle source</span>
353
-
354
- </div>
355
-
356
-
357
-
358
- <div class="method-description">
359
-
360
- <p>Calls <code>block</code> once for each <code>board</code> in self, passing
361
- that <code>board</code>, <code>move</code>, <code>coord_move</code> and
362
- <code>index</code> as parameters. Return self. If no block is given, the
363
- array of game moves is returned instead.</p>
364
-
365
-
366
-
367
-
368
- <div class="method-source-code" id="each-source">
369
- <pre>VALUE
370
- game_each (VALUE self)
371
- {
372
- if (!rb_block_given_p ())
373
- return game_moves(self);
374
- Game *g;
375
- Data_Get_Struct (self, Game, g);
376
- for (int i = 0; i &lt; g-&gt;current; i++)
377
- rb_yield_values (4,
378
- Data_Wrap_Struct (board_klass, 0, 0, get_board (g, i)),
379
- rb_str_new2 (g-&gt;moves[i]),
380
- rb_str_new2 (g-&gt;coord_moves[i]),
381
- INT2FIX (i));
382
- return self;
383
- }</pre>
384
- </div>
385
-
386
- </div>
387
-
388
-
389
-
390
-
391
- </div>
392
-
393
-
394
- <div id="method-i-move" class="method-detail ">
395
-
396
-
397
- <div class="method-heading">
398
- <span class="method-callseq">
399
- move(piece, disambiguating, to_coord, promote_in)
400
- </span>
401
-
402
- <span class="method-click-advice">click to toggle source</span>
403
-
404
- </div>
405
-
406
-
407
-
408
- <div class="method-description">
409
-
410
- <p>Make a move. This add a new <a href="Board.html">Board</a> in the <a
411
- href="Game.html">Game</a>.</p>
412
-
413
- <p>Parameters are:</p>
414
- <dl class="rdoc-list note-list"><dt><code>piece</code>
415
- <dd>
416
- <p>the character of the moving piece <em>(&#39;P&#39;, &#39;R&#39;,
417
- &#39;N&#39;, &#39;B&#39;, &#39;Q&#39;, &#39;K&#39;)</em>.</p>
418
- </dd><dt><code>disambiguating</code>
419
- <dd>
420
- <p>when two (or more) identical pieces can move to the same square, the moving
421
- piece is uniquely identified by specifying the piece&#39;s letter, followed
422
- by (in descending order of preference):</p>
423
- <ul><li>
424
- <p>the file of departure (if they differ); or</p>
425
- </li><li>
426
- <p>the rank of departure (if the files are the same but the ranks differ); or</p>
427
- </li><li>
428
- <p>both the rank and file (if neither alone is sufficient to identify the
429
- piece—which occurs only in rare cases where one or more pawns have
430
- promoted, resulting in a player having three or more identical pieces able
431
- to reach the same square).</p>
432
- </li></ul>
433
-
434
- <p>Keep blank if no needed.</p>
435
- </dd><dt><code>to_coord</code>
436
- <dd>
437
- <p>the square where the moving piece will <em>(&#39;a1&#39;, &#39;a2&#39;, … ,
438
- &#39;h7&#39;, &#39;h8&#39;)</em>.</p>
439
- </dd><dt><code>promote_in</code>
440
- <dd>
441
- <p>the character of promotion piece <em>(&#39;R&#39;, &#39;N&#39;,
442
- &#39;B&#39;, &#39;Q&#39;)</em>. If no promotion occured, this param will be
443
- ignored. If no value is passed, &#39;Q&#39; is the default.</p>
444
- </dd></dl>
445
-
446
- <p>This method returns a string that represents the short algebraic chess
447
- notation of the move or raise an <a
448
- href="IllegalMoveError.html">IllegalMoveError</a> if the move is illegal.</p>
449
-
450
-
451
-
452
-
453
- <div class="method-source-code" id="move-source">
454
- <pre>VALUE
455
- game_move (VALUE self, VALUE rb_piece, VALUE rb_disambiguating, VALUE rb_to_coord, VALUE rb_promote_in)
456
- {
457
- Game *g;
458
- Data_Get_Struct (self, Game, g);
459
- Board *board = current_board (g);
460
- char piece = StringValuePtr (rb_piece)[0];
461
- char *disambiguating = StringValuePtr (rb_disambiguating);
462
- char *to_coord = StringValuePtr (rb_to_coord);
463
- char promote_in = StringValuePtr (rb_promote_in)[0];
464
- int from, to;
465
- get_coord (board, piece, disambiguating, to_coord, promote_in, &amp;from, &amp;to);
466
- // printf (&quot;From: %d, To: %d, Promo: %c\n&quot;, from , to , promote_in);
467
- if (pseudo_legal_move (board, from, to) &amp;&amp; apply_move (g, from, to, promote_in))
468
- return rb_str_new2 (current_move (g));
469
- else
470
- rb_raise (illegal_move_error, &quot;Illegal move&quot;);
471
- }</pre>
472
- </div>
473
-
474
- </div>
475
-
476
-
477
-
478
-
479
- </div>
480
-
481
-
482
- <div id="method-i-move2" class="method-detail ">
483
-
484
-
485
- <div class="method-heading">
486
- <span class="method-callseq">
487
- move2(from, to, promote_in)
488
- </span>
489
-
490
- <span class="method-click-advice">click to toggle source</span>
491
-
492
- </div>
493
-
494
-
495
-
496
- <div class="method-description">
497
-
498
- <p>Make a move. This add a new <a href="Board.html">Board</a> in the <a
499
- href="Game.html">Game</a>.</p>
500
-
501
- <p>Parameters are:</p>
502
- <dl class="rdoc-list note-list"><dt><code>from</code>
503
- <dd>
504
- <p>the 2 character string representing the starting square of the moving piece
505
- <em>(&#39;a1&#39;, &#39;a2&#39;, … , &#39;h7&#39;, &#39;h8&#39;)</em>.</p>
506
- </dd><dt><code>to</code>
507
- <dd>
508
- <p>the 2 character string representing the ending square of the moving piece
509
- <em>(&#39;a1&#39;, &#39;a2&#39;, … , &#39;h7&#39;, &#39;h8&#39;)</em>.</p>
510
- </dd><dt><code>promote_in</code>
511
- <dd>
512
- <p>the character of promotion piece <em>(&#39;R&#39;, &#39;N&#39;,
513
- &#39;B&#39;, &#39;Q&#39;)</em>. If no promotion occured, this param will be
514
- ignored. If no value is passed, &#39;Q&#39; is the default.</p>
515
- </dd></dl>
516
-
517
- <p>This method returns a string that represents the short algebraic chess
518
- notation of the move or raise an <a
519
- href="IllegalMoveError.html">IllegalMoveError</a> if the move is illegal.</p>
520
-
521
-
522
-
523
-
524
- <div class="method-source-code" id="move2-source">
525
- <pre>VALUE
526
- game_move2 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
527
- {
528
- Game *g;
529
- Data_Get_Struct (self, Game, g);
530
- Board *board = current_board (g);
531
- int from = coord_to_square (StringValuePtr (rb_from));
532
- int to = coord_to_square (StringValuePtr (rb_to));
533
- char promote_in = StringValuePtr (rb_promote_in)[0];
534
- if (pseudo_legal_move (board, from, to) &amp;&amp; apply_move (g, from, to, promote_in))
535
- return rb_str_new2 (current_move (g));
536
- else
537
- rb_raise (illegal_move_error, &quot;Illegal move&quot;);
538
- }</pre>
539
- </div>
540
-
541
- </div>
542
-
543
-
544
-
545
-
546
- </div>
547
-
548
-
549
- <div id="method-i-move3" class="method-detail ">
550
-
551
-
552
- <div class="method-heading">
553
- <span class="method-callseq">
554
- move3(from, to, promote_in)
555
- </span>
556
-
557
- <span class="method-click-advice">click to toggle source</span>
558
-
559
- </div>
560
-
561
-
562
-
563
- <div class="method-description">
564
-
565
- <p>Make a move. This add a new <a href="Board.html">Board</a> in the <a
566
- href="Game.html">Game</a>.</p>
567
-
568
- <p>Each square on the chessboard is represented by an integer according to the
569
- following scheme:</p>
570
-
571
- <pre>8 | 56 57 58 59 60 61 62 63
572
- 7 | 48 49 50 51 52 53 54 55
573
- 6 | 40 41 42 43 44 45 46 47
574
- 5 | 32 33 34 35 36 37 38 39
575
- 4 | 24 25 26 27 28 29 30 31
576
- 3 | 16 17 18 19 20 21 22 23
577
- 2 | 8 9 10 11 12 13 14 15
578
- 1 | 0 1 2 3 4 5 6 7
579
- +-------------------------
580
- a b c d e f g h</pre>
581
-
582
- <p>Parameters are:</p>
583
- <dl class="rdoc-list note-list"><dt><code>from</code>
584
- <dd>
585
- <p>the integer representing the starting square of the moving piece.</p>
586
- </dd><dt><code>to</code>
587
- <dd>
588
- <p>the integer representing the ending square of the moving piece.</p>
589
- </dd><dt><code>promote_in</code>
590
- <dd>
591
- <p>the character of promotion piece <em>(&#39;R&#39;, &#39;N&#39;,
592
- &#39;B&#39;, &#39;Q&#39;)</em>. If no promotion occured, this param will be
593
- ignored. If no value is passed, &#39;Q&#39; is the default.</p>
594
- </dd></dl>
595
-
596
- <p>This method returns a string that represents the short algebraic chess
597
- notation of the move or raise an <a
598
- href="IllegalMoveError.html">IllegalMoveError</a> if the move is illegal.</p>
599
-
600
-
601
-
602
-
603
- <div class="method-source-code" id="move3-source">
604
- <pre>VALUE
605
- game_move3 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
606
- {
607
- Game *g;
608
- Data_Get_Struct (self, Game, g);
609
- Board *board = current_board (g);
610
- int from = FIX2INT (rb_from);
611
- int to = FIX2INT (rb_to);
612
- char promote_in = StringValuePtr (rb_promote_in)[0];
613
- if (pseudo_legal_move (board, from, to) &amp;&amp; apply_move (g, from, to, promote_in))
614
- return rb_str_new2 (current_move (g));
615
- else
616
- rb_raise (illegal_move_error, &quot;Illegal move&quot;);
617
- }</pre>
618
- </div>
619
-
620
- </div>
621
-
622
-
623
-
624
-
625
- </div>
626
-
627
-
628
- <div id="method-i-moves" class="method-detail ">
629
-
630
-
631
- <div class="method-heading">
632
- <span class="method-callseq">
633
- moves
634
- </span>
635
-
636
- <span class="method-click-advice">click to toggle source</span>
637
-
638
- </div>
639
-
640
-
641
-
642
- <div class="method-description">
643
-
644
- <p>Returns the array with all moves done <em>(es: Nc3)</em>.</p>
645
-
646
-
647
-
648
-
649
- <div class="method-source-code" id="moves-source">
650
- <pre>VALUE
651
- game_moves (VALUE self)
652
- {
653
- Game *g;
654
- Data_Get_Struct (self, Game, g);
655
- VALUE moves = rb_ary_new ();
656
- for (int i = 0; i &lt; g-&gt;current; i++)
657
- rb_ary_push (moves, rb_str_new2 (g-&gt;moves[i]));
658
- return moves;
659
- }</pre>
660
- </div>
661
-
662
- </div>
663
-
664
-
665
-
666
-
667
- </div>
668
-
669
-
670
- <div id="method-i-resign" class="method-detail ">
671
-
672
-
673
- <div class="method-heading">
674
- <span class="method-callseq">
675
- resign(color)
676
- </span>
677
-
678
- <span class="method-click-advice">click to toggle source</span>
679
-
680
- </div>
681
-
682
-
683
-
684
- <div class="method-description">
685
-
686
- <p>The game result is set to &#39;1-0&#39; if <code>color</code> is “black”,
687
- otherwise is set to &#39;0-1&#39; if color is “white”.</p>
688
-
689
- <p>Parameters are:</p>
690
- <dl class="rdoc-list note-list"><dt><code>color</code>
691
- <dd>
692
- <p>the color of the player who resigns the game; it can be <code>:white</code>
693
- or <code>:black</code>.</p>
694
- </dd></dl>
695
-
696
-
697
-
698
-
699
- <div class="method-source-code" id="resign-source">
700
- <pre>VALUE
701
- game_resign (VALUE self, VALUE color)
702
- {
703
- Game *g;
704
- Data_Get_Struct (self, Game, g);
705
- const char *c;
706
- if (TYPE (color) == T_SYMBOL)
707
- c = rb_id2name (SYM2ID (color));
708
- else
709
- c = StringValuePtr (color);
710
- if (strcmp (c, &quot;black&quot;) == 0)
711
- g-&gt;result = WHITE_WON;
712
- else if (strcmp (c, &quot;white&quot;) == 0)
713
- g-&gt;result = BLACK_WON;
714
- return Qnil;
715
- }</pre>
716
- </div>
717
-
718
- </div>
719
-
720
-
721
-
722
-
723
- </div>
724
-
725
-
726
- <div id="method-i-result" class="method-detail ">
727
-
728
-
729
- <div class="method-heading">
730
- <span class="method-callseq">
731
- result
732
- </span>
733
-
734
- <span class="method-click-advice">click to toggle source</span>
735
-
736
- </div>
737
-
738
-
739
-
740
- <div class="method-description">
741
-
742
- <p>Returns the result of the game:</p>
743
- <dl class="rdoc-list note-list"><dt>*
744
- <dd>
745
- <p>game in progress;</p>
746
- </dd><dt>1-0
747
- <dd>
748
- <p>white won;</p>
749
- </dd><dt>0-1
750
- <dd>
751
- <p>black won;</p>
752
- </dd><dt>1/2-1/2
753
- <dd>
754
- <p>draw</p>
755
- </dd></dl>
756
-
757
-
758
-
759
-
760
- <div class="method-source-code" id="result-source">
761
- <pre>VALUE
762
- game_result (VALUE self)
763
- {
764
- Game *g;
765
- Data_Get_Struct (self, Game, g);
766
- char *result = result_to_s (g-&gt;result);
767
- VALUE rb_result = rb_str_new2 (result);
768
- free (result);
769
- return rb_result;
770
- }</pre>
771
- </div>
772
-
773
- </div>
774
-
775
-
776
-
777
-
778
- </div>
779
-
780
-
781
- <div id="method-i-rollback-21" class="method-detail ">
782
-
783
-
784
- <div class="method-heading">
785
- <span class="method-callseq">
786
- rollback!
787
- </span>
788
-
789
- <span class="method-click-advice">click to toggle source</span>
790
-
791
- </div>
792
-
793
-
794
-
795
- <div class="method-description">
796
-
797
- <p>Rollback last move.</p>
798
-
799
-
800
-
801
-
802
- <div class="method-source-code" id="rollback-21-source">
803
- <pre>VALUE
804
- game_rollback (VALUE self)
805
- {
806
- Game *g;
807
- Data_Get_Struct (self, Game, g);
808
- rollback (g);
809
- return self;
810
- }</pre>
811
- </div>
812
-
813
- </div>
814
-
815
-
816
-
817
-
818
- </div>
819
-
820
-
821
- <div id="method-i-set_fen-21" class="method-detail ">
822
-
823
-
824
- <div class="method-heading">
825
- <span class="method-callseq">
826
- set_fen!(fen)
827
- </span>
828
-
829
- <span class="method-click-advice">click to toggle source</span>
830
-
831
- </div>
832
-
833
-
834
-
835
- <div class="method-description">
836
-
837
- <p>Set the game position with a FEN string.</p>
838
-
839
- <p>Parameters are:</p>
840
- <dl class="rdoc-list note-list"><dt><code>fen</code>
841
- <dd>
842
- <p>the FEN (Forsyth–Edwards Notation) string notation used to set the game
843
- position.</p>
844
- </dd></dl>
845
-
846
-
847
-
848
-
849
- <div class="method-source-code" id="set_fen-21-source">
850
- <pre>VALUE
851
- game_set_fen (VALUE self, VALUE fen)
852
- {
853
- Game *g;
854
- Data_Get_Struct (self, Game, g);
855
- set_fen (g, StringValuePtr (fen));
856
- return self;
857
- }</pre>
858
- </div>
859
-
860
- </div>
861
-
862
-
863
-
864
-
865
- </div>
866
-
867
-
868
- <div id="method-i-size" class="method-detail ">
869
-
870
-
871
- <div class="method-heading">
872
- <span class="method-callseq">
873
- size
874
- </span>
875
-
876
- <span class="method-click-advice">click to toggle source</span>
877
-
878
- </div>
879
-
880
-
881
-
882
- <div class="method-description">
883
-
884
- <p>Returns the number of moves done.</p>
885
-
886
-
887
-
888
-
889
- <div class="method-source-code" id="size-source">
890
- <pre>VALUE
891
- game_size (VALUE self)
892
- {
893
- Game *g;
894
- Data_Get_Struct (self, Game, g);
895
- return INT2FIX (g-&gt;current);
896
- }</pre>
897
- </div>
898
-
899
- </div>
900
-
901
-
902
-
903
-
904
- </div>
905
-
906
-
907
- <div id="method-i-threefold_repetition-3F" class="method-detail ">
908
-
909
-
910
- <div class="method-heading">
911
- <span class="method-callseq">
912
- threefold_repetition?
913
- </span>
914
-
915
- <span class="method-click-advice">click to toggle source</span>
916
-
917
- </div>
918
-
919
-
920
-
921
- <div class="method-description">
922
-
923
- <p>Returns <code>true</code> if a player can claim draw by the threefold
924
- repetition rule, <code>false</code> otherwise.</p>
925
-
926
-
927
-
928
-
929
- <div class="method-source-code" id="threefold_repetition-3F-source">
930
- <pre>VALUE
931
- game_threefold_repetition (VALUE self)
932
- {
933
- Game *g;
934
- Data_Get_Struct (self, Game, g);
935
- if (threefold_repetition (g))
936
- return Qtrue;
937
- else
938
- return Qfalse;
939
- }</pre>
940
- </div>
941
-
942
- </div>
943
-
944
-
945
-
946
-
947
- </div>
948
-
949
-
950
- <div id="method-i-to_s" class="method-detail ">
951
-
952
-
953
- <div class="method-heading">
954
- <span class="method-callseq">
955
- to_s
956
- </span>
957
-
958
- <span class="method-click-advice">click to toggle source</span>
959
-
960
- </div>
961
-
962
-
963
-
964
- <div class="method-description">
965
-
966
- <p>Current board to string.</p>
967
-
968
-
969
-
970
-
971
- <div class="method-source-code" id="to_s-source">
972
- <pre>VALUE
973
- game_to_s (VALUE self)
974
- {
975
- Game *g;
976
- Data_Get_Struct (self, Game, g);
977
- Board *b = get_board (g, g-&gt;current-1);
978
- char *s = print_board (b);
979
- VALUE rb_s = rb_str_new2 (s);
980
- free (s);
981
- return rb_s;
982
- }</pre>
983
- </div>
984
-
985
- </div>
986
-
987
-
988
-
989
-
990
- </div>
991
-
992
-
993
- </section>
994
-
995
- </section>
996
- </main>
997
-
998
-
999
- <footer id="validator-badges" role="contentinfo">
1000
- <p><a href="http://validator.w3.org/check/referer">Validate</a>
1001
- <p>Generated by <a href="https://rdoc.github.io/rdoc">RDoc</a> 5.1.0.
1002
- <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
1003
- </footer>
1004
-