@@ -6,7 +6,7 @@ $(document).ready(() => {
6
6
// $(".games-container").empty();
7
7
loadDatabase ( $ ( "#collection" ) . val ( ) ) ;
8
8
$ . get ( prefix + 'transpositions.json' , ( t ) => {
9
- database . transpositions = t ;
9
+ database . transpositions = JSON . parse ( t ) ;
10
10
} ) ;
11
11
12
12
} ) ;
@@ -22,10 +22,11 @@ function loadDatabase(db) {
22
22
document . directory . discoverRanges = [ ] ;
23
23
document . directory . transpositions = [ ] ;
24
24
$ ( ".games-container" ) . empty ( ) ;
25
- displayGame ( [ '' , '' , '' , 'Loading Games...' , 'This may take a second.' , '' , '' , '' , '' , '' , '' , '' , '' , '' ] , null )
25
+ displayGame ( [ '' , '' , '' , 'Loading Games...' , 'This may take a second.' , '' , '' , '' , '' , '' , '' , '' , '' , '' ] , null ) ;
26
26
activeDatabase = db ;
27
27
$ . get ( prefix + db + '/lookups/lookups.json' , ( r ) => {
28
28
database . lookup = new Map ( ) ;
29
+ r = JSON . parse ( r ) ;
29
30
for ( let moveLength of Object . keys ( r ) ) {
30
31
let section = new Map ( ) ;
31
32
for ( const [ move , data ] of Object . entries ( r [ moveLength ] ) ) {
@@ -116,28 +117,28 @@ function prepareDirectory(boards) {
116
117
loadDatabase ( $ ( "#collection" ) . val ( ) ) ;
117
118
document . directory . nextBoards = null ;
118
119
$ ( "#number-of-games" ) . text ( 0 ) ;
119
- // document.branches.upToDate = false;
120
120
document . directory . upToDate = ! document . directory . upToDate ;
121
121
boards = boards . slice ( 1 ) ;
122
122
const moves = boards . reduce ( ( acc , curr ) => acc += intToB64FourChr ( curr . scan ) , '' )
123
123
let aliases = [ moves ] ;
124
124
let transpositions = new Set ( ) ;
125
125
transpositions . add ( moves ) ;
126
- let moveCount = 0 ;
127
126
let currMoveLength = moves . length + 4 ;
128
127
let visited = new Set ( ) ;
129
128
return new ScheduledTask ( getTranspositions , [ aliases , transpositions , visited , currMoveLength , moves ] ) . setSleep ( 5 ) ;
130
129
}
130
+ const maxSize = { "world_championships" : 2 , "titled_tuesday" : 32 , "titled_arena" : 16 , "candidates" : 2 , "interzonals" : 2 , "lichess_broadcasts" : 8 } ;
131
131
function getTranspositions ( aliases , transpositions , visited , currMoveLength , moves ) {
132
132
let remLength = aliases . length
133
133
for ( let a = 0 ; a < remLength ; a ++ ) {
134
134
let alias = aliases [ a ] ;
135
135
const alias_full = [ ...transpositions ] . filter ( x => x . startsWith ( alias ) ) . at ( 0 ) ;
136
136
if ( alias . length == moves . length && ! transpositions . has ( alias ) ) transpositions . add ( alias ) ;
137
+ const collection = $ ( "#collection" ) . val ( ) ;
137
138
while ( aliases [ a ] . length > currMoveLength && alias . length > 8 ) {
138
139
if ( ! visited . has ( aliases [ a ] ) ) {
139
140
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 ] ) ) ) ;
141
142
temp = temp . map ( x => x + alias_full . slice ( x . length ) )
142
143
temp = temp . filter ( x => ! transpositions . has ( x ) )
143
144
visited . add ( aliases [ a ] ) ;
@@ -153,38 +154,11 @@ function getTranspositions(aliases, transpositions, visited, currMoveLength, mov
153
154
if ( aliases . reduce ( ( acc , curr ) => acc . length > curr . length ? acc : curr , aliases [ 0 ] ) . length > 8 ) {
154
155
return new ScheduledTask ( getTranspositions , [ aliases , transpositions , visited , currMoveLength , moves ] ) ;
155
156
} else {
156
- let ranges = [ ] ;
157
-
158
157
localDirectory . transpositions = [ ...transpositions ] ;
159
- let timeout ;
160
- if ( document . directory . indexStep > 0 ) {
161
- timeout = 4000 ;
162
- }
163
- else {
164
- timeout = 1000 ;
165
- }
166
158
return new ScheduledTask ( getSearchRanges , [ transpositions ] ) . setSleep ( 10 ) ;
167
159
}
168
160
}
169
161
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
-
188
162
let scheduleStage = 0 ;
189
163
190
164
class Scheduler {
@@ -287,6 +261,7 @@ document.directory.search.games = [];
287
261
document . directory . search . cache = new MaxSizeMap ( 30 ) ;
288
262
289
263
function getSearchRanges ( transpositions ) {
264
+ const collection = $ ( "#collection" ) . val ( ) ;
290
265
let ranges = [ ] ;
291
266
let chunks = [ ] ;
292
267
document . directory . search . games = [ ] ;
@@ -355,14 +330,14 @@ function getSearchRanges(transpositions) {
355
330
requests . add ( [ 5000 , Math . floor ( ranges [ r ] [ 2 ] [ 0 ] [ 1 ] / 5000 ) ] ) ;
356
331
} else {
357
332
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 ) ;
359
334
requests . add ( [ step * 20000 , Math . floor ( ranges [ r ] [ 0 ] / step ) ] ) ;
360
335
if ( ( step * Math . floor ( ranges [ r ] [ 0 ] / step ) ) + step < ranges [ r ] [ 1 ] )
361
336
requests . add ( [ step * 20000 , ( Math . floor ( ranges [ r ] [ 0 ] / step ) + 1 ) ] ) ;
362
337
}
363
338
}
364
339
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 ;
366
341
setTimeout ( ( r ) => pullGames ( Array . from ( r ) , $ ( "#collection" ) . val ( ) ) , timeout , requests ) ;
367
342
return new ScheduledTask ( gamesObserver , [ requests . size ] ) . setSleep ( 5 ) ;
368
343
}
@@ -417,6 +392,7 @@ function sortGames() {
417
392
else
418
393
return criteria [ 1 ] == "Dsc" ? bVal . localeCompare ( aVal ) : aVal . localeCompare ( bVal ) ; } ) ;
419
394
$ ( "#games-container" ) . empty ( ) ;
395
+ displayGame ( [ '' , '' , '' , 'Loading Games...' , 'This may take a second.' , '' , '' , '' , '' , '' , '' , '' , '' , '' ] , null ) ;
420
396
return new ScheduledTask ( addToDirectory , [ 0 ] ) ;
421
397
}
422
398
0 commit comments