chess 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/Rakefile +1 -0
  4. data/doc/apple-touch-icon.png +0 -0
  5. data/doc/classes/Chess.html +162 -0
  6. data/doc/classes/Chess/BadNotationError.html +84 -0
  7. data/doc/classes/Chess/Board.html +795 -0
  8. data/doc/classes/Chess/CGame.html +1168 -0
  9. data/doc/classes/Chess/Game.html +775 -0
  10. data/doc/classes/Chess/Gnuchess.html +206 -0
  11. data/doc/classes/Chess/IllegalMoveError.html +82 -0
  12. data/doc/classes/Chess/InvalidFenFormatError.html +82 -0
  13. data/doc/classes/Chess/InvalidPgnFormatError.html +82 -0
  14. data/doc/classes/Chess/Pgn.html +332 -0
  15. data/doc/classes/Chess/UTF8Notation.html +175 -0
  16. data/doc/created.rid +15 -0
  17. data/doc/css/github.css +123 -0
  18. data/doc/css/main.css +323 -0
  19. data/doc/css/panel.css +384 -0
  20. data/doc/css/reset.css +48 -0
  21. data/doc/favicon.ico +0 -0
  22. data/doc/files/README_rdoc.html +122 -0
  23. data/doc/files/ext/bitboard_c.html +68 -0
  24. data/doc/files/ext/board_c.html +68 -0
  25. data/doc/files/ext/chess_c.html +68 -0
  26. data/doc/files/ext/common_c.html +68 -0
  27. data/doc/files/ext/game_c.html +68 -0
  28. data/doc/files/ext/special_c.html +68 -0
  29. data/doc/files/lib/chess/exceptions_rb.html +94 -0
  30. data/doc/files/lib/chess/game_rb.html +84 -0
  31. data/doc/files/lib/chess/gnuchess_rb.html +84 -0
  32. data/doc/files/lib/chess/pgn_rb.html +84 -0
  33. data/doc/files/lib/chess/utf8_notation_rb.html +84 -0
  34. data/doc/files/lib/chess/version_rb.html +85 -0
  35. data/doc/files/lib/chess_rb.html +84 -0
  36. data/doc/i/arrows.png +0 -0
  37. data/doc/i/results_bg.png +0 -0
  38. data/doc/i/tree_bg.png +0 -0
  39. data/doc/index.html +13 -0
  40. data/doc/js/highlight.pack.js +1 -0
  41. data/doc/js/jquery-1.3.2.min.js +19 -0
  42. data/doc/js/jquery-effect.js +593 -0
  43. data/doc/js/main.js +24 -0
  44. data/doc/js/navigation.js +142 -0
  45. data/doc/js/search_index.js +1 -0
  46. data/doc/js/searchdoc.js +449 -0
  47. data/doc/js/searcher.js +228 -0
  48. data/doc/panel/index.html +73 -0
  49. data/doc/panel/links.html +34 -0
  50. data/doc/panel/tree.js +1 -0
  51. data/ext/chess.c +82 -33
  52. data/ext/chess.h +1 -1
  53. data/ext/common.c +1 -1
  54. data/ext/common.h +1 -1
  55. data/ext/game.c +7 -6
  56. data/ext/game.h +1 -1
  57. data/lib/chess/exceptions.rb +2 -1
  58. data/lib/chess/game.rb +18 -5
  59. data/lib/chess/gnuchess.rb +1 -1
  60. data/lib/chess/utf8_notation.rb +1 -0
  61. data/lib/chess/version.rb +1 -1
  62. metadata +50 -3
@@ -0,0 +1,1168 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <title>Chess::CGame</title>
7
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
8
+ <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
9
+ <link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
10
+ <link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
11
+ <script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
12
+ <script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
13
+ <script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
14
+ <script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
15
+
16
+ </head>
17
+
18
+ <body>
19
+ <div class="banner">
20
+
21
+ <h1>
22
+ <span class="type">Class</span>
23
+ Chess::CGame
24
+
25
+ <span class="parent">&lt;
26
+
27
+ Object
28
+
29
+ </span>
30
+
31
+ </h1>
32
+ <ul class="files">
33
+
34
+ <li><a href="../../files/ext/chess_c.html">ext/chess.c</a></li>
35
+
36
+ </ul>
37
+ </div>
38
+ <div id="bodyContent">
39
+ <div id="content">
40
+
41
+ <div class="description">
42
+
43
+ <p>This class rappresents a collection of boards of a single chess game.</p>
44
+
45
+ </div>
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+ <!-- Method ref -->
61
+ <div class="sectiontitle">Methods</div>
62
+ <dl class="methods">
63
+
64
+ <dt>#</dt>
65
+ <dd>
66
+ <ul>
67
+
68
+
69
+ <li>
70
+ <a href="#method-i-5B-5D">[]</a>
71
+ </li>
72
+
73
+ </ul>
74
+ </dd>
75
+
76
+ <dt>B</dt>
77
+ <dd>
78
+ <ul>
79
+
80
+
81
+ <li>
82
+ <a href="#method-i-board">board</a>
83
+ </li>
84
+
85
+ </ul>
86
+ </dd>
87
+
88
+ <dt>C</dt>
89
+ <dd>
90
+ <ul>
91
+
92
+
93
+ <li>
94
+ <a href="#method-i-coord_moves">coord_moves</a>,
95
+ </li>
96
+
97
+
98
+ <li>
99
+ <a href="#method-i-current">current</a>
100
+ </li>
101
+
102
+ </ul>
103
+ </dd>
104
+
105
+ <dt>D</dt>
106
+ <dd>
107
+ <ul>
108
+
109
+
110
+ <li>
111
+ <a href="#method-i-draw">draw</a>
112
+ </li>
113
+
114
+ </ul>
115
+ </dd>
116
+
117
+ <dt>E</dt>
118
+ <dd>
119
+ <ul>
120
+
121
+
122
+ <li>
123
+ <a href="#method-i-each">each</a>
124
+ </li>
125
+
126
+ </ul>
127
+ </dd>
128
+
129
+ <dt>F</dt>
130
+ <dd>
131
+ <ul>
132
+
133
+
134
+ <li>
135
+ <a href="#method-i-full_moves">full_moves</a>
136
+ </li>
137
+
138
+ </ul>
139
+ </dd>
140
+
141
+ <dt>M</dt>
142
+ <dd>
143
+ <ul>
144
+
145
+
146
+ <li>
147
+ <a href="#method-i-move">move</a>,
148
+ </li>
149
+
150
+
151
+ <li>
152
+ <a href="#method-i-move2">move2</a>,
153
+ </li>
154
+
155
+
156
+ <li>
157
+ <a href="#method-i-move3">move3</a>,
158
+ </li>
159
+
160
+
161
+ <li>
162
+ <a href="#method-i-moves">moves</a>
163
+ </li>
164
+
165
+ </ul>
166
+ </dd>
167
+
168
+ <dt>R</dt>
169
+ <dd>
170
+ <ul>
171
+
172
+
173
+ <li>
174
+ <a href="#method-i-resign">resign</a>,
175
+ </li>
176
+
177
+
178
+ <li>
179
+ <a href="#method-i-result">result</a>,
180
+ </li>
181
+
182
+
183
+ <li>
184
+ <a href="#method-i-rollback-21">rollback!</a>
185
+ </li>
186
+
187
+ </ul>
188
+ </dd>
189
+
190
+ <dt>S</dt>
191
+ <dd>
192
+ <ul>
193
+
194
+
195
+ <li>
196
+ <a href="#method-i-set_fen-21">set_fen!</a>,
197
+ </li>
198
+
199
+
200
+ <li>
201
+ <a href="#method-i-size">size</a>
202
+ </li>
203
+
204
+ </ul>
205
+ </dd>
206
+
207
+ <dt>T</dt>
208
+ <dd>
209
+ <ul>
210
+
211
+
212
+ <li>
213
+ <a href="#method-i-threefold_repetition-3F">threefold_repetition?</a>,
214
+ </li>
215
+
216
+
217
+ <li>
218
+ <a href="#method-i-to_s">to_s</a>
219
+ </li>
220
+
221
+ </ul>
222
+ </dd>
223
+
224
+ </dl>
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+ <!-- Methods -->
244
+
245
+ <div class="sectiontitle">Instance Public methods</div>
246
+
247
+ <div class="method">
248
+ <div class="title method-title" id="method-i-5B-5D">
249
+
250
+ <b>[n]
251
+ </b>
252
+
253
+ <a href="../../classes/Chess/CGame.html#method-i-5B-5D" name="method-i-5B-5D" class="permalink">Link</a>
254
+ </div>
255
+
256
+
257
+ <div class="description">
258
+ <p>Returns the <code>n</code>-th <a href="Board.html">Board</a> of the <a
259
+ href="Game.html">Game</a> or <code>nil</code> if the <code>n</code>-th <a
260
+ href="Board.html">Board</a> does not exist.</p>
261
+ </div>
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+ <div class="sourcecode">
271
+
272
+ <p class="source-link">
273
+ Source:
274
+ <a href="javascript:toggleSource('method-i-5B-5D_source')" id="l_method-i-5B-5D_source">show</a>
275
+
276
+ </p>
277
+ <div id="method-i-5B-5D_source" class="dyn-source">
278
+ <pre>VALUE
279
+ game_boards (VALUE self, VALUE index)
280
+ {
281
+ Game *g;
282
+ Data_Get_Struct (self, Game, g);
283
+ int n = FIX2INT (index);
284
+ Board *board = get_board (g, n);
285
+ if (board)
286
+ return Data_Wrap_Struct (board_klass, 0, 0, board);
287
+ return Qnil;
288
+ }</pre>
289
+ </div>
290
+ </div>
291
+
292
+ </div>
293
+
294
+ <div class="method">
295
+ <div class="title method-title" id="method-i-board">
296
+
297
+ <b>board</b>()
298
+
299
+ <a href="../../classes/Chess/CGame.html#method-i-board" name="method-i-board" class="permalink">Link</a>
300
+ </div>
301
+
302
+
303
+ <div class="description">
304
+
305
+ </div>
306
+
307
+
308
+
309
+
310
+
311
+ <div class="aka">
312
+ Alias for: <a href="CGame.html#method-i-current">current</a>
313
+ </div>
314
+
315
+
316
+
317
+ </div>
318
+
319
+ <div class="method">
320
+ <div class="title method-title" id="method-i-coord_moves">
321
+
322
+ <b>coord_moves
323
+ </b>
324
+
325
+ <a href="../../classes/Chess/CGame.html#method-i-coord_moves" name="method-i-coord_moves" class="permalink">Link</a>
326
+ </div>
327
+
328
+
329
+ <div class="description">
330
+ <p>Returns the array with all moves done in coordinate chess notation <em>(es:
331
+ b1c3)</em>.</p>
332
+ </div>
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+ <div class="sourcecode">
342
+
343
+ <p class="source-link">
344
+ Source:
345
+ <a href="javascript:toggleSource('method-i-coord_moves_source')" id="l_method-i-coord_moves_source">show</a>
346
+
347
+ </p>
348
+ <div id="method-i-coord_moves_source" class="dyn-source">
349
+ <pre>VALUE
350
+ game_coord_moves (VALUE self)
351
+ {
352
+ Game *g;
353
+ Data_Get_Struct (self, Game, g);
354
+ int i;
355
+ VALUE moves = rb_ary_new ();
356
+ for (i = 0; i &lt; g-&gt;current; i++)
357
+ rb_ary_push (moves, rb_str_new2 (g-&gt;coord_moves[i]));
358
+ return moves;
359
+ }</pre>
360
+ </div>
361
+ </div>
362
+
363
+ </div>
364
+
365
+ <div class="method">
366
+ <div class="title method-title" id="method-i-current">
367
+
368
+ <b>current
369
+ </b>
370
+
371
+ <a href="../../classes/Chess/CGame.html#method-i-current" name="method-i-current" class="permalink">Link</a>
372
+ </div>
373
+
374
+
375
+ <div class="description">
376
+ <p>Returns the current <a href="Board.html">Board</a> of the <a
377
+ href="Game.html">Game</a> (the current chess position of the game).</p>
378
+ </div>
379
+
380
+
381
+
382
+ <div class="aka">
383
+ Also aliased as: <a href="CGame.html#method-i-board">board</a>
384
+ </div>
385
+
386
+
387
+
388
+
389
+
390
+
391
+ <div class="sourcecode">
392
+
393
+ <p class="source-link">
394
+ Source:
395
+ <a href="javascript:toggleSource('method-i-current_source')" id="l_method-i-current_source">show</a>
396
+
397
+ </p>
398
+ <div id="method-i-current_source" class="dyn-source">
399
+ <pre>VALUE
400
+ game_current_board (VALUE self)
401
+ {
402
+ Game *g;
403
+ Data_Get_Struct (self, Game, g);
404
+ return game_boards (self, INT2FIX (g-&gt;current-1));
405
+ }</pre>
406
+ </div>
407
+ </div>
408
+
409
+ </div>
410
+
411
+ <div class="method">
412
+ <div class="title method-title" id="method-i-draw">
413
+
414
+ <b>draw
415
+ </b>
416
+
417
+ <a href="../../classes/Chess/CGame.html#method-i-draw" name="method-i-draw" class="permalink">Link</a>
418
+ </div>
419
+
420
+
421
+ <div class="description">
422
+ <p>The game result is set to draw.</p>
423
+ </div>
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+ <div class="sourcecode">
433
+
434
+ <p class="source-link">
435
+ Source:
436
+ <a href="javascript:toggleSource('method-i-draw_source')" id="l_method-i-draw_source">show</a>
437
+
438
+ </p>
439
+ <div id="method-i-draw_source" class="dyn-source">
440
+ <pre>VALUE
441
+ game_draw (VALUE self)
442
+ {
443
+ Game *g;
444
+ Data_Get_Struct (self, Game, g);
445
+ g-&gt;result = DRAW;
446
+ return Qnil;
447
+ }</pre>
448
+ </div>
449
+ </div>
450
+
451
+ </div>
452
+
453
+ <div class="method">
454
+ <div class="title method-title" id="method-i-each">
455
+
456
+ <b>each { |board, move, full_move, index| block }
457
+ </b>
458
+
459
+ <a href="../../classes/Chess/CGame.html#method-i-each" name="method-i-each" class="permalink">Link</a>
460
+ </div>
461
+
462
+
463
+ <div class="description">
464
+ <p>Calls <code>block</code> once for each <code>board</code> in self, passing
465
+ that <code>board</code>, <code>move</code>, <code>full_move</code> and
466
+ <code>index</code> as parameters. Return self. If no block is given, the
467
+ array of game moves is returned instead.</p>
468
+ </div>
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+ <div class="sourcecode">
478
+
479
+ <p class="source-link">
480
+ Source:
481
+ <a href="javascript:toggleSource('method-i-each_source')" id="l_method-i-each_source">show</a>
482
+
483
+ </p>
484
+ <div id="method-i-each_source" class="dyn-source">
485
+ <pre>VALUE
486
+ game_each (VALUE self)
487
+ {
488
+ if (!rb_block_given_p ())
489
+ return game_moves(self);
490
+ int i;
491
+ Game *g;
492
+ Data_Get_Struct (self, Game, g);
493
+ for (i = 0; i &lt; g-&gt;current; i++)
494
+ rb_yield_values (4, Data_Wrap_Struct (board_klass, 0, 0, get_board (g, i)),
495
+ rb_str_new2 (g-&gt;moves[i]), rb_str_new2 (g-&gt;coord_moves[i]),
496
+ INT2FIX (i));
497
+ return self;
498
+ }</pre>
499
+ </div>
500
+ </div>
501
+
502
+ </div>
503
+
504
+ <div class="method">
505
+ <div class="title method-title" id="method-i-full_moves">
506
+
507
+ <b>full_moves</b>()
508
+
509
+ <a href="../../classes/Chess/CGame.html#method-i-full_moves" name="method-i-full_moves" class="permalink">Link</a>
510
+ </div>
511
+
512
+
513
+ <div class="description">
514
+
515
+ </div>
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+ <div class="sourcecode">
525
+
526
+ <p class="source-link">
527
+ Source:
528
+ <a href="javascript:toggleSource('method-i-full_moves_source')" id="l_method-i-full_moves_source">show</a>
529
+
530
+ </p>
531
+ <div id="method-i-full_moves_source" class="dyn-source">
532
+ <pre>VALUE
533
+ game_full_moves (VALUE self)
534
+ {
535
+ 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;);
536
+ return game_coord_moves (self);
537
+ }</pre>
538
+ </div>
539
+ </div>
540
+
541
+ </div>
542
+
543
+ <div class="method">
544
+ <div class="title method-title" id="method-i-move">
545
+
546
+ <b>move(piece, disambiguating, to_coord, promote_in)
547
+ </b>
548
+
549
+ <a href="../../classes/Chess/CGame.html#method-i-move" name="method-i-move" class="permalink">Link</a>
550
+ </div>
551
+
552
+
553
+ <div class="description">
554
+ <p>Make a move. This add a new <a href="Board.html">Board</a> in the <a
555
+ href="Game.html">Game</a>.</p>
556
+
557
+ <p>Parameters are:</p>
558
+ <dl class="rdoc-list note-list"><dt>piece
559
+ <dd>
560
+ <p>the character of the moving piece <em>(&#39;P&#39;, &#39;R&#39;,
561
+ &#39;N&#39;, &#39;B&#39;, &#39;Q&#39;, &#39;K&#39;)</em>.</p>
562
+ </dd><dt><code>disambiguating</code>
563
+ <dd>
564
+ <p>when two (or more) identical pieces can move to the same square, the moving
565
+ piece is uniquely identified by specifying the piece&#39;s letter, followed
566
+ by (in descending order of preference):</p>
567
+ <ul><li>
568
+ <p>the file of departure (if they differ); or</p>
569
+ </li><li>
570
+ <p>the rank of departure (if the files are the same but the ranks differ); or</p>
571
+ </li><li>
572
+ <p>both the rank and file (if neither alone is sufficient to identify the
573
+ piece—which occurs only in rare cases where one or more pawns have
574
+ promoted, resulting in a player having three or more identical pieces able
575
+ to reach the same square).</p>
576
+ </li></ul>
577
+
578
+ <p>Keep blank if no needed.</p>
579
+ </dd><dt><code>to_coord</code>
580
+ <dd>
581
+ <p>the square where the moving piece will <em>(&#39;a1&#39;, &#39;a2&#39;, … ,
582
+ &#39;h7&#39;, &#39;h8&#39;)</em>.</p>
583
+ </dd><dt><code>promote_in</code>
584
+ <dd>
585
+ <p>the character of promotion piece <em>(&#39;R&#39;, &#39;N&#39;,
586
+ &#39;B&#39;, &#39;Q&#39;)</em>. If no promotion occured, this param will be
587
+ ignored. If no value is passed, &#39;Q&#39; is the default.</p>
588
+ </dd></dl>
589
+
590
+ <p>This method returns a string that represents the short algebraic chess
591
+ notation of the move or raise an <a
592
+ href="IllegalMoveError.html">IllegalMoveError</a> if the move is illegal.</p>
593
+ </div>
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+
602
+ <div class="sourcecode">
603
+
604
+ <p class="source-link">
605
+ Source:
606
+ <a href="javascript:toggleSource('method-i-move_source')" id="l_method-i-move_source">show</a>
607
+
608
+ </p>
609
+ <div id="method-i-move_source" class="dyn-source">
610
+ <pre>VALUE
611
+ game_move (VALUE self, VALUE rb_piece, VALUE rb_disambiguating, VALUE rb_to_coord, VALUE rb_promote_in)
612
+ {
613
+ Game *g;
614
+ Data_Get_Struct (self, Game, g);
615
+ Board *board = current_board (g);
616
+ char piece = StringValuePtr (rb_piece)[0];
617
+ char *disambiguating = StringValuePtr (rb_disambiguating);
618
+ char *to_coord = StringValuePtr (rb_to_coord);
619
+ char promote_in = StringValuePtr (rb_promote_in)[0];
620
+ int from, to;
621
+ get_coord (board, piece, disambiguating, to_coord, promote_in, &amp;from, &amp;to);
622
+ // printf (&quot;From: %d, To: %d, Promo: %c\n&quot;, from , to , promote_in);
623
+ if (pseudo_legal_move (board, from, to) &amp;&amp; apply_move (g, from, to, promote_in))
624
+ return rb_str_new2 (current_move (g));
625
+ else
626
+ rb_raise (illegal_move_error, &quot;Illegal move&quot;);
627
+ }</pre>
628
+ </div>
629
+ </div>
630
+
631
+ </div>
632
+
633
+ <div class="method">
634
+ <div class="title method-title" id="method-i-move2">
635
+
636
+ <b>move2(from, to, promote_in)
637
+ </b>
638
+
639
+ <a href="../../classes/Chess/CGame.html#method-i-move2" name="method-i-move2" class="permalink">Link</a>
640
+ </div>
641
+
642
+
643
+ <div class="description">
644
+ <p>Make a move. This add a new <a href="Board.html">Board</a> in the <a
645
+ href="Game.html">Game</a>.</p>
646
+
647
+ <p>Parameters are:</p>
648
+ <dl class="rdoc-list note-list"><dt>from
649
+ <dd>
650
+ <p>the 2 character string representing the starting square of the moving piece
651
+ <em>(&#39;a1&#39;, &#39;a2&#39;, … , &#39;h7&#39;, &#39;h8&#39;)</em>.</p>
652
+ </dd><dt><code>to</code>
653
+ <dd>
654
+ <p>the 2 character string representing the ending square of the moving piece
655
+ <em>(&#39;a1&#39;, &#39;a2&#39;, … , &#39;h7&#39;, &#39;h8&#39;)</em>.</p>
656
+ </dd><dt><code>promote_in</code>
657
+ <dd>
658
+ <p>the character of promotion piece <em>(&#39;R&#39;, &#39;N&#39;,
659
+ &#39;B&#39;, &#39;Q&#39;)</em>. If no promotion occured, this param will be
660
+ ignored. If no value is passed, &#39;Q&#39; is the default.</p>
661
+ </dd></dl>
662
+
663
+ <p>This method returns a string that represents the short algebraic chess
664
+ notation of the move or raise an <a
665
+ href="IllegalMoveError.html">IllegalMoveError</a> if the move is illegal.</p>
666
+ </div>
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+ <div class="sourcecode">
676
+
677
+ <p class="source-link">
678
+ Source:
679
+ <a href="javascript:toggleSource('method-i-move2_source')" id="l_method-i-move2_source">show</a>
680
+
681
+ </p>
682
+ <div id="method-i-move2_source" class="dyn-source">
683
+ <pre>VALUE
684
+ game_move2 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
685
+ {
686
+ Game *g;
687
+ Data_Get_Struct (self, Game, g);
688
+ Board *board = current_board (g);
689
+ int from = coord_to_square (StringValuePtr (rb_from));
690
+ int to = coord_to_square (StringValuePtr (rb_to));
691
+ char promote_in = StringValuePtr (rb_promote_in)[0];
692
+ if (pseudo_legal_move (board, from, to) &amp;&amp; apply_move (g, from, to, promote_in))
693
+ return rb_str_new2 (current_move (g));
694
+ else
695
+ rb_raise (illegal_move_error, &quot;Illegal move&quot;);
696
+ }</pre>
697
+ </div>
698
+ </div>
699
+
700
+ </div>
701
+
702
+ <div class="method">
703
+ <div class="title method-title" id="method-i-move3">
704
+
705
+ <b>move3(from, to, promote_in)
706
+ </b>
707
+
708
+ <a href="../../classes/Chess/CGame.html#method-i-move3" name="method-i-move3" class="permalink">Link</a>
709
+ </div>
710
+
711
+
712
+ <div class="description">
713
+ <p>Make a move. This add a new <a href="Board.html">Board</a> in the <a
714
+ href="Game.html">Game</a>.</p>
715
+
716
+ <p>Each square on the chessboard is represented by an integer according to the
717
+ following scheme:</p>
718
+
719
+ <pre><code>8 | 56 57 58 59 60 61 62 63
720
+ 7 | 48 49 50 51 52 53 54 55
721
+ 6 | 40 41 42 43 44 45 46 47
722
+ 5 | 32 33 34 35 36 37 38 39
723
+ 4 | 24 25 26 27 28 29 30 31
724
+ 3 | 16 17 18 19 20 21 22 23
725
+ 2 | 8 9 10 11 12 13 14 15
726
+ 1 | 0 1 2 3 4 5 6 7
727
+ +-------------------------
728
+ a b c d e f g h</code></pre>
729
+
730
+ <p>Parameters are:</p>
731
+ <dl class="rdoc-list note-list"><dt><code>from</code>
732
+ <dd>
733
+ <p>the integer representing the starting square of the moving piece.</p>
734
+ </dd><dt><code>to</code>
735
+ <dd>
736
+ <p>the integer representing the ending square of the moving piece.</p>
737
+ </dd><dt><code>promote_in</code>
738
+ <dd>
739
+ <p>the character of promotion piece <em>(&#39;R&#39;, &#39;N&#39;,
740
+ &#39;B&#39;, &#39;Q&#39;)</em>. If no promotion occured, this param will be
741
+ ignored. If no value is passed, &#39;Q&#39; is the default.</p>
742
+ </dd></dl>
743
+
744
+ <p>This method returns a string that represents the short algebraic chess
745
+ notation of the move or raise an <a
746
+ href="IllegalMoveError.html">IllegalMoveError</a> if the move is illegal.</p>
747
+ </div>
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+ <div class="sourcecode">
757
+
758
+ <p class="source-link">
759
+ Source:
760
+ <a href="javascript:toggleSource('method-i-move3_source')" id="l_method-i-move3_source">show</a>
761
+
762
+ </p>
763
+ <div id="method-i-move3_source" class="dyn-source">
764
+ <pre>VALUE
765
+ game_move3 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
766
+ {
767
+ Game *g;
768
+ Data_Get_Struct (self, Game, g);
769
+ Board *board = current_board (g);
770
+ int from = FIX2INT (rb_from);
771
+ int to = FIX2INT (rb_to);
772
+ char promote_in = StringValuePtr (rb_promote_in)[0];
773
+ if (pseudo_legal_move (board, from, to) &amp;&amp; apply_move (g, from, to, promote_in))
774
+ return rb_str_new2 (current_move (g));
775
+ else
776
+ rb_raise (illegal_move_error, &quot;Illegal move&quot;);
777
+ }</pre>
778
+ </div>
779
+ </div>
780
+
781
+ </div>
782
+
783
+ <div class="method">
784
+ <div class="title method-title" id="method-i-moves">
785
+
786
+ <b>moves
787
+ </b>
788
+
789
+ <a href="../../classes/Chess/CGame.html#method-i-moves" name="method-i-moves" class="permalink">Link</a>
790
+ </div>
791
+
792
+
793
+ <div class="description">
794
+ <p>Returns the array with all moves done <em>(es: Nc3)</em>.</p>
795
+ </div>
796
+
797
+
798
+
799
+
800
+
801
+
802
+
803
+
804
+ <div class="sourcecode">
805
+
806
+ <p class="source-link">
807
+ Source:
808
+ <a href="javascript:toggleSource('method-i-moves_source')" id="l_method-i-moves_source">show</a>
809
+
810
+ </p>
811
+ <div id="method-i-moves_source" class="dyn-source">
812
+ <pre>VALUE
813
+ game_moves (VALUE self)
814
+ {
815
+ Game *g;
816
+ Data_Get_Struct (self, Game, g);
817
+ int i;
818
+ VALUE moves = rb_ary_new ();
819
+ for (i = 0; i &lt; g-&gt;current; i++)
820
+ rb_ary_push (moves, rb_str_new2 (g-&gt;moves[i]));
821
+ return moves;
822
+ }</pre>
823
+ </div>
824
+ </div>
825
+
826
+ </div>
827
+
828
+ <div class="method">
829
+ <div class="title method-title" id="method-i-resign">
830
+
831
+ <b>resign(color)
832
+ </b>
833
+
834
+ <a href="../../classes/Chess/CGame.html#method-i-resign" name="method-i-resign" class="permalink">Link</a>
835
+ </div>
836
+
837
+
838
+ <div class="description">
839
+ <p>The game result is set to &#39;1-0&#39; if <code>color</code> is “black”,
840
+ otherwise is set to &#39;0-1&#39; if color is “white”.</p>
841
+
842
+ <p>Parameters are:</p>
843
+ <dl class="rdoc-list note-list"><dt><code>color</code>
844
+ <dd>
845
+ <p>the color of the player who resigns the game; it can be <code>:white</code>
846
+ or <code>:black</code>.</p>
847
+ </dd></dl>
848
+ </div>
849
+
850
+
851
+
852
+
853
+
854
+
855
+
856
+
857
+ <div class="sourcecode">
858
+
859
+ <p class="source-link">
860
+ Source:
861
+ <a href="javascript:toggleSource('method-i-resign_source')" id="l_method-i-resign_source">show</a>
862
+
863
+ </p>
864
+ <div id="method-i-resign_source" class="dyn-source">
865
+ <pre>VALUE
866
+ game_resign (VALUE self, VALUE color)
867
+ {
868
+ Game *g;
869
+ Data_Get_Struct (self, Game, g);
870
+ const char *c;
871
+ if (TYPE (color) == T_SYMBOL)
872
+ c = rb_id2name (SYM2ID (color));
873
+ else
874
+ c = StringValuePtr (color);
875
+ if (strcmp (c, &quot;black&quot;) == 0)
876
+ g-&gt;result = WHITE_WON;
877
+ else if (strcmp (c, &quot;white&quot;) == 0)
878
+ g-&gt;result = BLACK_WON;
879
+ return Qnil;
880
+ }</pre>
881
+ </div>
882
+ </div>
883
+
884
+ </div>
885
+
886
+ <div class="method">
887
+ <div class="title method-title" id="method-i-result">
888
+
889
+ <b>result
890
+ </b>
891
+
892
+ <a href="../../classes/Chess/CGame.html#method-i-result" name="method-i-result" class="permalink">Link</a>
893
+ </div>
894
+
895
+
896
+ <div class="description">
897
+ <p>Returns the result of the game:</p>
898
+ <dl class="rdoc-list note-list"><dt>*
899
+ <dd>
900
+ <p>game in progress;</p>
901
+ </dd><dt>1-0
902
+ <dd>
903
+ <p>white won;</p>
904
+ </dd><dt>0-1
905
+ <dd>
906
+ <p>black won;</p>
907
+ </dd><dt>1/2-1/2
908
+ <dd>
909
+ <p>draw</p>
910
+ </dd></dl>
911
+ </div>
912
+
913
+
914
+
915
+
916
+
917
+
918
+
919
+
920
+ <div class="sourcecode">
921
+
922
+ <p class="source-link">
923
+ Source:
924
+ <a href="javascript:toggleSource('method-i-result_source')" id="l_method-i-result_source">show</a>
925
+
926
+ </p>
927
+ <div id="method-i-result_source" class="dyn-source">
928
+ <pre>VALUE
929
+ game_result (VALUE self)
930
+ {
931
+ Game *g;
932
+ Data_Get_Struct (self, Game, g);
933
+ char *result = result_to_s (g-&gt;result);
934
+ VALUE rb_result = rb_str_new2 (result);
935
+ free (result);
936
+ return rb_result;
937
+ }</pre>
938
+ </div>
939
+ </div>
940
+
941
+ </div>
942
+
943
+ <div class="method">
944
+ <div class="title method-title" id="method-i-rollback-21">
945
+
946
+ <b>rollback!
947
+ </b>
948
+
949
+ <a href="../../classes/Chess/CGame.html#method-i-rollback-21" name="method-i-rollback-21" class="permalink">Link</a>
950
+ </div>
951
+
952
+
953
+ <div class="description">
954
+ <p>Rollback last move.</p>
955
+ </div>
956
+
957
+
958
+
959
+
960
+
961
+
962
+
963
+
964
+ <div class="sourcecode">
965
+
966
+ <p class="source-link">
967
+ Source:
968
+ <a href="javascript:toggleSource('method-i-rollback-21_source')" id="l_method-i-rollback-21_source">show</a>
969
+
970
+ </p>
971
+ <div id="method-i-rollback-21_source" class="dyn-source">
972
+ <pre>VALUE
973
+ game_rollback (VALUE self)
974
+ {
975
+ Game *g;
976
+ Data_Get_Struct (self, Game, g);
977
+ rollback (g);
978
+ return self;
979
+ }</pre>
980
+ </div>
981
+ </div>
982
+
983
+ </div>
984
+
985
+ <div class="method">
986
+ <div class="title method-title" id="method-i-set_fen-21">
987
+
988
+ <b>set_fen!(fen)
989
+ </b>
990
+
991
+ <a href="../../classes/Chess/CGame.html#method-i-set_fen-21" name="method-i-set_fen-21" class="permalink">Link</a>
992
+ </div>
993
+
994
+
995
+ <div class="description">
996
+ <p>Set the game position with a FEN string.</p>
997
+
998
+ <p>Parameters are:</p>
999
+ <dl class="rdoc-list note-list"><dt>fen
1000
+ <dd>
1001
+ <p>the FEN (Forsyth–Edwards Notation) string notation used to set the game
1002
+ position.</p>
1003
+ </dd></dl>
1004
+ </div>
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+ <div class="sourcecode">
1014
+
1015
+ <p class="source-link">
1016
+ Source:
1017
+ <a href="javascript:toggleSource('method-i-set_fen-21_source')" id="l_method-i-set_fen-21_source">show</a>
1018
+
1019
+ </p>
1020
+ <div id="method-i-set_fen-21_source" class="dyn-source">
1021
+ <pre>VALUE
1022
+ game_set_fen (VALUE self, VALUE fen)
1023
+ {
1024
+ Game *g;
1025
+ Data_Get_Struct (self, Game, g);
1026
+ set_fen (g, StringValuePtr (fen));
1027
+ return self;
1028
+ }</pre>
1029
+ </div>
1030
+ </div>
1031
+
1032
+ </div>
1033
+
1034
+ <div class="method">
1035
+ <div class="title method-title" id="method-i-size">
1036
+
1037
+ <b>size
1038
+ </b>
1039
+
1040
+ <a href="../../classes/Chess/CGame.html#method-i-size" name="method-i-size" class="permalink">Link</a>
1041
+ </div>
1042
+
1043
+
1044
+ <div class="description">
1045
+ <p>Returns the number of moves done.</p>
1046
+ </div>
1047
+
1048
+
1049
+
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+ <div class="sourcecode">
1056
+
1057
+ <p class="source-link">
1058
+ Source:
1059
+ <a href="javascript:toggleSource('method-i-size_source')" id="l_method-i-size_source">show</a>
1060
+
1061
+ </p>
1062
+ <div id="method-i-size_source" class="dyn-source">
1063
+ <pre>VALUE
1064
+ game_size (VALUE self)
1065
+ {
1066
+ Game *g;
1067
+ Data_Get_Struct (self, Game, g);
1068
+ return INT2FIX (g-&gt;current);
1069
+ }</pre>
1070
+ </div>
1071
+ </div>
1072
+
1073
+ </div>
1074
+
1075
+ <div class="method">
1076
+ <div class="title method-title" id="method-i-threefold_repetition-3F">
1077
+
1078
+ <b>threefold_repetition?
1079
+ </b>
1080
+
1081
+ <a href="../../classes/Chess/CGame.html#method-i-threefold_repetition-3F" name="method-i-threefold_repetition-3F" class="permalink">Link</a>
1082
+ </div>
1083
+
1084
+
1085
+ <div class="description">
1086
+ <p>Returns <code>true</code> if a player can claim draw by the threefold
1087
+ repetition rule, <code>false</code> otherwise.</p>
1088
+ </div>
1089
+
1090
+
1091
+
1092
+
1093
+
1094
+
1095
+
1096
+
1097
+ <div class="sourcecode">
1098
+
1099
+ <p class="source-link">
1100
+ Source:
1101
+ <a href="javascript:toggleSource('method-i-threefold_repetition-3F_source')" id="l_method-i-threefold_repetition-3F_source">show</a>
1102
+
1103
+ </p>
1104
+ <div id="method-i-threefold_repetition-3F_source" class="dyn-source">
1105
+ <pre>VALUE
1106
+ game_threefold_repetition (VALUE self)
1107
+ {
1108
+ Game *g;
1109
+ Data_Get_Struct (self, Game, g);
1110
+ if (threefold_repetition (g))
1111
+ return Qtrue;
1112
+ else
1113
+ return Qfalse;
1114
+ }</pre>
1115
+ </div>
1116
+ </div>
1117
+
1118
+ </div>
1119
+
1120
+ <div class="method">
1121
+ <div class="title method-title" id="method-i-to_s">
1122
+
1123
+ <b>to_s
1124
+ </b>
1125
+
1126
+ <a href="../../classes/Chess/CGame.html#method-i-to_s" name="method-i-to_s" class="permalink">Link</a>
1127
+ </div>
1128
+
1129
+
1130
+ <div class="description">
1131
+ <p>Current board to string.</p>
1132
+ </div>
1133
+
1134
+
1135
+
1136
+
1137
+
1138
+
1139
+
1140
+
1141
+ <div class="sourcecode">
1142
+
1143
+ <p class="source-link">
1144
+ Source:
1145
+ <a href="javascript:toggleSource('method-i-to_s_source')" id="l_method-i-to_s_source">show</a>
1146
+
1147
+ </p>
1148
+ <div id="method-i-to_s_source" class="dyn-source">
1149
+ <pre>VALUE
1150
+ game_to_s (VALUE self)
1151
+ {
1152
+ Game *g;
1153
+ Data_Get_Struct (self, Game, g);
1154
+ Board *b = get_board (g, g-&gt;current-1);
1155
+ char *s = print_board (b);
1156
+ VALUE rb_s = rb_str_new2 (s);
1157
+ free (s);
1158
+ return rb_s;
1159
+ }</pre>
1160
+ </div>
1161
+ </div>
1162
+
1163
+ </div>
1164
+ </div>
1165
+
1166
+ </div>
1167
+ </body>
1168
+ </html>