Skip to content

Commit 00010d0

Browse files
committed
minor revisions
- fixed bug that prevented some databases from loading - changed version in about page to beta v1.1
1 parent 9a225d3 commit 00010d0

File tree

3 files changed

+13
-35
lines changed

3 files changed

+13
-35
lines changed

about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<a href="../donate.html"><p id="donate" class="banner-text">donate</p></a>
2121
</div>
2222
<div class="about-text">
23-
<p style="color: aqua">beta v1.0<br></p>
23+
<p style="color: aqua">beta v1.1<br></p>
2424
<p style="display: inline-block;">The Chess Library is an open-source database of 700,000+ chess games, run by
2525
<a href="https://www.github.com/gitpushjoe" style="word-wrap: break-word;"><nobr>a single college student.</nobr></a> It's currently in open beta testing right now so if you have any suggestions, bug findings, questions, or would like to help expand the database,
2626
please share using the donate link above. (Note: The back-end web scraping and data formatting scripts will be up soon.)<br>&nbsp;<br><br>Sources:<br>

database.js

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $(document).ready(() => {
66
// $(".games-container").empty();
77
loadDatabase($("#collection").val());
88
$.get(prefix + 'transpositions.json', (t) => {
9-
database.transpositions = t;
9+
database.transpositions = JSON.parse(t);
1010
});
1111

1212
});
@@ -22,10 +22,11 @@ function loadDatabase(db) {
2222
document.directory.discoverRanges = [];
2323
document.directory.transpositions = [];
2424
$(".games-container").empty();
25-
displayGame(['','','','Loading Games...','This may take a second.','','','','','','','','',''], null)
25+
displayGame(['','','','Loading Games...','This may take a second.','','','','','','','','',''], null);
2626
activeDatabase = db;
2727
$.get(prefix + db + '/lookups/lookups.json', (r) => {
2828
database.lookup = new Map();
29+
r = JSON.parse(r);
2930
for (let moveLength of Object.keys(r)) {
3031
let section = new Map();
3132
for (const [move, data] of Object.entries(r[moveLength])) {
@@ -116,28 +117,28 @@ function prepareDirectory(boards) {
116117
loadDatabase($("#collection").val());
117118
document.directory.nextBoards = null;
118119
$("#number-of-games").text(0);
119-
// document.branches.upToDate = false;
120120
document.directory.upToDate = !document.directory.upToDate;
121121
boards = boards.slice(1);
122122
const moves = boards.reduce((acc, curr) => acc += intToB64FourChr(curr.scan), '')
123123
let aliases = [moves];
124124
let transpositions = new Set();
125125
transpositions.add(moves);
126-
let moveCount = 0;
127126
let currMoveLength = moves.length + 4;
128127
let visited = new Set();
129128
return new ScheduledTask(getTranspositions, [aliases, transpositions, visited, currMoveLength, moves]).setSleep(5);
130129
}
130+
const maxSize = {"world_championships": 2, "titled_tuesday": 32, "titled_arena": 16, "candidates": 2, "interzonals": 2, "lichess_broadcasts": 8};
131131
function getTranspositions(aliases, transpositions, visited, currMoveLength, moves) {
132132
let remLength = aliases.length
133133
for (let a = 0; a < remLength; a++) {
134134
let alias = aliases[a];
135135
const alias_full = [...transpositions].filter(x => x.startsWith(alias)).at(0);
136136
if (alias.length == moves.length && !transpositions.has(alias)) transpositions.add(alias);
137+
const collection = $("#collection").val();
137138
while (aliases[a].length > currMoveLength && alias.length > 8) {
138139
if (!visited.has(aliases[a])) {
139140
let temp = database.transpositions[aliases[a].length].reduce((acc, curr) => { if (curr.includes(aliases[a])) acc.push(...curr.filter(x => !aliases.includes(x))); return acc; }, []);
140-
temp = temp.filter(x => !!database.lookup.get(Math.min(x.length, 32)).get(x.slice(0, 32)));
141+
temp = temp.filter(x => !!database.lookup.get(Math.min(x.length, maxSize[collection])).get(x.slice(0, maxSize[collection])));
141142
temp = temp.map(x => x + alias_full.slice(x.length))
142143
temp = temp.filter(x => !transpositions.has(x))
143144
visited.add(aliases[a]);
@@ -153,38 +154,11 @@ function getTranspositions(aliases, transpositions, visited, currMoveLength, mov
153154
if (aliases.reduce((acc, curr) => acc.length > curr.length ? acc : curr, aliases[0]).length > 8) {
154155
return new ScheduledTask(getTranspositions, [aliases, transpositions, visited, currMoveLength, moves]);
155156
} else {
156-
let ranges = [];
157-
158157
localDirectory.transpositions = [...transpositions];
159-
let timeout;
160-
if (document.directory.indexStep > 0) {
161-
timeout = 4000;
162-
}
163-
else {
164-
timeout = 1000;
165-
}
166158
return new ScheduledTask(getSearchRanges, [transpositions]).setSleep(10);
167159
}
168160
}
169161

170-
function checkForBoardUpdates(boards) {
171-
if (!document.directory.updating) {
172-
if (boards) {
173-
// setTimeout(updateDatabase, 500, boards);
174-
175-
} else if (document.directory.nextBoards) {
176-
if (document.directory.nextBoards.length == mainGame.boards.length)
177-
setTimeout(updateDatabase, 500, document.directory.nextBoards);
178-
else {
179-
setTimeout(checkForBoardUpdates, 1000, mainGame.boards);
180-
}
181-
}
182-
} else {
183-
if (boards)
184-
document.directory.nextBoards = boards;
185-
}
186-
}
187-
188162
let scheduleStage = 0;
189163

190164
class Scheduler {
@@ -287,6 +261,7 @@ document.directory.search.games = [];
287261
document.directory.search.cache = new MaxSizeMap(30);
288262

289263
function getSearchRanges(transpositions) {
264+
const collection = $("#collection").val();
290265
let ranges = [];
291266
let chunks = [];
292267
document.directory.search.games = [];
@@ -355,14 +330,14 @@ function getSearchRanges(transpositions) {
355330
requests.add([5000, Math.floor(ranges[r][2][0][1] / 5000)]);
356331
} else {
357332
const dist = ranges[r][1] - ranges[r][0];
358-
let step = Math.min(2**dist.toString(2).length, 16);
333+
let step = Math.min(2**dist.toString(2).length, maxSize[collection] / 2);
359334
requests.add([step * 20000, Math.floor(ranges[r][0] / step)]);
360335
if ((step * Math.floor(ranges[r][0] / step)) + step < ranges[r][1])
361336
requests.add([step * 20000, (Math.floor(ranges[r][0] / step) + 1)]);
362337
}
363338
}
364339
document.branches.branches = branches;
365-
const timeout = [...requests].some(x => !document.directory.search.cache.has(x)) ? 1000 : 0;
340+
const timeout = [...requests].some(x => !document.directory.search.cache.has(x)) ? 500 : 0;
366341
setTimeout((r) => pullGames(Array.from(r), $("#collection").val()), timeout, requests);
367342
return new ScheduledTask(gamesObserver, [requests.size]).setSleep(5);
368343
}
@@ -417,6 +392,7 @@ function sortGames() {
417392
else
418393
return criteria[1] == "Dsc" ? bVal.localeCompare(aVal) : aVal.localeCompare(bVal);});
419394
$("#games-container").empty();
395+
displayGame(['','','','Loading Games...','This may take a second.','','','','','','','','',''], null);
420396
return new ScheduledTask(addToDirectory, [0]);
421397
}
422398

script.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Note: every use of the word "scan" in this document refers to the ChessScan notation method, as outlined in the root directory.
2+
13
const canvas = document.getElementById('chessboard');
24
const ctx = canvas.getContext('2d');
35
const CANVAS_SIZE = 800;

0 commit comments

Comments
 (0)