chess 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +1 -1
  3. data/Rakefile +3 -4
  4. data/chess.gemspec +5 -0
  5. data/doc/Chess.html +112 -0
  6. data/doc/Chess/BadNotationError.html +107 -0
  7. data/doc/Chess/Board.html +703 -0
  8. data/doc/Chess/CGame.html +1005 -0
  9. data/doc/Chess/Game.html +684 -0
  10. data/doc/Chess/Gnuchess.html +215 -0
  11. data/doc/Chess/IllegalMoveError.html +105 -0
  12. data/doc/Chess/InvalidFenFormatError.html +105 -0
  13. data/doc/Chess/InvalidPgnFormatError.html +105 -0
  14. data/doc/Chess/Pgn.html +309 -0
  15. data/doc/Chess/UTF8Notation.html +174 -0
  16. data/doc/README_rdoc.html +143 -0
  17. data/doc/created.rid +15 -15
  18. data/doc/css/fonts.css +167 -0
  19. data/doc/css/rdoc.css +590 -0
  20. data/doc/fonts/Lato-Light.ttf +0 -0
  21. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  22. data/doc/fonts/Lato-Regular.ttf +0 -0
  23. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  24. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  25. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  26. data/doc/images/add.png +0 -0
  27. data/doc/images/arrow_up.png +0 -0
  28. data/doc/images/brick.png +0 -0
  29. data/doc/images/brick_link.png +0 -0
  30. data/doc/images/bug.png +0 -0
  31. data/doc/images/bullet_black.png +0 -0
  32. data/doc/images/bullet_toggle_minus.png +0 -0
  33. data/doc/images/bullet_toggle_plus.png +0 -0
  34. data/doc/images/date.png +0 -0
  35. data/doc/images/delete.png +0 -0
  36. data/doc/images/find.png +0 -0
  37. data/doc/images/loadingAnimation.gif +0 -0
  38. data/doc/images/macFFBgHack.png +0 -0
  39. data/doc/images/package.png +0 -0
  40. data/doc/images/page_green.png +0 -0
  41. data/doc/images/page_white_text.png +0 -0
  42. data/doc/images/page_white_width.png +0 -0
  43. data/doc/images/plugin.png +0 -0
  44. data/doc/images/ruby.png +0 -0
  45. data/doc/images/tag_blue.png +0 -0
  46. data/doc/images/tag_green.png +0 -0
  47. data/doc/images/transparent.png +0 -0
  48. data/doc/images/wrench.png +0 -0
  49. data/doc/images/wrench_orange.png +0 -0
  50. data/doc/images/zoom.png +0 -0
  51. data/doc/index.html +159 -12
  52. data/doc/js/darkfish.js +161 -0
  53. data/doc/js/jquery.js +4 -0
  54. data/doc/js/navigation.js.gz +0 -0
  55. data/doc/js/search.js +109 -0
  56. data/doc/js/search_index.js +1 -1
  57. data/doc/js/search_index.js.gz +0 -0
  58. data/doc/js/searcher.js +1 -0
  59. data/doc/js/searcher.js.gz +0 -0
  60. data/doc/table_of_contents.html +331 -0
  61. data/ext/chess.c +5 -2
  62. data/ext/game.c +1 -1
  63. data/ext/game.h +1 -1
  64. data/lib/chess/game.rb +1 -1
  65. data/lib/chess/pgn.rb +5 -1
  66. data/lib/chess/version.rb +1 -1
  67. metadata +112 -46
  68. data/doc/apple-touch-icon.png +0 -0
  69. data/doc/classes/Chess.html +0 -162
  70. data/doc/classes/Chess/BadNotationError.html +0 -84
  71. data/doc/classes/Chess/Board.html +0 -795
  72. data/doc/classes/Chess/CGame.html +0 -1168
  73. data/doc/classes/Chess/Game.html +0 -775
  74. data/doc/classes/Chess/Gnuchess.html +0 -206
  75. data/doc/classes/Chess/IllegalMoveError.html +0 -82
  76. data/doc/classes/Chess/InvalidFenFormatError.html +0 -82
  77. data/doc/classes/Chess/InvalidPgnFormatError.html +0 -82
  78. data/doc/classes/Chess/Pgn.html +0 -332
  79. data/doc/classes/Chess/UTF8Notation.html +0 -175
  80. data/doc/css/github.css +0 -123
  81. data/doc/css/main.css +0 -323
  82. data/doc/css/panel.css +0 -384
  83. data/doc/css/reset.css +0 -48
  84. data/doc/favicon.ico +0 -0
  85. data/doc/files/README_rdoc.html +0 -122
  86. data/doc/files/ext/bitboard_c.html +0 -68
  87. data/doc/files/ext/board_c.html +0 -68
  88. data/doc/files/ext/chess_c.html +0 -68
  89. data/doc/files/ext/common_c.html +0 -68
  90. data/doc/files/ext/game_c.html +0 -68
  91. data/doc/files/ext/special_c.html +0 -68
  92. data/doc/files/lib/chess/exceptions_rb.html +0 -94
  93. data/doc/files/lib/chess/game_rb.html +0 -84
  94. data/doc/files/lib/chess/gnuchess_rb.html +0 -84
  95. data/doc/files/lib/chess/pgn_rb.html +0 -84
  96. data/doc/files/lib/chess/utf8_notation_rb.html +0 -84
  97. data/doc/files/lib/chess/version_rb.html +0 -85
  98. data/doc/files/lib/chess_rb.html +0 -84
  99. data/doc/i/arrows.png +0 -0
  100. data/doc/i/results_bg.png +0 -0
  101. data/doc/i/tree_bg.png +0 -0
  102. data/doc/js/highlight.pack.js +0 -1
  103. data/doc/js/jquery-1.3.2.min.js +0 -19
  104. data/doc/js/jquery-effect.js +0 -593
  105. data/doc/js/main.js +0 -24
  106. data/doc/js/searchdoc.js +0 -449
  107. data/doc/panel/index.html +0 -73
  108. data/doc/panel/links.html +0 -34
  109. data/doc/panel/tree.js +0 -1
@@ -0,0 +1,1005 @@
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
+ int i;
246
+ VALUE moves = rb_ary_new ();
247
+ for (i = 0; i &lt; g-&gt;current; i++)
248
+ rb_ary_push (moves, rb_str_new2 (g-&gt;coord_moves[i]));
249
+ return moves;
250
+ }</pre>
251
+ </div>
252
+
253
+ </div>
254
+
255
+
256
+
257
+
258
+ </div>
259
+
260
+
261
+ <div id="method-i-current" class="method-detail ">
262
+
263
+
264
+ <div class="method-heading">
265
+ <span class="method-callseq">
266
+ current
267
+ </span>
268
+
269
+ <span class="method-click-advice">click to toggle source</span>
270
+
271
+ </div>
272
+
273
+
274
+
275
+ <div class="method-description">
276
+
277
+ <p>Returns the current <a href="Board.html">Board</a> of the <a
278
+ href="Game.html">Game</a> (the current chess position of the game).</p>
279
+
280
+
281
+
282
+
283
+ <div class="method-source-code" id="current-source">
284
+ <pre>VALUE
285
+ game_current_board (VALUE self)
286
+ {
287
+ Game *g;
288
+ Data_Get_Struct (self, Game, g);
289
+ return game_boards (self, INT2FIX (g-&gt;current-1));
290
+ }</pre>
291
+ </div>
292
+
293
+ </div>
294
+
295
+
296
+ <div class="aliases">
297
+ Also aliased as: <a href="CGame.html#method-i-board">board</a>
298
+ </div>
299
+
300
+
301
+
302
+ </div>
303
+
304
+
305
+ <div id="method-i-draw" class="method-detail ">
306
+
307
+
308
+ <div class="method-heading">
309
+ <span class="method-callseq">
310
+ draw
311
+ </span>
312
+
313
+ <span class="method-click-advice">click to toggle source</span>
314
+
315
+ </div>
316
+
317
+
318
+
319
+ <div class="method-description">
320
+
321
+ <p>The game result is set to draw.</p>
322
+
323
+
324
+
325
+
326
+ <div class="method-source-code" id="draw-source">
327
+ <pre>VALUE
328
+ game_draw (VALUE self)
329
+ {
330
+ Game *g;
331
+ Data_Get_Struct (self, Game, g);
332
+ g-&gt;result = DRAW;
333
+ return Qnil;
334
+ }</pre>
335
+ </div>
336
+
337
+ </div>
338
+
339
+
340
+
341
+
342
+ </div>
343
+
344
+
345
+ <div id="method-i-each" class="method-detail ">
346
+
347
+
348
+ <div class="method-heading">
349
+ <span class="method-callseq">
350
+ each { |board, move, coord_move, index| block }
351
+ </span>
352
+
353
+ <span class="method-click-advice">click to toggle source</span>
354
+
355
+ </div>
356
+
357
+
358
+
359
+ <div class="method-description">
360
+
361
+ <p>Calls <code>block</code> once for each <code>board</code> in self, passing
362
+ that <code>board</code>, <code>move</code>, <code>coord_move</code> and
363
+ <code>index</code> as parameters. Return self. If no block is given, the
364
+ array of game moves is returned instead.</p>
365
+
366
+
367
+
368
+
369
+ <div class="method-source-code" id="each-source">
370
+ <pre>VALUE
371
+ game_each (VALUE self)
372
+ {
373
+ if (!rb_block_given_p ())
374
+ return game_moves(self);
375
+ int i;
376
+ Game *g;
377
+ Data_Get_Struct (self, Game, g);
378
+ for (i = 0; i &lt; g-&gt;current; i++)
379
+ rb_yield_values (4, Data_Wrap_Struct (board_klass, 0, 0, get_board (g, i)),
380
+ rb_str_new2 (g-&gt;moves[i]), 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
+ int i;
656
+ VALUE moves = rb_ary_new ();
657
+ for (i = 0; i &lt; g-&gt;current; i++)
658
+ rb_ary_push (moves, rb_str_new2 (g-&gt;moves[i]));
659
+ return moves;
660
+ }</pre>
661
+ </div>
662
+
663
+ </div>
664
+
665
+
666
+
667
+
668
+ </div>
669
+
670
+
671
+ <div id="method-i-resign" class="method-detail ">
672
+
673
+
674
+ <div class="method-heading">
675
+ <span class="method-callseq">
676
+ resign(color)
677
+ </span>
678
+
679
+ <span class="method-click-advice">click to toggle source</span>
680
+
681
+ </div>
682
+
683
+
684
+
685
+ <div class="method-description">
686
+
687
+ <p>The game result is set to &#39;1-0&#39; if <code>color</code> is “black”,
688
+ otherwise is set to &#39;0-1&#39; if color is “white”.</p>
689
+
690
+ <p>Parameters are:</p>
691
+ <dl class="rdoc-list note-list"><dt><code>color</code>
692
+ <dd>
693
+ <p>the color of the player who resigns the game; it can be <code>:white</code>
694
+ or <code>:black</code>.</p>
695
+ </dd></dl>
696
+
697
+
698
+
699
+
700
+ <div class="method-source-code" id="resign-source">
701
+ <pre>VALUE
702
+ game_resign (VALUE self, VALUE color)
703
+ {
704
+ Game *g;
705
+ Data_Get_Struct (self, Game, g);
706
+ const char *c;
707
+ if (TYPE (color) == T_SYMBOL)
708
+ c = rb_id2name (SYM2ID (color));
709
+ else
710
+ c = StringValuePtr (color);
711
+ if (strcmp (c, &quot;black&quot;) == 0)
712
+ g-&gt;result = WHITE_WON;
713
+ else if (strcmp (c, &quot;white&quot;) == 0)
714
+ g-&gt;result = BLACK_WON;
715
+ return Qnil;
716
+ }</pre>
717
+ </div>
718
+
719
+ </div>
720
+
721
+
722
+
723
+
724
+ </div>
725
+
726
+
727
+ <div id="method-i-result" class="method-detail ">
728
+
729
+
730
+ <div class="method-heading">
731
+ <span class="method-callseq">
732
+ result
733
+ </span>
734
+
735
+ <span class="method-click-advice">click to toggle source</span>
736
+
737
+ </div>
738
+
739
+
740
+
741
+ <div class="method-description">
742
+
743
+ <p>Returns the result of the game:</p>
744
+ <dl class="rdoc-list note-list"><dt>*
745
+ <dd>
746
+ <p>game in progress;</p>
747
+ </dd><dt>1-0
748
+ <dd>
749
+ <p>white won;</p>
750
+ </dd><dt>0-1
751
+ <dd>
752
+ <p>black won;</p>
753
+ </dd><dt>1/2-1/2
754
+ <dd>
755
+ <p>draw</p>
756
+ </dd></dl>
757
+
758
+
759
+
760
+
761
+ <div class="method-source-code" id="result-source">
762
+ <pre>VALUE
763
+ game_result (VALUE self)
764
+ {
765
+ Game *g;
766
+ Data_Get_Struct (self, Game, g);
767
+ char *result = result_to_s (g-&gt;result);
768
+ VALUE rb_result = rb_str_new2 (result);
769
+ free (result);
770
+ return rb_result;
771
+ }</pre>
772
+ </div>
773
+
774
+ </div>
775
+
776
+
777
+
778
+
779
+ </div>
780
+
781
+
782
+ <div id="method-i-rollback-21" class="method-detail ">
783
+
784
+
785
+ <div class="method-heading">
786
+ <span class="method-callseq">
787
+ rollback!
788
+ </span>
789
+
790
+ <span class="method-click-advice">click to toggle source</span>
791
+
792
+ </div>
793
+
794
+
795
+
796
+ <div class="method-description">
797
+
798
+ <p>Rollback last move.</p>
799
+
800
+
801
+
802
+
803
+ <div class="method-source-code" id="rollback-21-source">
804
+ <pre>VALUE
805
+ game_rollback (VALUE self)
806
+ {
807
+ Game *g;
808
+ Data_Get_Struct (self, Game, g);
809
+ rollback (g);
810
+ return self;
811
+ }</pre>
812
+ </div>
813
+
814
+ </div>
815
+
816
+
817
+
818
+
819
+ </div>
820
+
821
+
822
+ <div id="method-i-set_fen-21" class="method-detail ">
823
+
824
+
825
+ <div class="method-heading">
826
+ <span class="method-callseq">
827
+ set_fen!(fen)
828
+ </span>
829
+
830
+ <span class="method-click-advice">click to toggle source</span>
831
+
832
+ </div>
833
+
834
+
835
+
836
+ <div class="method-description">
837
+
838
+ <p>Set the game position with a FEN string.</p>
839
+
840
+ <p>Parameters are:</p>
841
+ <dl class="rdoc-list note-list"><dt><code>fen</code>
842
+ <dd>
843
+ <p>the FEN (Forsyth–Edwards Notation) string notation used to set the game
844
+ position.</p>
845
+ </dd></dl>
846
+
847
+
848
+
849
+
850
+ <div class="method-source-code" id="set_fen-21-source">
851
+ <pre>VALUE
852
+ game_set_fen (VALUE self, VALUE fen)
853
+ {
854
+ Game *g;
855
+ Data_Get_Struct (self, Game, g);
856
+ set_fen (g, StringValuePtr (fen));
857
+ return self;
858
+ }</pre>
859
+ </div>
860
+
861
+ </div>
862
+
863
+
864
+
865
+
866
+ </div>
867
+
868
+
869
+ <div id="method-i-size" class="method-detail ">
870
+
871
+
872
+ <div class="method-heading">
873
+ <span class="method-callseq">
874
+ size
875
+ </span>
876
+
877
+ <span class="method-click-advice">click to toggle source</span>
878
+
879
+ </div>
880
+
881
+
882
+
883
+ <div class="method-description">
884
+
885
+ <p>Returns the number of moves done.</p>
886
+
887
+
888
+
889
+
890
+ <div class="method-source-code" id="size-source">
891
+ <pre>VALUE
892
+ game_size (VALUE self)
893
+ {
894
+ Game *g;
895
+ Data_Get_Struct (self, Game, g);
896
+ return INT2FIX (g-&gt;current);
897
+ }</pre>
898
+ </div>
899
+
900
+ </div>
901
+
902
+
903
+
904
+
905
+ </div>
906
+
907
+
908
+ <div id="method-i-threefold_repetition-3F" class="method-detail ">
909
+
910
+
911
+ <div class="method-heading">
912
+ <span class="method-callseq">
913
+ threefold_repetition?
914
+ </span>
915
+
916
+ <span class="method-click-advice">click to toggle source</span>
917
+
918
+ </div>
919
+
920
+
921
+
922
+ <div class="method-description">
923
+
924
+ <p>Returns <code>true</code> if a player can claim draw by the threefold
925
+ repetition rule, <code>false</code> otherwise.</p>
926
+
927
+
928
+
929
+
930
+ <div class="method-source-code" id="threefold_repetition-3F-source">
931
+ <pre>VALUE
932
+ game_threefold_repetition (VALUE self)
933
+ {
934
+ Game *g;
935
+ Data_Get_Struct (self, Game, g);
936
+ if (threefold_repetition (g))
937
+ return Qtrue;
938
+ else
939
+ return Qfalse;
940
+ }</pre>
941
+ </div>
942
+
943
+ </div>
944
+
945
+
946
+
947
+
948
+ </div>
949
+
950
+
951
+ <div id="method-i-to_s" class="method-detail ">
952
+
953
+
954
+ <div class="method-heading">
955
+ <span class="method-callseq">
956
+ to_s
957
+ </span>
958
+
959
+ <span class="method-click-advice">click to toggle source</span>
960
+
961
+ </div>
962
+
963
+
964
+
965
+ <div class="method-description">
966
+
967
+ <p>Current board to string.</p>
968
+
969
+
970
+
971
+
972
+ <div class="method-source-code" id="to_s-source">
973
+ <pre>VALUE
974
+ game_to_s (VALUE self)
975
+ {
976
+ Game *g;
977
+ Data_Get_Struct (self, Game, g);
978
+ Board *b = get_board (g, g-&gt;current-1);
979
+ char *s = print_board (b);
980
+ VALUE rb_s = rb_str_new2 (s);
981
+ free (s);
982
+ return rb_s;
983
+ }</pre>
984
+ </div>
985
+
986
+ </div>
987
+
988
+
989
+
990
+
991
+ </div>
992
+
993
+
994
+ </section>
995
+
996
+ </section>
997
+ </main>
998
+
999
+
1000
+ <footer id="validator-badges" role="contentinfo">
1001
+ <p><a href="http://validator.w3.org/check/referer">Validate</a>
1002
+ <p>Generated by <a href="https://rdoc.github.io/rdoc">RDoc</a> 5.1.0.
1003
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
1004
+ </footer>
1005
+