chess 0.0.9 → 0.1.0
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 +0 -1
- data/Rakefile +1 -0
- data/doc/apple-touch-icon.png +0 -0
- data/doc/classes/Chess.html +162 -0
- data/doc/classes/Chess/BadNotationError.html +84 -0
- data/doc/classes/Chess/Board.html +795 -0
- data/doc/classes/Chess/CGame.html +1168 -0
- data/doc/classes/Chess/Game.html +775 -0
- data/doc/classes/Chess/Gnuchess.html +206 -0
- data/doc/classes/Chess/IllegalMoveError.html +82 -0
- data/doc/classes/Chess/InvalidFenFormatError.html +82 -0
- data/doc/classes/Chess/InvalidPgnFormatError.html +82 -0
- data/doc/classes/Chess/Pgn.html +332 -0
- data/doc/classes/Chess/UTF8Notation.html +175 -0
- data/doc/created.rid +15 -0
- data/doc/css/github.css +123 -0
- data/doc/css/main.css +323 -0
- data/doc/css/panel.css +384 -0
- data/doc/css/reset.css +48 -0
- data/doc/favicon.ico +0 -0
- data/doc/files/README_rdoc.html +122 -0
- data/doc/files/ext/bitboard_c.html +68 -0
- data/doc/files/ext/board_c.html +68 -0
- data/doc/files/ext/chess_c.html +68 -0
- data/doc/files/ext/common_c.html +68 -0
- data/doc/files/ext/game_c.html +68 -0
- data/doc/files/ext/special_c.html +68 -0
- data/doc/files/lib/chess/exceptions_rb.html +94 -0
- data/doc/files/lib/chess/game_rb.html +84 -0
- data/doc/files/lib/chess/gnuchess_rb.html +84 -0
- data/doc/files/lib/chess/pgn_rb.html +84 -0
- data/doc/files/lib/chess/utf8_notation_rb.html +84 -0
- data/doc/files/lib/chess/version_rb.html +85 -0
- data/doc/files/lib/chess_rb.html +84 -0
- data/doc/i/arrows.png +0 -0
- data/doc/i/results_bg.png +0 -0
- data/doc/i/tree_bg.png +0 -0
- data/doc/index.html +13 -0
- data/doc/js/highlight.pack.js +1 -0
- data/doc/js/jquery-1.3.2.min.js +19 -0
- data/doc/js/jquery-effect.js +593 -0
- data/doc/js/main.js +24 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searchdoc.js +449 -0
- data/doc/js/searcher.js +228 -0
- data/doc/panel/index.html +73 -0
- data/doc/panel/links.html +34 -0
- data/doc/panel/tree.js +1 -0
- data/ext/chess.c +82 -33
- data/ext/chess.h +1 -1
- data/ext/common.c +1 -1
- data/ext/common.h +1 -1
- data/ext/game.c +7 -6
- data/ext/game.h +1 -1
- data/lib/chess/exceptions.rb +2 -1
- data/lib/chess/game.rb +18 -5
- data/lib/chess/gnuchess.rb +1 -1
- data/lib/chess/utf8_notation.rb +1 -0
- data/lib/chess/version.rb +1 -1
- metadata +50 -3
data/doc/js/searcher.js
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
Searcher = function(data) {
|
2
|
+
this.data = data;
|
3
|
+
this.handlers = [];
|
4
|
+
}
|
5
|
+
|
6
|
+
Searcher.prototype = new function() {
|
7
|
+
// search is performed in chunks of 1000 for non-blocking user input
|
8
|
+
var CHUNK_SIZE = 1000;
|
9
|
+
// do not try to find more than 100 results
|
10
|
+
var MAX_RESULTS = 100;
|
11
|
+
var huid = 1;
|
12
|
+
var suid = 1;
|
13
|
+
var runs = 0;
|
14
|
+
|
15
|
+
this.find = function(query) {
|
16
|
+
var queries = splitQuery(query);
|
17
|
+
var regexps = buildRegexps(queries);
|
18
|
+
var highlighters = buildHilighters(queries);
|
19
|
+
var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
|
20
|
+
var _this = this;
|
21
|
+
|
22
|
+
this.currentSuid = state.n;
|
23
|
+
|
24
|
+
if (!query) return;
|
25
|
+
|
26
|
+
var run = function() {
|
27
|
+
// stop current search thread if new search started
|
28
|
+
if (state.n != _this.currentSuid) return;
|
29
|
+
|
30
|
+
var results =
|
31
|
+
performSearch(_this.data, regexps, queries, highlighters, state);
|
32
|
+
var hasMore = (state.limit > 0 && state.pass < 4);
|
33
|
+
|
34
|
+
triggerResults.call(_this, results, !hasMore);
|
35
|
+
if (hasMore) {
|
36
|
+
setTimeout(run, 2);
|
37
|
+
}
|
38
|
+
runs++;
|
39
|
+
};
|
40
|
+
runs = 0;
|
41
|
+
|
42
|
+
// start search thread
|
43
|
+
run();
|
44
|
+
}
|
45
|
+
|
46
|
+
/* ----- Events ------ */
|
47
|
+
this.ready = function(fn) {
|
48
|
+
fn.huid = huid;
|
49
|
+
this.handlers.push(fn);
|
50
|
+
}
|
51
|
+
|
52
|
+
/* ----- Utilities ------ */
|
53
|
+
function splitQuery(query) {
|
54
|
+
return jQuery.grep(query.split(/(\s+|::?|\(\)?)/), function(string) {
|
55
|
+
return string.match(/\S/);
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
function buildRegexps(queries) {
|
60
|
+
return jQuery.map(queries, function(query) {
|
61
|
+
return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i');
|
62
|
+
});
|
63
|
+
}
|
64
|
+
|
65
|
+
function buildHilighters(queries) {
|
66
|
+
return jQuery.map(queries, function(query) {
|
67
|
+
return jQuery.map(query.split(''), function(l, i) {
|
68
|
+
return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
|
69
|
+
}).join('');
|
70
|
+
});
|
71
|
+
}
|
72
|
+
|
73
|
+
// function longMatchRegexp(index, longIndex, regexps) {
|
74
|
+
// for (var i = regexps.length - 1; i >= 0; i--){
|
75
|
+
// if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
|
76
|
+
// };
|
77
|
+
// return true;
|
78
|
+
// }
|
79
|
+
|
80
|
+
|
81
|
+
/* ----- Mathchers ------ */
|
82
|
+
|
83
|
+
/*
|
84
|
+
* This record matches if the index starts with queries[0] and the record
|
85
|
+
* matches all of the regexps
|
86
|
+
*/
|
87
|
+
function matchPassBeginning(index, longIndex, queries, regexps) {
|
88
|
+
if (index.indexOf(queries[0]) != 0) return false;
|
89
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
90
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
91
|
+
return false;
|
92
|
+
};
|
93
|
+
return true;
|
94
|
+
}
|
95
|
+
|
96
|
+
/*
|
97
|
+
* This record matches if the longIndex starts with queries[0] and the
|
98
|
+
* longIndex matches all of the regexps
|
99
|
+
*/
|
100
|
+
function matchPassLongIndex(index, longIndex, queries, regexps) {
|
101
|
+
if (longIndex.indexOf(queries[0]) != 0) return false;
|
102
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
103
|
+
if (!longIndex.match(regexps[i]))
|
104
|
+
return false;
|
105
|
+
};
|
106
|
+
return true;
|
107
|
+
}
|
108
|
+
|
109
|
+
/*
|
110
|
+
* This record matches if the index contains queries[0] and the record
|
111
|
+
* matches all of the regexps
|
112
|
+
*/
|
113
|
+
function matchPassContains(index, longIndex, queries, regexps) {
|
114
|
+
if (index.indexOf(queries[0]) == -1) return false;
|
115
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
116
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
117
|
+
return false;
|
118
|
+
};
|
119
|
+
return true;
|
120
|
+
}
|
121
|
+
|
122
|
+
/*
|
123
|
+
* This record matches if regexps[0] matches the index and the record
|
124
|
+
* matches all of the regexps
|
125
|
+
*/
|
126
|
+
function matchPassRegexp(index, longIndex, queries, regexps) {
|
127
|
+
if (!index.match(regexps[0])) return false;
|
128
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
129
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
130
|
+
return false;
|
131
|
+
};
|
132
|
+
return true;
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
/* ----- Highlighters ------ */
|
137
|
+
function highlightRegexp(info, queries, regexps, highlighters) {
|
138
|
+
var result = createResult(info);
|
139
|
+
for (var i=0, l = regexps.length; i < l; i++) {
|
140
|
+
result.title = result.title.replace(regexps[i], highlighters[i]);
|
141
|
+
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
|
142
|
+
};
|
143
|
+
return result;
|
144
|
+
}
|
145
|
+
|
146
|
+
function hltSubstring(string, pos, length) {
|
147
|
+
return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
|
148
|
+
}
|
149
|
+
|
150
|
+
function highlightQuery(info, queries, regexps, highlighters) {
|
151
|
+
var result = createResult(info);
|
152
|
+
var pos = 0;
|
153
|
+
var lcTitle = result.title.toLowerCase();
|
154
|
+
|
155
|
+
pos = lcTitle.indexOf(queries[0]);
|
156
|
+
if (pos != -1) {
|
157
|
+
result.title = hltSubstring(result.title, pos, queries[0].length);
|
158
|
+
}
|
159
|
+
|
160
|
+
result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
|
161
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
162
|
+
result.title = result.title.replace(regexps[i], highlighters[i]);
|
163
|
+
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
|
164
|
+
};
|
165
|
+
return result;
|
166
|
+
}
|
167
|
+
|
168
|
+
function createResult(info) {
|
169
|
+
var result = {};
|
170
|
+
result.title = info[0];
|
171
|
+
result.namespace = info[1];
|
172
|
+
result.path = info[2];
|
173
|
+
result.params = info[3];
|
174
|
+
result.snippet = info[4];
|
175
|
+
return result;
|
176
|
+
}
|
177
|
+
|
178
|
+
/* ----- Searching ------ */
|
179
|
+
function performSearch(data, regexps, queries, highlighters, state) {
|
180
|
+
var searchIndex = data.searchIndex;
|
181
|
+
var longSearchIndex = data.longSearchIndex;
|
182
|
+
var info = data.info;
|
183
|
+
var result = [];
|
184
|
+
var i = state.from;
|
185
|
+
var l = searchIndex.length;
|
186
|
+
var togo = CHUNK_SIZE;
|
187
|
+
var matchFunc, hltFunc;
|
188
|
+
|
189
|
+
while (state.pass < 4 && state.limit > 0 && togo > 0) {
|
190
|
+
if (state.pass == 0) {
|
191
|
+
matchFunc = matchPassBeginning;
|
192
|
+
hltFunc = highlightQuery;
|
193
|
+
} else if (state.pass == 1) {
|
194
|
+
matchFunc = matchPassLongIndex;
|
195
|
+
hltFunc = highlightQuery;
|
196
|
+
} else if (state.pass == 2) {
|
197
|
+
matchFunc = matchPassContains;
|
198
|
+
hltFunc = highlightQuery;
|
199
|
+
} else if (state.pass == 3) {
|
200
|
+
matchFunc = matchPassRegexp;
|
201
|
+
hltFunc = highlightRegexp;
|
202
|
+
}
|
203
|
+
|
204
|
+
for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
|
205
|
+
if (info[i].n == state.n) continue;
|
206
|
+
if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
|
207
|
+
info[i].n = state.n;
|
208
|
+
result.push(hltFunc(info[i], queries, regexps, highlighters));
|
209
|
+
state.limit--;
|
210
|
+
}
|
211
|
+
};
|
212
|
+
if (searchIndex.length <= i) {
|
213
|
+
state.pass++;
|
214
|
+
i = state.from = 0;
|
215
|
+
} else {
|
216
|
+
state.from = i;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
return result;
|
220
|
+
}
|
221
|
+
|
222
|
+
function triggerResults(results, isLast) {
|
223
|
+
jQuery.each(this.handlers, function(i, fn) {
|
224
|
+
fn.call(this, results, isLast)
|
225
|
+
})
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
4
|
+
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
6
|
+
<head>
|
7
|
+
<title>search index</title>
|
8
|
+
<link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" charset="utf-8" />
|
9
|
+
<link rel="stylesheet" href="../css/panel.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
<script src="../js/search_index.js" type="text/javascript" charset="utf-8"></script>
|
11
|
+
<script src="../js/searcher.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="tree.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script src="../js/searchdoc.js" type="text/javascript" charset="utf-8"></script>
|
15
|
+
<script type="text/javascript" charset="utf-8">
|
16
|
+
function placeholder() {
|
17
|
+
if ($('<input type="text">')[0].placeholder !== undefined) return;
|
18
|
+
|
19
|
+
$('#search-label').click(function() {
|
20
|
+
$('#search').focus();
|
21
|
+
$('#search-label').hide();
|
22
|
+
});
|
23
|
+
|
24
|
+
$('#search').focus(function() {
|
25
|
+
$('#search-label').hide();
|
26
|
+
});
|
27
|
+
$('#search').blur(function() {
|
28
|
+
this.value == '' && $('#search-label').show()
|
29
|
+
});
|
30
|
+
|
31
|
+
$('#search')[0].value == '' && $('#search-label').show();
|
32
|
+
}
|
33
|
+
$(function() {
|
34
|
+
placeholder();
|
35
|
+
$('#links').hide();
|
36
|
+
var panel = new Searchdoc.Panel($('#panel'), search_data, tree, window.parent.frames[1]);
|
37
|
+
$('#search').focus();
|
38
|
+
|
39
|
+
var s = window.parent.location.search.match(/\?q=([^&]+)/);
|
40
|
+
if (s) {
|
41
|
+
s = decodeURIComponent(s[1]).replace(/\+/g, ' ');
|
42
|
+
if (s.length > 0)
|
43
|
+
{
|
44
|
+
$('#search').val(s);
|
45
|
+
panel.search(s, true);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
})
|
49
|
+
</script>
|
50
|
+
</head>
|
51
|
+
<body>
|
52
|
+
<div class="panel panel_tree" id="panel">
|
53
|
+
<div class="header">
|
54
|
+
<div>
|
55
|
+
<label for="search" id="search-label" style="display: none">Search</label>
|
56
|
+
<table>
|
57
|
+
<tr><td>
|
58
|
+
<input type="Search" placeholder="Search" autosave="searchdoc" results="10" id="search" autocomplete="off"/>
|
59
|
+
</td></tr>
|
60
|
+
</table></div>
|
61
|
+
</div>
|
62
|
+
<div class="tree">
|
63
|
+
<ul>
|
64
|
+
</ul>
|
65
|
+
</div>
|
66
|
+
<div class="result">
|
67
|
+
<ul>
|
68
|
+
</ul>
|
69
|
+
</div>
|
70
|
+
</div>
|
71
|
+
<a href="links.html" id="links">index</a>
|
72
|
+
</body>
|
73
|
+
</html>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<html>
|
2
|
+
<head>File index</head>
|
3
|
+
<body>
|
4
|
+
|
5
|
+
<a href="../files/README_rdoc.html">README.rdoc</a>
|
6
|
+
|
7
|
+
<a href="../files/ext/bitboard_c.html">ext/bitboard.c</a>
|
8
|
+
|
9
|
+
<a href="../files/ext/board_c.html">ext/board.c</a>
|
10
|
+
|
11
|
+
<a href="../files/ext/chess_c.html">ext/chess.c</a>
|
12
|
+
|
13
|
+
<a href="../files/ext/common_c.html">ext/common.c</a>
|
14
|
+
|
15
|
+
<a href="../files/ext/game_c.html">ext/game.c</a>
|
16
|
+
|
17
|
+
<a href="../files/ext/special_c.html">ext/special.c</a>
|
18
|
+
|
19
|
+
<a href="../files/lib/chess_rb.html">lib/chess.rb</a>
|
20
|
+
|
21
|
+
<a href="../files/lib/chess/exceptions_rb.html">lib/chess/exceptions.rb</a>
|
22
|
+
|
23
|
+
<a href="../files/lib/chess/game_rb.html">lib/chess/game.rb</a>
|
24
|
+
|
25
|
+
<a href="../files/lib/chess/gnuchess_rb.html">lib/chess/gnuchess.rb</a>
|
26
|
+
|
27
|
+
<a href="../files/lib/chess/pgn_rb.html">lib/chess/pgn.rb</a>
|
28
|
+
|
29
|
+
<a href="../files/lib/chess/utf8_notation_rb.html">lib/chess/utf8_notation.rb</a>
|
30
|
+
|
31
|
+
<a href="../files/lib/chess/version_rb.html">lib/chess/version.rb</a>
|
32
|
+
|
33
|
+
</body>
|
34
|
+
</html>
|
data/doc/panel/tree.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
var tree = [["","","files",[["README.rdoc","files/README_rdoc.html","",[]],["","","ext",[["bitboard.c","files/ext/bitboard_c.html","",[]],["board.c","files/ext/board_c.html","",[]],["chess.c","files/ext/chess_c.html","",[]],["common.c","files/ext/common_c.html","",[]],["game.c","files/ext/game_c.html","",[]],["special.c","files/ext/special_c.html","",[]]]],["","","lib",[["","","chess",[["exceptions.rb","files/lib/chess/exceptions_rb.html","",[]],["game.rb","files/lib/chess/game_rb.html","",[]],["gnuchess.rb","files/lib/chess/gnuchess_rb.html","",[]],["pgn.rb","files/lib/chess/pgn_rb.html","",[]],["utf8_notation.rb","files/lib/chess/utf8_notation_rb.html","",[]],["version.rb","files/lib/chess/version_rb.html","",[]]]],["chess.rb","files/lib/chess_rb.html","",[]]]]]],["Chess","classes/Chess.html","",[["BadNotationError","classes/Chess/BadNotationError.html"," < StandardError",[]],["Board","classes/Chess/Board.html"," < Object",[]],["CGame","classes/Chess/CGame.html"," < Object",[]],["Game","classes/Chess/Game.html"," < Chess::CGame",[]],["Gnuchess","classes/Chess/Gnuchess.html","",[]],["IllegalMoveError","classes/Chess/IllegalMoveError.html"," < StandardError",[]],["InvalidFenFormatError","classes/Chess/InvalidFenFormatError.html"," < StandardError",[]],["InvalidPgnFormatError","classes/Chess/InvalidPgnFormatError.html"," < StandardError",[]],["Pgn","classes/Chess/Pgn.html"," < Object",[]],["UTF8Notation","classes/Chess/UTF8Notation.html","",[]]]]]
|
data/ext/chess.c
CHANGED
@@ -31,7 +31,8 @@ game_alloc (VALUE class)
|
|
31
31
|
* Set the game position with a FEN string.
|
32
32
|
*
|
33
33
|
* Parameters are:
|
34
|
-
* +fen+:: the FEN (Forsyth–Edwards Notation) string notation used to set the
|
34
|
+
* +fen+:: the FEN (Forsyth–Edwards Notation) string notation used to set the
|
35
|
+
* game position.
|
35
36
|
*/
|
36
37
|
VALUE
|
37
38
|
game_set_fen (VALUE self, VALUE fen)
|
@@ -49,14 +50,26 @@ game_set_fen (VALUE self, VALUE fen)
|
|
49
50
|
*
|
50
51
|
* Parameters are:
|
51
52
|
* +piece+:: the character of the moving piece <em>('P', 'R', 'N', 'B', 'Q', 'K')</em>.
|
52
|
-
* +disambiguating+:: when two (or more) identical pieces can move to the same
|
53
|
-
*
|
54
|
-
*
|
55
|
-
*
|
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).
|
56
65
|
* Keep blank if no needed.
|
57
66
|
* +to_coord+:: the square where the moving piece will <em>('a1', 'a2', ... , 'h7', 'h8')</em>.
|
58
|
-
* +promote_in+:: the character of promotion piece <em>('R', 'N', 'B', 'Q')</em>.
|
59
|
-
*
|
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.
|
60
73
|
*/
|
61
74
|
VALUE
|
62
75
|
game_move (VALUE self, VALUE rb_piece, VALUE rb_disambiguating, VALUE rb_to_coord, VALUE rb_promote_in)
|
@@ -83,10 +96,16 @@ game_move (VALUE self, VALUE rb_piece, VALUE rb_disambiguating, VALUE rb_to_coor
|
|
83
96
|
* Make a move. This add a new Board in the Game.
|
84
97
|
*
|
85
98
|
* Parameters are:
|
86
|
-
* +from+:: the 2 character string representing the starting square of the
|
87
|
-
*
|
88
|
-
* +
|
89
|
-
*
|
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.
|
90
109
|
*/
|
91
110
|
VALUE
|
92
111
|
game_move2 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
|
@@ -108,7 +127,8 @@ game_move2 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
|
|
108
127
|
*
|
109
128
|
* Make a move. This add a new Board in the Game.
|
110
129
|
*
|
111
|
-
* Each square on the chessboard is represented by an integer according to the
|
130
|
+
* Each square on the chessboard is represented by an integer according to the
|
131
|
+
* following scheme:
|
112
132
|
* 8 | 56 57 58 59 60 61 62 63
|
113
133
|
* 7 | 48 49 50 51 52 53 54 55
|
114
134
|
* 6 | 40 41 42 43 44 45 46 47
|
@@ -119,11 +139,16 @@ game_move2 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
|
|
119
139
|
* 1 | 0 1 2 3 4 5 6 7
|
120
140
|
* +-------------------------
|
121
141
|
* a b c d e f g h
|
142
|
+
*
|
122
143
|
* Parameters are:
|
123
144
|
* +from+:: the integer representing the starting square of the moving piece.
|
124
145
|
* +to+:: the integer representing the ending square of the moving piece.
|
125
|
-
* +promote_in+:: the character of promotion piece <em>('R', 'N', 'B', 'Q')</em>.
|
126
|
-
*
|
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.
|
127
152
|
*/
|
128
153
|
VALUE
|
129
154
|
game_move3 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
|
@@ -143,10 +168,12 @@ game_move3 (VALUE self, VALUE rb_from, VALUE rb_to, VALUE rb_promote_in)
|
|
143
168
|
/*
|
144
169
|
* call-seq: resign(color)
|
145
170
|
*
|
146
|
-
* The game result is set to '1-0' if +color+ is "black", otherwise is set to
|
171
|
+
* The game result is set to '1-0' if +color+ is "black", otherwise is set to
|
172
|
+
* '0-1' if color is "white".
|
147
173
|
*
|
148
174
|
* Parameters are:
|
149
|
-
* +color+:: the color of the player who resigns the game; it can be +:white+ or
|
175
|
+
* +color+:: the color of the player who resigns the game; it can be +:white+ or
|
176
|
+
* +:black+.
|
150
177
|
*/
|
151
178
|
VALUE
|
152
179
|
game_resign (VALUE self, VALUE color)
|
@@ -182,7 +209,8 @@ game_draw (VALUE self)
|
|
182
209
|
/*
|
183
210
|
* call-seq: [n]
|
184
211
|
*
|
185
|
-
* Returns the +n+-th Board of the Game or +nil+ if the +n+-th Board does not
|
212
|
+
* Returns the +n+-th Board of the Game or +nil+ if the +n+-th Board does not
|
213
|
+
* exist.
|
186
214
|
*/
|
187
215
|
VALUE
|
188
216
|
game_boards (VALUE self, VALUE index)
|
@@ -199,7 +227,8 @@ game_boards (VALUE self, VALUE index)
|
|
199
227
|
/*
|
200
228
|
* call-seq: current
|
201
229
|
*
|
202
|
-
* Returns the current Board of the Game (the current chess position of the
|
230
|
+
* Returns the current Board of the Game (the current chess position of the
|
231
|
+
* game).
|
203
232
|
*/
|
204
233
|
VALUE
|
205
234
|
game_current_board (VALUE self)
|
@@ -227,26 +256,34 @@ game_moves (VALUE self)
|
|
227
256
|
}
|
228
257
|
|
229
258
|
/*
|
230
|
-
* call-seq:
|
259
|
+
* call-seq: coord_moves
|
231
260
|
*
|
232
|
-
* Returns the array with all
|
261
|
+
* Returns the array with all moves done in coordinate chess notation <em>(es: b1c3)</em>.
|
233
262
|
*/
|
234
263
|
VALUE
|
235
|
-
|
264
|
+
game_coord_moves (VALUE self)
|
236
265
|
{
|
237
266
|
Game *g;
|
238
267
|
Data_Get_Struct (self, Game, g);
|
239
268
|
int i;
|
240
269
|
VALUE moves = rb_ary_new ();
|
241
270
|
for (i = 0; i < g->current; i++)
|
242
|
-
rb_ary_push (moves, rb_str_new2 (g->
|
271
|
+
rb_ary_push (moves, rb_str_new2 (g->coord_moves[i]));
|
243
272
|
return moves;
|
244
273
|
}
|
245
274
|
|
275
|
+
VALUE
|
276
|
+
game_full_moves (VALUE self)
|
277
|
+
{
|
278
|
+
printf ("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");
|
279
|
+
return game_coord_moves (self);
|
280
|
+
}
|
281
|
+
|
246
282
|
/*
|
247
283
|
* call-seq: threefold_repetition?
|
248
284
|
*
|
249
|
-
* Returns +true+ if a player can claim draw by the threefold repetition rule,
|
285
|
+
* Returns +true+ if a player can claim draw by the threefold repetition rule,
|
286
|
+
* +false+ otherwise.
|
250
287
|
*/
|
251
288
|
VALUE
|
252
289
|
game_threefold_repetition (VALUE self)
|
@@ -309,7 +346,7 @@ game_each (VALUE self)
|
|
309
346
|
Data_Get_Struct (self, Game, g);
|
310
347
|
for (i = 0; i < g->current; i++)
|
311
348
|
rb_yield_values (4, Data_Wrap_Struct (board_klass, 0, 0, get_board (g, i)),
|
312
|
-
rb_str_new2 (g->moves[i]), rb_str_new2 (g->
|
349
|
+
rb_str_new2 (g->moves[i]), rb_str_new2 (g->coord_moves[i]),
|
313
350
|
INT2FIX (i));
|
314
351
|
return self;
|
315
352
|
}
|
@@ -389,7 +426,8 @@ board_placement (VALUE self)
|
|
389
426
|
* Returns the piece on the +square+ of the chessboard. If there is no piece or
|
390
427
|
* the square is not valid return the blank string.
|
391
428
|
*
|
392
|
-
* Each square on the chessboard is represented by an integer according to the
|
429
|
+
* Each square on the chessboard is represented by an integer according to the
|
430
|
+
* following scheme:
|
393
431
|
* 8 | 56 57 58 59 60 61 62 63
|
394
432
|
* 7 | 48 49 50 51 52 53 54 55
|
395
433
|
* 6 | 40 41 42 43 44 45 46 47
|
@@ -424,7 +462,8 @@ board_get_piece (VALUE self, VALUE square)
|
|
424
462
|
/*
|
425
463
|
* call-seq: check?
|
426
464
|
*
|
427
|
-
* Returns +true+ if the king of the color that has the turn is in check,
|
465
|
+
* Returns +true+ if the king of the color that has the turn is in check,
|
466
|
+
* +false+ otherwise.
|
428
467
|
*/
|
429
468
|
VALUE
|
430
469
|
board_king_in_check (VALUE self)
|
@@ -440,7 +479,8 @@ board_king_in_check (VALUE self)
|
|
440
479
|
/*
|
441
480
|
* call-seq: checkmate?
|
442
481
|
*
|
443
|
-
* Returns +true+ if the king of the color that has the turn is in checkmate,
|
482
|
+
* Returns +true+ if the king of the color that has the turn is in checkmate,
|
483
|
+
* +false+ otherwise.
|
444
484
|
*/
|
445
485
|
VALUE
|
446
486
|
board_king_in_checkmate (VALUE self)
|
@@ -456,7 +496,8 @@ board_king_in_checkmate (VALUE self)
|
|
456
496
|
/*
|
457
497
|
* call-seq: stalemate?
|
458
498
|
*
|
459
|
-
* Returns +true+ if the pieces of the color that has the turn are in stalemate,
|
499
|
+
* Returns +true+ if the pieces of the color that has the turn are in stalemate,
|
500
|
+
* +false+ otherwise.
|
460
501
|
*/
|
461
502
|
VALUE
|
462
503
|
board_stalemate (VALUE self)
|
@@ -472,7 +513,8 @@ board_stalemate (VALUE self)
|
|
472
513
|
/*
|
473
514
|
* call-seq: insufficient_material?
|
474
515
|
*
|
475
|
-
* Returns +true+ if the board has insufficient material to checkmate, +false+
|
516
|
+
* Returns +true+ if the board has insufficient material to checkmate, +false+
|
517
|
+
* otherwise.
|
476
518
|
*/
|
477
519
|
VALUE
|
478
520
|
board_insufficient_material (VALUE self)
|
@@ -488,7 +530,8 @@ board_insufficient_material (VALUE self)
|
|
488
530
|
/*
|
489
531
|
* call-seq: fifty_move_rule?
|
490
532
|
*
|
491
|
-
* Returns +true+ if a player can claim draw by the fifty-move rule, +false+
|
533
|
+
* Returns +true+ if a player can claim draw by the fifty-move rule, +false+
|
534
|
+
* otherwise.
|
492
535
|
*/
|
493
536
|
VALUE
|
494
537
|
board_fifty_move_rule (VALUE self)
|
@@ -520,7 +563,9 @@ board_active_color (VALUE self)
|
|
520
563
|
/*
|
521
564
|
* call-seq: halfmove_clock
|
522
565
|
*
|
523
|
-
* Returns the halfmove clock that is the number of halfmoves since the last
|
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.
|
524
569
|
*/
|
525
570
|
VALUE
|
526
571
|
board_halfmove_clock (VALUE self)
|
@@ -533,7 +578,8 @@ board_halfmove_clock (VALUE self)
|
|
533
578
|
/*
|
534
579
|
* call-seq: fullmove_number
|
535
580
|
*
|
536
|
-
* Returns the fullmove number: the number of the full move. It starts at 1, and
|
581
|
+
* Returns the fullmove number: the number of the full move. It starts at 1, and
|
582
|
+
* is incremented after black's move.
|
537
583
|
*/
|
538
584
|
VALUE
|
539
585
|
board_fullmove_number (VALUE self)
|
@@ -597,6 +643,7 @@ Init_chess ()
|
|
597
643
|
rb_define_method (game, "[]", game_boards, 1);
|
598
644
|
rb_define_method (game, "current", game_current_board, 0);
|
599
645
|
rb_define_method (game, "moves", game_moves, 0);
|
646
|
+
rb_define_method (game, "coord_moves", game_coord_moves, 0);
|
600
647
|
rb_define_method (game, "full_moves", game_full_moves, 0);
|
601
648
|
rb_define_method (game, "threefold_repetition?", game_threefold_repetition, 0);
|
602
649
|
rb_define_method (game, "result", game_result, 0);
|
@@ -608,7 +655,9 @@ Init_chess ()
|
|
608
655
|
|
609
656
|
/*
|
610
657
|
* This class rappresents a chess board.
|
611
|
-
* The rappresentation of the board use _bitboards_ where each bit represents
|
658
|
+
* The rappresentation of the board use _bitboards_ where each bit represents
|
659
|
+
* a game position or state, designed for optimization of speed and/or memory
|
660
|
+
* or disk use in mass calculations.
|
612
661
|
* This ensures a fast library.
|
613
662
|
*/
|
614
663
|
board_klass = rb_define_class_under (chess, "Board", rb_cObject);
|