chess 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +44 -0
- data/Rakefile +6 -7
- data/chess.gemspec +1 -1
- data/ext/bitboard.c +24 -0
- data/ext/board.c +78 -24
- data/ext/board.h +4 -2
- data/ext/chess.c +216 -196
- data/ext/chess.h +1 -0
- data/ext/common.c +10 -0
- data/ext/game.c +33 -16
- data/ext/special.c +14 -11
- data/ext/special.h +1 -2
- data/lib/chess/exceptions.rb +7 -10
- data/lib/chess/game.rb +66 -50
- data/lib/chess/gnuchess.rb +19 -25
- data/lib/chess/pgn.rb +49 -9
- data/lib/chess/utf8_notation.rb +11 -9
- data/lib/chess/version.rb +1 -1
- data/test/pgn_collection/illegal/0001.pgn +18 -0
- data/test/pgn_collection/illegal/0002.pgn +17 -0
- data/test/pgn_collection/illegal/0003.pgn +13 -0
- data/test/pgn_collection/illegal/0004.pgn +15 -0
- data/test/pgn_collection/illegal/0005.pgn +16 -0
- data/test/pgn_collection/invalid/0001.pgn +20 -0
- data/test/pgn_collection/invalid/0002.pgn +16 -0
- data/test/pgn_collection/invalid/0003.pgn +13 -0
- data/test/pgn_collection/invalid/0004.pgn +15 -0
- data/test/pgn_collection/valid/0001.pgn +6 -7
- data/test/pgn_collection/valid/0002.pgn +8 -9
- data/test/pgn_collection/valid/0005.pgn +7 -8
- data/test/pgn_collection/valid/0009.pgn +14 -15
- data/test/pgn_collection/valid/0010.pgn +6 -7
- data/test/pgn_collection/valid/0011.pgn +5 -6
- data/test/pgn_collection/valid/0012.pgn +0 -1
- data/test/pgn_collection/valid/0013.pgn +5 -6
- data/test/pgn_collection/valid/0014.pgn +6 -7
- data/test/pgn_collection/valid/0020.pgn +6 -7
- data/test/pgn_collection/valid/0021.pgn +15 -16
- data/test/pgn_collection/valid/0971.pgn +22 -14
- data/test/test_big_pgn_collection.rb +12 -5
- data/test/test_helper.rb +1 -1
- data/test/test_illegal_moves.rb +14 -0
- data/test/test_insufficient_material.rb +13 -1
- data/test/test_particular_situations.rb +14 -0
- data/test/test_pgn.rb +24 -0
- data/test/test_pgn_collection.rb +1 -4
- metadata +30 -63
- data/README.rdoc +0 -44
- data/doc/Chess.html +0 -112
- data/doc/Chess/BadNotationError.html +0 -107
- data/doc/Chess/Board.html +0 -700
- data/doc/Chess/CGame.html +0 -1004
- data/doc/Chess/Game.html +0 -684
- data/doc/Chess/Gnuchess.html +0 -215
- data/doc/Chess/IllegalMoveError.html +0 -105
- data/doc/Chess/InvalidFenFormatError.html +0 -105
- data/doc/Chess/InvalidPgnFormatError.html +0 -105
- data/doc/Chess/Pgn.html +0 -309
- data/doc/Chess/UTF8Notation.html +0 -174
- data/doc/README_rdoc.html +0 -143
- data/doc/created.rid +0 -15
- data/doc/css/fonts.css +0 -167
- data/doc/css/rdoc.css +0 -590
- data/doc/fonts/Lato-Light.ttf +0 -0
- data/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/doc/fonts/Lato-Regular.ttf +0 -0
- data/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -160
- data/doc/js/darkfish.js +0 -161
- data/doc/js/jquery.js +0 -4
- data/doc/js/navigation.js +0 -142
- data/doc/js/navigation.js.gz +0 -0
- data/doc/js/search.js +0 -109
- data/doc/js/search_index.js +0 -1
- data/doc/js/search_index.js.gz +0 -0
- data/doc/js/searcher.js +0 -229
- data/doc/js/searcher.js.gz +0 -0
- 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
|
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
|
-
|
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
|
-
*
|
30
|
-
*
|
31
|
-
*
|
32
|
-
*
|
33
|
-
*
|
34
|
-
*
|
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
|
-
*
|
48
|
-
*
|
49
|
-
*
|
50
|
-
*
|
51
|
-
*
|
52
|
-
*
|
53
|
-
*
|
54
|
-
*
|
55
|
-
*
|
56
|
-
*
|
57
|
-
*
|
58
|
-
*
|
59
|
-
*
|
60
|
-
*
|
61
|
-
*
|
62
|
-
*
|
63
|
-
*
|
64
|
-
*
|
65
|
-
*
|
66
|
-
*
|
67
|
-
*
|
68
|
-
*
|
69
|
-
*
|
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
|
-
|
86
|
-
|
87
|
-
|
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
|
-
*
|
95
|
-
*
|
96
|
-
*
|
97
|
-
*
|
98
|
-
*
|
99
|
-
*
|
100
|
-
*
|
101
|
-
*
|
102
|
-
*
|
103
|
-
*
|
104
|
-
*
|
105
|
-
*
|
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
|
-
*
|
127
|
-
*
|
128
|
-
*
|
129
|
-
*
|
130
|
-
*
|
131
|
-
*
|
132
|
-
*
|
133
|
-
*
|
134
|
-
*
|
135
|
-
*
|
136
|
-
*
|
137
|
-
*
|
138
|
-
*
|
139
|
-
*
|
140
|
-
*
|
141
|
-
*
|
142
|
-
*
|
143
|
-
*
|
144
|
-
*
|
145
|
-
*
|
146
|
-
*
|
147
|
-
*
|
148
|
-
*
|
149
|
-
*
|
150
|
-
*
|
151
|
-
*
|
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
|
-
*
|
170
|
-
*
|
171
|
-
*
|
172
|
-
*
|
173
|
-
*
|
174
|
-
*
|
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
|
-
*
|
197
|
-
*
|
198
|
-
*
|
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
|
-
*
|
211
|
-
*
|
212
|
-
*
|
213
|
-
*
|
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
|
-
*
|
229
|
-
*
|
230
|
-
*
|
231
|
-
*
|
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
|
-
*
|
243
|
-
*
|
244
|
-
*
|
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
|
-
*
|
259
|
-
*
|
260
|
-
*
|
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
|
-
*
|
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
|
-
*
|
285
|
-
*
|
286
|
-
*
|
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
|
-
*
|
302
|
-
*
|
303
|
-
* Returns the result of the game:
|
304
|
-
*
|
305
|
-
*
|
306
|
-
* 0
|
307
|
-
*
|
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
|
-
*
|
322
|
-
*
|
323
|
-
*
|
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
|
-
*
|
335
|
-
*
|
336
|
-
*
|
337
|
-
*
|
338
|
-
*
|
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
|
-
*
|
358
|
-
*
|
359
|
-
*
|
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
|
-
*
|
372
|
-
*
|
373
|
-
*
|
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
|
-
*
|
391
|
-
*
|
392
|
-
*
|
393
|
-
*
|
394
|
-
*
|
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
|
-
*
|
424
|
-
*
|
425
|
-
*
|
426
|
-
* the
|
427
|
-
*
|
428
|
-
*
|
429
|
-
*
|
430
|
-
*
|
431
|
-
*
|
432
|
-
*
|
433
|
-
*
|
434
|
-
*
|
435
|
-
*
|
436
|
-
*
|
437
|
-
*
|
438
|
-
*
|
439
|
-
*
|
440
|
-
*
|
441
|
-
*
|
442
|
-
*
|
443
|
-
*
|
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
|
-
*
|
464
|
-
*
|
465
|
-
*
|
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
|
-
*
|
481
|
-
*
|
482
|
-
*
|
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
|
-
*
|
498
|
-
*
|
499
|
-
*
|
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
|
-
*
|
515
|
-
*
|
516
|
-
*
|
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
|
-
*
|
532
|
-
*
|
533
|
-
*
|
534
|
-
|
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
|
-
*
|
549
|
-
*
|
550
|
-
*
|
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
|
-
*
|
565
|
-
*
|
566
|
-
*
|
567
|
-
*
|
568
|
-
*
|
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
|
-
*
|
580
|
-
*
|
581
|
-
*
|
582
|
-
*
|
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
|
-
*
|
594
|
-
*
|
595
|
-
*
|
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
|
-
*
|
610
|
-
*
|
611
|
-
*
|
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);
|