chess 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
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/ext/board.h CHANGED
@@ -43,7 +43,7 @@ bboard* get_piece_bitboard (Board *board, char piece);
43
43
  bboard* get_bitboard (Board *board, int square);
44
44
  bboard xray (Board *board, int from, bool only_attack);
45
45
  bboard all_xray (Board *board, int color, bool only_attack);
46
- bboard all_xray_friend (Board *board, int color, bool only_attack);
46
+ bboard all_xray_without_friends (Board *board, int color, bool only_attack);
47
47
  void remove_piece (Board *board, int square, Board *new_board);
48
48
  int same_pieces_that_can_capture_a_square (Board *board, int color, int square, int *pieces, char piece_filter);
49
49
  bool capture (Board *board, int color, int square);
@@ -52,9 +52,11 @@ bool king_in_check (Board *board, int color);
52
52
  bool king_in_checkmate (Board *board, int color);
53
53
  bool stalemate (Board *board, int color);
54
54
  bool insufficient_material (Board *board);
55
+ bool only_kings (Board *board);
55
56
  bool fifty_move_rule (Board *board);
57
+ bool invalid_promotion (Board *board, int from, int to);
56
58
  bool pseudo_legal_move (Board *board, int from, int to);
57
- void get_coord (Board *board, char piece, const char* disambiguating, const char *to_coord, char promote_in, int *from, int *to);
59
+ bool get_coord (Board *board, char piece, const char* disambiguating, const char *to_coord, char promote_in, int *from, int *to);
58
60
  bool try_move (Board *board, int from, int to, char promote_in, Board *new_board, char **move_done, char *capture);
59
61
  char* get_notation (Board *board, int from, int to, int capture, int ep, char promotion, int check, int checkmate);
60
62
  char* to_fen (Board *board);
data/ext/chess.c CHANGED
@@ -26,13 +26,12 @@ game_alloc (VALUE class)
26
26
  }
27
27
 
28
28
  /*
29
- * call-seq: set_fen!(fen)
30
- *
31
- * Set the game position with a FEN string.
32
- *
33
- * Parameters are:
34
- * +fen+:: the FEN (Forsyth–Edwards Notation) string notation used to set the
35
- * game position.
29
+ * @overload set_fen!(fen)
30
+ * Set the game position by FEN string.
31
+ * @param [String] fen The FEN (Forsyth–Edwards Notation) string notation used
32
+ * to set the game position.
33
+ * @return [Game] Returns `self` with position of the pieces corresponding to
34
+ * the FEN string.
36
35
  */
37
36
  VALUE
38
37
  game_set_fen (VALUE self, VALUE fen)
@@ -44,32 +43,30 @@ game_set_fen (VALUE self, VALUE fen)
44
43
  }
45
44
 
46
45
  /*
47
- * call-seq: move(piece, disambiguating, to_coord, promote_in)
48
- *
49
- * Make a move. This add a new Board in the Game.
50
- *
51
- * Parameters are:
52
- * +piece+:: the character of the moving piece <em>('P', 'R', 'N', 'B', 'Q', 'K')</em>.
53
- * +disambiguating+:: when two (or more) identical pieces can move to the same
54
- * square, the moving piece is uniquely identified by
55
- * specifying the piece's letter, followed by (in descending
56
- * order of preference):
57
- * * the file of departure (if they differ); or
58
- * * the rank of departure (if the files are the same but
59
- * the ranks differ); or
60
- * * both the rank and file (if neither alone is
61
- * sufficient to identify the piece—which occurs only in
62
- * rare cases where one or more pawns have promoted,
63
- * resulting in a player having three or more identical
64
- * pieces able to reach the same square).
65
- * Keep blank if no needed.
66
- * +to_coord+:: the square where the moving piece will <em>('a1', 'a2', ... , 'h7', 'h8')</em>.
67
- * +promote_in+:: the character of promotion piece <em>('R', 'N', 'B', 'Q')</em>.
68
- * If no promotion occured, this param will be ignored. If no
69
- * value is passed, 'Q' is the default.
70
- *
71
- * This method returns a string that represents the short algebraic chess
72
- * notation of the move or raise an IllegalMoveError if the move is illegal.
46
+ * @overload move(piece, disambiguating, to_coord, promote_in)
47
+ * Make a move.
48
+ * @note This add a new {Board} in the {Game}.
49
+ * @param [String] piece The character of the moving piece _('P', 'R', 'N',
50
+ * 'B', 'Q', 'K')_.
51
+ * @param [String] disambiguating When two (or more) identical pieces can move
52
+ * to the same square, the moving piece is uniquely identified by specifying
53
+ * the piece's letter, followed by (in descending order of preference):
54
+ *
55
+ * * the file of departure (if they differ);
56
+ * * the rank of departure (if the files are the same but the ranks differ);
57
+ * * both the rank and file (if neither alone is sufficient to identify the
58
+ * piece—which occurs only in rare cases where one or more pawns have
59
+ * promoted, resulting in a player having three or more identical pieces
60
+ * able to reach the same square).
61
+ * Keep `nil` if no needed.
62
+ * @param [String] to_coord The square where the moving piece will _('a1',
63
+ * 'a2', ... , 'h7', 'h8')_.
64
+ * @param [String] promote_in The character of promotion piece _('R', 'N',
65
+ * 'B', 'Q')_. If not `nil` and no promotion occured raise an
66
+ * {IllegalMoveError}. If `nil`, _'Q'_ is the default.
67
+ * @return [String] Returns a string that represents the short algebraic chess
68
+ * notation of the move.
69
+ * @raise [IllegalMoveError]
73
70
  */
74
71
  VALUE
75
72
  game_move (VALUE self, VALUE rb_piece, VALUE rb_disambiguating, VALUE rb_to_coord, VALUE rb_promote_in)
@@ -78,34 +75,33 @@ game_move (VALUE self, VALUE rb_piece, VALUE rb_disambiguating, VALUE rb_to_coor
78
75
  Data_Get_Struct (self, Game, g);
79
76
  Board *board = current_board (g);
80
77
  char piece = StringValuePtr (rb_piece)[0];
81
- char *disambiguating = StringValuePtr (rb_disambiguating);
78
+ char *disambiguating = rb_disambiguating == Qnil ? NULL : StringValuePtr (rb_disambiguating);
82
79
  char *to_coord = StringValuePtr (rb_to_coord);
83
- char promote_in = StringValuePtr (rb_promote_in)[0];
80
+ char promote_in = rb_promote_in == Qnil ? '\0' : StringValuePtr (rb_promote_in)[0];
84
81
  int from, to;
85
- get_coord (board, piece, disambiguating, to_coord, promote_in, &from, &to);
86
- // printf ("From: %d, To: %d, Promo: %c\n", from , to , promote_in);
87
- if (pseudo_legal_move (board, from, to) && apply_move (g, from, to, promote_in))
82
+ if (
83
+ get_coord (board, piece, disambiguating, to_coord, promote_in, &from, &to) &&
84
+ apply_move (g, from, to, promote_in)
85
+ )
88
86
  return rb_str_new2 (current_move (g));
89
87
  else
90
88
  rb_raise (illegal_move_error, "Illegal move");
91
89
  }
92
90
 
93
91
  /*
94
- * call-seq: move2(from, to, promote_in)
95
- *
96
- * Make a move. This add a new Board in the Game.
97
- *
98
- * Parameters are:
99
- * +from+:: the 2 character string representing the starting square of the
100
- * moving piece <em>('a1', 'a2', ... , 'h7', 'h8')</em>.
101
- * +to+:: the 2 character string representing the ending square of the moving
102
- * piece <em>('a1', 'a2', ... , 'h7', 'h8')</em>.
103
- * +promote_in+:: the character of promotion piece <em>('R', 'N', 'B', 'Q')</em>.
104
- * If no promotion occured, this param will be ignored. If no
105
- * value is passed, 'Q' is the default.
106
- *
107
- * This method returns a string that represents the short algebraic chess
108
- * notation of the move or raise an IllegalMoveError if the move is illegal.
92
+ * @overload move2(from, to, promote_in)
93
+ * Make a move.
94
+ * @note This add a new {Board} in the {Game}.
95
+ * @param [String] from The 2 character string representing the starting
96
+ * square of the moving piece _('a1', 'a2', ... , 'h7', 'h8')_.
97
+ * @param [String] to The 2 character string representing the ending square of
98
+ * the moving piece _('a1', 'a2', ... , 'h7', 'h8')_.
99
+ * @param [String] promote_in The character of promotion piece _('R', 'N',
100
+ * 'B', 'Q')_. If not `nil` and no promotion occured raise an
101
+ * {IllegalMoveError}. If `nil`, _'Q'_ is the default.
102
+ * @return [String] Returns a string that represents the short algebraic chess
103
+ * notation of the move.
104
+ * @raise [IllegalMoveError]
109
105
  */
110
106
  VALUE
111
107
  game_move2 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
@@ -115,7 +111,7 @@ game_move2 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
115
111
  Board *board = current_board (g);
116
112
  int from = coord_to_square (StringValuePtr (rb_from));
117
113
  int to = coord_to_square (StringValuePtr (rb_to));
118
- char promote_in = StringValuePtr (rb_promote_in)[0];
114
+ char promote_in = rb_promote_in == Qnil ? '\0' : StringValuePtr (rb_promote_in)[0];
119
115
  if (pseudo_legal_move (board, from, to) && apply_move (g, from, to, promote_in))
120
116
  return rb_str_new2 (current_move (g));
121
117
  else
@@ -123,32 +119,33 @@ game_move2 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
123
119
  }
124
120
 
125
121
  /*
126
- * call-seq: move3(from, to, promote_in)
127
- *
128
- * Make a move. This add a new Board in the Game.
129
- *
130
- * Each square on the chessboard is represented by an integer according to the
131
- * following scheme:
132
- * 8 | 56 57 58 59 60 61 62 63
133
- * 7 | 48 49 50 51 52 53 54 55
134
- * 6 | 40 41 42 43 44 45 46 47
135
- * 5 | 32 33 34 35 36 37 38 39
136
- * 4 | 24 25 26 27 28 29 30 31
137
- * 3 | 16 17 18 19 20 21 22 23
138
- * 2 | 8 9 10 11 12 13 14 15
139
- * 1 | 0 1 2 3 4 5 6 7
140
- * +-------------------------
141
- * a b c d e f g h
142
- *
143
- * Parameters are:
144
- * +from+:: the integer representing the starting square of the moving piece.
145
- * +to+:: the integer representing the ending square of the moving piece.
146
- * +promote_in+:: the character of promotion piece <em>('R', 'N', 'B', 'Q')</em>.
147
- * If no promotion occured, this param will be ignored. If no
148
- * value is passed, 'Q' is the default.
149
- *
150
- * This method returns a string that represents the short algebraic chess
151
- * notation of the move or raise an IllegalMoveError if the move is illegal.
122
+ * @overload move3(from, to, promote_in)
123
+ * Make a move.
124
+ * Each square on the chessboard is represented by an integer according to the
125
+ * following scheme:
126
+ *
127
+ * 8 | 56 57 58 59 60 61 62 63
128
+ * 7 | 48 49 50 51 52 53 54 55
129
+ * 6 | 40 41 42 43 44 45 46 47
130
+ * 5 | 32 33 34 35 36 37 38 39
131
+ * 4 | 24 25 26 27 28 29 30 31
132
+ * 3 | 16 17 18 19 20 21 22 23
133
+ * 2 | 8 9 10 11 12 13 14 15
134
+ * 1 | 0 1 2 3 4 5 6 7
135
+ * +-------------------------
136
+ * a b c d e f g h
137
+ *
138
+ * @note This add a new {Board} in the {Game}.
139
+ * @param [Integer] from The integer representing the starting square of the
140
+ * moving piece.
141
+ * @param [Integer] to The integer representing the ending square of the
142
+ * moving piece.
143
+ * @param [String] promote_in The character of promotion piece _('R', 'N',
144
+ * 'B', 'Q')_. If not `nil` and no promotion occured raise an
145
+ * {IllegalMoveError}. If `nil`, _'Q'_ is the default.
146
+ * @return [String] Returns a string that represents the short algebraic chess
147
+ * notation of the move.
148
+ * @raise [IllegalMoveError]
152
149
  */
153
150
  VALUE
154
151
  game_move3 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
@@ -158,7 +155,7 @@ game_move3 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
158
155
  Board *board = current_board (g);
159
156
  int from = FIX2INT (rb_from);
160
157
  int to = FIX2INT (rb_to);
161
- char promote_in = StringValuePtr (rb_promote_in)[0];
158
+ char promote_in = rb_promote_in == Qnil ? '\0' : StringValuePtr (rb_promote_in)[0];
162
159
  if (pseudo_legal_move (board, from, to) && apply_move (g, from, to, promote_in))
163
160
  return rb_str_new2 (current_move (g));
164
161
  else
@@ -166,14 +163,12 @@ game_move3 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
166
163
  }
167
164
 
168
165
  /*
169
- * call-seq: resign(color)
170
- *
171
- * The game result is set to '1-0' if +color+ is "black", otherwise is set to
172
- * '0-1' if color is "white".
173
- *
174
- * Parameters are:
175
- * +color+:: the color of the player who resigns the game; it can be +:white+ or
176
- * +:black+.
166
+ * @overload resign(color)
167
+ * The game result is set to '1-0' if `color` is _black_, otherwise is set to
168
+ * '0-1' if color is _white_.
169
+ * @param [String,Symbol] color The color of the player who resigns the game;
170
+ * it can be `:white` or `:black`.
171
+ * @return [nil]
177
172
  */
178
173
  VALUE
179
174
  game_resign (VALUE self, VALUE color)
@@ -193,9 +188,9 @@ game_resign (VALUE self, VALUE color)
193
188
  }
194
189
 
195
190
  /*
196
- * call-seq: draw
197
- *
198
- * The game result is set to draw.
191
+ * @overload draw
192
+ * The game result is set to draw.
193
+ * @return [nil]
199
194
  */
200
195
  VALUE
201
196
  game_draw (VALUE self)
@@ -207,10 +202,10 @@ game_draw (VALUE self)
207
202
  }
208
203
 
209
204
  /*
210
- * call-seq: [n]
211
- *
212
- * Returns the +n+-th Board of the Game or +nil+ if the +n+-th Board does not
213
- * exist.
205
+ * @overload [](n)
206
+ * Returns the `n`-th {Board} of the {Game} or `nil` if the `n`-th {Board}
207
+ * does not exist.
208
+ * @return [Board]
214
209
  */
215
210
  VALUE
216
211
  game_boards (VALUE self, VALUE index)
@@ -225,10 +220,10 @@ game_boards (VALUE self, VALUE index)
225
220
  }
226
221
 
227
222
  /*
228
- * call-seq: current
229
- *
230
- * Returns the current Board of the Game (the current chess position of the
231
- * game).
223
+ * @overload current
224
+ * Returns the current {Board} of the {Game} (the current chess position of
225
+ * the game).
226
+ * @return [Board]
232
227
  */
233
228
  VALUE
234
229
  game_current_board (VALUE self)
@@ -239,9 +234,9 @@ game_current_board (VALUE self)
239
234
  }
240
235
 
241
236
  /*
242
- * call-seq: moves
243
- *
244
- * Returns the array with all moves done <em>(es: Nc3)</em>.
237
+ * @overload moves
238
+ * Returns the array with all moves done _(es: Nc3)_.
239
+ * @return [Array<String>]
245
240
  */
246
241
  VALUE
247
242
  game_moves (VALUE self)
@@ -255,9 +250,10 @@ game_moves (VALUE self)
255
250
  }
256
251
 
257
252
  /*
258
- * call-seq: coord_moves
259
- *
260
- * Returns the array with all moves done in coordinate chess notation <em>(es: b1c3)</em>.
253
+ * @overload coord_moves
254
+ * Returns the array with all moves done in coordinate chess notation _(es:
255
+ * b1c3)_.
256
+ * @return [Array<String>]
261
257
  */
262
258
  VALUE
263
259
  game_coord_moves (VALUE self)
@@ -271,7 +267,8 @@ game_coord_moves (VALUE self)
271
267
  }
272
268
 
273
269
  /*
274
- * :nodoc:
270
+ * @overload full_moves
271
+ * @deprecated Use {#coord_moves} instead.
275
272
  */
276
273
  VALUE
277
274
  game_full_moves (VALUE self)
@@ -281,10 +278,9 @@ game_full_moves (VALUE self)
281
278
  }
282
279
 
283
280
  /*
284
- * call-seq: threefold_repetition?
285
- *
286
- * Returns +true+ if a player can claim draw by the threefold repetition rule,
287
- * +false+ otherwise.
281
+ * @overload threefold_repetition?
282
+ * Returns `true` if a player can claim draw by the threefold repetition rule,
283
+ * `false` otherwise.
288
284
  */
289
285
  VALUE
290
286
  game_threefold_repetition (VALUE self)
@@ -298,13 +294,14 @@ game_threefold_repetition (VALUE self)
298
294
  }
299
295
 
300
296
  /*
301
- * call-seq: result
302
- *
303
- * Returns the result of the game:
304
- * *:: game in progress;
305
- * 1-0:: white won;
306
- * 0-1:: black won;
307
- * 1/2-1/2:: draw
297
+ * @overload result
298
+ * Returns the result of the game.
299
+ * @return [String] Returns the result of the game:
300
+ *
301
+ * * `*`: game in progress;
302
+ * * `1-0`: white won;
303
+ * * `0-1`: black won;
304
+ * * `1/2-1/2`: draw.
308
305
  */
309
306
  VALUE
310
307
  game_result (VALUE self)
@@ -318,9 +315,9 @@ game_result (VALUE self)
318
315
  }
319
316
 
320
317
  /*
321
- * call-seq: size
322
- *
323
- * Returns the number of moves done.
318
+ * @overload size
319
+ * Returns the number of moves done.
320
+ * @return [Integer]
324
321
  */
325
322
  VALUE
326
323
  game_size (VALUE self)
@@ -331,11 +328,13 @@ game_size (VALUE self)
331
328
  }
332
329
 
333
330
  /*
334
- * call-seq: each { |board, move, coord_move, index| block }
335
- *
336
- * Calls +block+ once for each +board+ in self, passing that
337
- * +board+, +move+, +coord_move+ and +index+ as parameters. Return self.
338
- * If no block is given, the array of game moves is returned instead.
331
+ * @overload each
332
+ * Cycle the {Game}.
333
+ * @yield [board, move, coord_move, index]
334
+ * Calls `block` once for each {Board} in `self`, passing that
335
+ * `board`, `move`, `coord_move` and `index` as parameters.
336
+ * @return [Game] Returns `self` if a block is given.
337
+ * @return [Array<String>] Returns the array of game moves if no block is given.
339
338
  */
340
339
  VALUE
341
340
  game_each (VALUE self)
@@ -354,9 +353,9 @@ game_each (VALUE self)
354
353
  }
355
354
 
356
355
  /*
357
- * call-seq: rollback!
358
- *
359
- * Rollback last move.
356
+ * @overload rollback!
357
+ * Rollback last move.
358
+ * @return [Game] Returns `self` with last move cancelled.
360
359
  */
361
360
  VALUE
362
361
  game_rollback (VALUE self)
@@ -368,9 +367,9 @@ game_rollback (VALUE self)
368
367
  }
369
368
 
370
369
  /*
371
- * call-seq: to_s
372
- *
373
- * Current board to string.
370
+ * @overload to_s
371
+ * Current {Board} to string.
372
+ * @return [String]
374
373
  */
375
374
  VALUE
376
375
  game_to_s (VALUE self)
@@ -387,11 +386,13 @@ game_to_s (VALUE self)
387
386
  // Board
388
387
 
389
388
  /*
390
- * call-seq: placement { |piece, index| block }
391
- *
392
- * Calls +block+ once for each square in the board, passing the
393
- * +piece+ in the square and the +index+ as parameters. Return self.
394
- * If no block is given, the array of pieces is returned instead.
389
+ * @overload placement
390
+ * Cycle the {Board} squares.
391
+ * @yield [piece, index]
392
+ * Calls `block` once for each square in the {Board}, passing the `piece` in
393
+ * the square and the `index` as parameters.
394
+ * @return [Board] Returns `self` if a block is given.
395
+ * @return [Array<String>] Returns the array of pieces if no block is given.
395
396
  */
396
397
  VALUE
397
398
  board_placement (VALUE self)
@@ -420,27 +421,27 @@ board_placement (VALUE self)
420
421
  }
421
422
 
422
423
  /*
423
- * call-seq: [square]
424
- *
425
- * Returns the piece on the +square+ of the chessboard. If there is no piece or
426
- * the square is not valid return +nil+.
427
- *
428
- * Each square on the chessboard is represented by an integer according to the
429
- * following scheme:
430
- * 8 | 56 57 58 59 60 61 62 63
431
- * 7 | 48 49 50 51 52 53 54 55
432
- * 6 | 40 41 42 43 44 45 46 47
433
- * 5 | 32 33 34 35 36 37 38 39
434
- * 4 | 24 25 26 27 28 29 30 31
435
- * 3 | 16 17 18 19 20 21 22 23
436
- * 2 | 8 9 10 11 12 13 14 15
437
- * 1 | 0 1 2 3 4 5 6 7
438
- * +-------------------------
439
- * a b c d e f g h
440
- *
441
- * Parameters are:
442
- * +square+:: the square of the board. Can be an integer between 0 and 63 or a
443
- * string like 'a2', 'c5'...
424
+ * @overload [](square)
425
+ * Returns the piece on the `square` of the chessboard. If there is no piece
426
+ * or the square is not valid return `nil`.
427
+ * Each square on the chessboard is represented by an integer according to the
428
+ * following scheme:
429
+ *
430
+ * 8 | 56 57 58 59 60 61 62 63
431
+ * 7 | 48 49 50 51 52 53 54 55
432
+ * 6 | 40 41 42 43 44 45 46 47
433
+ * 5 | 32 33 34 35 36 37 38 39
434
+ * 4 | 24 25 26 27 28 29 30 31
435
+ * 3 | 16 17 18 19 20 21 22 23
436
+ * 2 | 8 9 10 11 12 13 14 15
437
+ * 1 | 0 1 2 3 4 5 6 7
438
+ * +-------------------------
439
+ * a b c d e f g h
440
+ *
441
+ * @param [Integer,String] square The square of the {Board}. Can be an integer
442
+ * between 0 and 63 or a string like 'a2', 'c5'...
443
+ * @return [String] The symbol that identify the piece _('P', 'R', 'N', 'B',
444
+ * 'Q', 'K')_. Upcase for a white piece, downcase for a black piece.
444
445
  */
445
446
  VALUE
446
447
  board_get_piece (VALUE self, VALUE square)
@@ -460,10 +461,9 @@ board_get_piece (VALUE self, VALUE square)
460
461
  }
461
462
 
462
463
  /*
463
- * call-seq: check?
464
- *
465
- * Returns +true+ if the king of the color that has the turn is in check,
466
- * +false+ otherwise.
464
+ * @overload check?
465
+ * Returns `true` if the king of the color that has the turn is in check,
466
+ * `false` otherwise.
467
467
  */
468
468
  VALUE
469
469
  board_king_in_check (VALUE self)
@@ -477,10 +477,9 @@ board_king_in_check (VALUE self)
477
477
  }
478
478
 
479
479
  /*
480
- * call-seq: checkmate?
481
- *
482
- * Returns +true+ if the king of the color that has the turn is in checkmate,
483
- * +false+ otherwise.
480
+ * @overload checkmate?
481
+ * Returns `true` if the king of the color that has the turn is in checkmate,
482
+ * `false` otherwise.
484
483
  */
485
484
  VALUE
486
485
  board_king_in_checkmate (VALUE self)
@@ -494,10 +493,9 @@ board_king_in_checkmate (VALUE self)
494
493
  }
495
494
 
496
495
  /*
497
- * call-seq: stalemate?
498
- *
499
- * Returns +true+ if the pieces of the color that has the turn are in stalemate,
500
- * +false+ otherwise.
496
+ * @overload stalemate?
497
+ * Returns `true` if the pieces of the color that has the turn are in
498
+ * stalemate, `false` otherwise.
501
499
  */
502
500
  VALUE
503
501
  board_stalemate (VALUE self)
@@ -511,10 +509,9 @@ board_stalemate (VALUE self)
511
509
  }
512
510
 
513
511
  /*
514
- * call-seq: insufficient_material?
515
- *
516
- * Returns +true+ if the board has insufficient material to checkmate, +false+
517
- * otherwise.
512
+ * @overload insufficient_material?
513
+ * Returns `true` if the board has insufficient material to checkmate, `false`
514
+ * otherwise.
518
515
  */
519
516
  VALUE
520
517
  board_insufficient_material (VALUE self)
@@ -528,10 +525,25 @@ board_insufficient_material (VALUE self)
528
525
  }
529
526
 
530
527
  /*
531
- * call-seq: fifty_move_rule?
532
- *
533
- * Returns +true+ if a player can claim draw by the fifty-move rule, +false+
534
- * otherwise.
528
+ * @overload only_kings?
529
+ * Returns `true` if on the board there are only the two kings, `false`
530
+ * otherwise.
531
+ */
532
+ VALUE
533
+ board_only_kings (VALUE self)
534
+ {
535
+ Board *board;
536
+ Data_Get_Struct (self, Board, board);
537
+ if (only_kings (board))
538
+ return Qtrue;
539
+ else
540
+ return Qfalse;
541
+ }
542
+
543
+ /*
544
+ * @overload fifty_move_rule?
545
+ * Returns `true` if a player can claim draw by the fifty-move rule, `false`
546
+ * otherwise.
535
547
  */
536
548
  VALUE
537
549
  board_fifty_move_rule (VALUE self)
@@ -545,9 +557,10 @@ board_fifty_move_rule (VALUE self)
545
557
  }
546
558
 
547
559
  /*
548
- * call-seq: active_color
549
- *
550
- * Returns the active color: +false+ means white turn, +true+ means black turn.
560
+ * @overload active_color
561
+ * Returns the active color: `false` means white turn, `true` means black
562
+ * turn.
563
+ * @return [Boolean]
551
564
  */
552
565
  VALUE
553
566
  board_active_color (VALUE self)
@@ -561,11 +574,11 @@ board_active_color (VALUE self)
561
574
  }
562
575
 
563
576
  /*
564
- * call-seq: halfmove_clock
565
- *
566
- * Returns the halfmove clock that is the number of halfmoves since the last
567
- * pawn advance or capture. This is used to determine if a draw can be claimed
568
- * under the fifty-move rule.
577
+ * @overload halfmove_clock
578
+ * Returns the halfmove clock that is the number of halfmoves since the last
579
+ * pawn advance or capture. This is used to determine if a draw can be claimed
580
+ * under the fifty-move rule.
581
+ * @return [Integer]
569
582
  */
570
583
  VALUE
571
584
  board_halfmove_clock (VALUE self)
@@ -576,10 +589,10 @@ board_halfmove_clock (VALUE self)
576
589
  }
577
590
 
578
591
  /*
579
- * call-seq: fullmove_number
580
- *
581
- * Returns the fullmove number: the number of the full move. It starts at 1, and
582
- * is incremented after black's move.
592
+ * @overload fullmove_number
593
+ * Returns the fullmove number: the number of the full move. It starts at 1,
594
+ * and * is incremented after black's move.
595
+ * @return [Integer]
583
596
  */
584
597
  VALUE
585
598
  board_fullmove_number (VALUE self)
@@ -590,9 +603,9 @@ board_fullmove_number (VALUE self)
590
603
  }
591
604
 
592
605
  /*
593
- * call-seq: to_fen
594
- *
595
- * Return the FEN string of the board.
606
+ * @overload to_fen
607
+ * Returns the FEN string of the board.
608
+ * @return [String]
596
609
  */
597
610
  VALUE
598
611
  board_to_fen (VALUE self)
@@ -606,9 +619,9 @@ board_to_fen (VALUE self)
606
619
  }
607
620
 
608
621
  /*
609
- * call-seq: to_s
610
- *
611
- * Board to string.
622
+ * @overload to_s
623
+ * {Board} to string.
624
+ * @return [String]
612
625
  */
613
626
  VALUE
614
627
  board_to_s (VALUE self)
@@ -630,6 +643,8 @@ Init_chess ()
630
643
  VALUE chess = rb_define_module ("Chess");
631
644
 
632
645
  /*
646
+ * Document-class: Chess::CGame
647
+ *
633
648
  * This class rappresents a collection of boards of a single chess game.
634
649
  */
635
650
  VALUE game = rb_define_class_under (chess, "CGame", rb_cObject);
@@ -654,6 +669,8 @@ Init_chess ()
654
669
  rb_define_alias (game, "board", "current");
655
670
 
656
671
  /*
672
+ * Document-class: Chess::Board
673
+ *
657
674
  * This class rappresents a chess board.
658
675
  * The rappresentation of the board use _bitboards_ where each bit represents
659
676
  * a game position or state, designed for optimization of speed and/or memory
@@ -667,6 +684,7 @@ Init_chess ()
667
684
  rb_define_method (board_klass, "checkmate?", board_king_in_checkmate, 0);
668
685
  rb_define_method (board_klass, "stalemate?", board_stalemate, 0);
669
686
  rb_define_method (board_klass, "insufficient_material?", board_insufficient_material, 0);
687
+ rb_define_method (board_klass, "only_kings?", board_only_kings, 0);
670
688
  rb_define_method (board_klass, "fifty_rule_move?", board_fifty_move_rule, 0);
671
689
  rb_define_method (board_klass, "active_color", board_active_color, 0);
672
690
  rb_define_method (board_klass, "halfmove_clock", board_halfmove_clock, 0);
@@ -675,6 +693,8 @@ Init_chess ()
675
693
  rb_define_method (board_klass, "to_s", board_to_s, 0);
676
694
 
677
695
  /*
696
+ * Document-class: Chess::IllegalMoveError
697
+ *
678
698
  * This exception will be raised when making an illegal move.
679
699
  */
680
700
  illegal_move_error = rb_define_class_under (chess, "IllegalMoveError", rb_eStandardError);