Skip to content

Commit 1e1e017

Browse files
committed
beta v1.3 - stockfish update
- added stockfish 11 support! - added fen getter to chess library - moved scheduler class into its own file - fixed various mobile UI bugs
1 parent 48a757f commit 1e1e017

File tree

14 files changed

+453
-219
lines changed

14 files changed

+453
-219
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}

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.2.3.2<br></p>
23+
<p style="color: aqua">beta v1.2.2<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>

chess.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Game {
104104
dynamicQueue = [];
105105
overlayQueue = [];
106106
this.validProspects = [];
107-
setTimeout(() => this.dispatchBoards(), this.dispatchDelayTime);
107+
if (this.dispatchDelayTime != -1) setTimeout(() => this.dispatchBoards(), this.dispatchDelayTime);
108108
}
109109

110110
/** Sets the current Board forwards by n steps.
@@ -117,7 +117,7 @@ class Game {
117117
promotionMode = false;
118118
dynamicQueue = [];
119119
overlayQueue = [];
120-
setTimeout(() => this.dispatchBoards(), this.dispatchDelayTime);
120+
if (this.dispatchDelayTime != -1) setTimeout(() => this.dispatchBoards(), this.dispatchDelayTime);
121121
}
122122

123123
/** Sets the current Board to the nth Board.
@@ -220,6 +220,28 @@ class Game {
220220
return this.validProspects;
221221
}
222222

223+
fen() {
224+
const board = [...this.board()].map(p => p && p.toUpperCase() != 'X' ? p: '#')
225+
let fen = [0, 1, 2, 3, 4, 5, 6, 7].reduce((acc, curr) => {
226+
return acc + board.slice(curr * 8, (curr + 1) * 8).join('').replace(/#{1,8}/g, (match) => match.length) + '/'
227+
}, "").slice(0, -1);
228+
fen += ` ${this.currentBoard % 2 == 0 ? 'w' : 'b'} `;
229+
fen += this.board().castling.W % 2 == 1 ? 'K' : '';
230+
fen += this.board().castling.W > 1 ? 'Q' : '';
231+
fen += this.board().castling.B % 2 == 1 ? 'k' : '';
232+
fen += this.board().castling.B > 1 ? 'q' : '';
233+
fen += this.board().castling.W == 0 && this.board().castling.B == 0 ? '-' : '';
234+
fen += ` ${renderSqToAlgebraicStr(board.findIndex(sq => sq.toUpperCase() == 'X'))}`;
235+
if (fen.slice(-1) != " ")
236+
fen += " "
237+
else fen += "- ";
238+
const fiftyMove = this.boards.slice(0, this.currentBoard).reduce((acc, board, idx) =>
239+
[1, 3, 5].includes((board.scan & 0b0_00_000_111_000_000000_000000) >> 15) ||
240+
(board.scan & 0b0_00_000_000_111_000000_000000) >> 12 == 1 ? idx : acc, 0);
241+
fen += this.currentBoard - fiftyMove;
242+
fen += ` ${Math.round(this.currentBoard / 2)}`;
243+
return fen;
244+
}
223245
/** Directly updates the current board with a move.
224246
* @param {number} origin: origin square
225247
* @param {number} destination: destination square
@@ -238,6 +260,7 @@ class Game {
238260
} else {
239261
board = findProspects(origin, this.board()).filter((prospect) => prospect.destination == destination).at(0).board;
240262
}
263+
board.halfMoves = this.board().halfMoves + 1;
241264
if (promotion) {
242265
board.scan = moveObj.getScan([ChessScan.disambiguation, ChessScan.piece]);
243266
if (promotion.toLowerCase() == 'n') board.scan = board.scan | (1 << 20);
@@ -272,7 +295,7 @@ class Game {
272295
this.currentBoard++;
273296
}
274297
}
275-
if (!force) this.dispatchBoards();
298+
if (!force && this.dispatchDelayTime != -1) this.dispatchBoards();
276299
return true;
277300
}
278301

database.js

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -161,95 +161,6 @@ function getTranspositions(aliases, transpositions, visited, currMoveLength, mov
161161

162162
let scheduleStage = 0;
163163

164-
class Scheduler {
165-
constructor() {
166-
this.cycleToken = this.generateToken();
167-
this.tokenLocked = false;
168-
this.lockRevisitDelay = 100;
169-
}
170-
push(task, revisiting=false) {
171-
// console.log(task.func, task.args, task.sleep, task.lock, task.newSession, revisiting);
172-
if (task.token != this.cycleToken) return;
173-
if (task.sleep > 0 && !revisiting) {
174-
setTimeout(() => this.push(task, true), task.sleep);
175-
return;
176-
}
177-
if (this.tokenLocked) {
178-
setTimeout(() => this.push(task, true), this.lockRevisitDelay);
179-
return;
180-
}
181-
if (task.startNewSession) {
182-
this.cycleToken = this.generateToken();
183-
task.token = this.cycleToken;
184-
console.log("new session", this.cycleToken);
185-
}
186-
if (task.lock) {
187-
this.tokenLocked = true;
188-
}
189-
task.execute().then((chainedTaskData) => {
190-
if (task.lock)
191-
this.unlock();
192-
if (!chainedTaskData) return;
193-
let chainedTask = chainedTaskData.task;
194-
let chainedToken = chainedTaskData.token;
195-
chainedTask.setToken(chainedToken);
196-
this.push(chainedTask);
197-
});
198-
}
199-
generateToken() {
200-
return Math.random().toString(16).slice(2);
201-
}
202-
unlock () {
203-
this.tokenLocked = false;
204-
}
205-
force(task) {
206-
task.token = this.cycleToken;
207-
this.push(task);
208-
}
209-
}
210-
211-
class ScheduledTask {
212-
constructor(func=null, args=[], token=null, lock=false, startNewSession=false, sleep=10) {
213-
this.token = token;
214-
this.startNewSession = startNewSession;
215-
this.sleep = sleep;
216-
this.func = func ? func : () => { };
217-
this.args = args;
218-
this.lock = lock;
219-
220-
}
221-
set(func, ...args) {
222-
this.func = func;
223-
this.args = args;
224-
return this;
225-
}
226-
setNewSession(bool) {
227-
this.startNewSession = bool;
228-
return this;
229-
}
230-
setLock(bool) {
231-
this.lock = bool;
232-
return this;
233-
}
234-
setSleep(ms) {
235-
this.sleep = ms;
236-
return this;
237-
}
238-
setToken(token) {
239-
this.token = token;
240-
return this;
241-
}
242-
execute() {
243-
return new Promise((resolve, reject) => {
244-
const res = this.func(...this.args);
245-
if (res instanceof ScheduledTask) {
246-
resolve({"task": res, "token": this.token});
247-
}
248-
resolve(null);
249-
});
250-
}
251-
}
252-
253164
let scheduler = new Scheduler();
254165
let localDirectory = {};
255166
let searchForGamesRange = [null, null];

index.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@
3030
<div class="flexbox-container">
3131
<div id="chessboard-column">
3232
<div id="icon-column">
33+
<img class="options-icon robot" src="resources\\icons\\robot-sleep.png"></img>
3334
<img class="options-icon legals" src="resources\\icons\\legals-enabled.png"></img>
3435
<img class="options-icon arrows" src="resources\\icons\\arrows-enabled.png"></img>
3536
<!-- <img class="options-icon" src="resources\\icons\\legals-enabled.png"></img> -->
3637
</div>
3738
<div id="chessboard-column-main">
39+
<div id="stockfish">
40+
<!-- <p style="display: inline-block; height: 0;">&nbsp;</p> -->
41+
<p class="stockfish-text evaluation">+0.00</p>
42+
<p style="display: inline-block; height: 0; font-size: .25em;">&nbsp;</p>
43+
<p class="stockfish-text data depth">at depth ??<br></p>
44+
<p class="stockfish-text data continuation">null</p>
45+
</div>
3846
<canvas id="chessboard" width="800" height="800"></canvas>
3947
<div id="moves-display">
4048
<div class="moves-block">
@@ -74,11 +82,16 @@
7482
<div class="directory-header">
7583
<div class="directory-header-text">
7684
<p>found</p>
77-
<p id="number-of-games">142,357</p>
85+
<p id="number-of-games">781,475</p>
7886
<select name="Collection" id="collection">
7987
<option value="world_championships">World Championship</option>
8088
<option value="candidates">Candidates</option>
8189
<option value="interzonals">Interzonal</option>
90+
<option value="women">Women's WCC</option>
91+
<option value="wijk">Wijk aan Zee</option>
92+
<option value="olympiads">Chess Olympiad</option>
93+
<option value="world_cup">World Cup</option>
94+
<option value="sinquefield">Sinquefield</option>
8295
<option value="tcec">TCEC</option>
8396
<option value="lichess_broadcasts">Lichess Broadcast (2017—)</option>
8497
<option value="titled_arena">Lichess Titled Arena</option>
@@ -111,11 +124,13 @@
111124
<p class="rating black">(2627)</p>
112125
</div>
113126
</div>
127+
</div>
128+
<script src="scheduler.js"></script>
114129
<script src="rendering.js"></script>
115130
<script src="chess.js"></script>
116131
<script src="script.js"></script>
117132
<script src="database.js"> </script>
118-
<script src="move-display.js"> </script>
133+
<script src="move-display.js"> </script>>
119134
</div>
120135

121136
</body>

resources/icons/1x/robot-wake.png

28.7 KB
Loading

resources/icons/Untitled-2-04.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

resources/icons/robot-sleep.png

21.5 KB
Loading

resources/icons/robot-wake.png

24.5 KB
Loading

scheduler.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
class Scheduler {
2+
constructor() {
3+
this.cycleToken = this.generateToken();
4+
this.tokenLocked = false;
5+
this.lockRevisitDelay = 100;
6+
}
7+
push(task, revisiting=false) {
8+
if (task.token != this.cycleToken) return;
9+
if (task.sleep > 0 && !revisiting) {
10+
setTimeout(() => this.push(task, true), task.sleep);
11+
return;
12+
}
13+
if (this.tokenLocked) {
14+
setTimeout(() => this.push(task, true), this.lockRevisitDelay);
15+
return;
16+
}
17+
if (task.startNewSession) {
18+
this.cycleToken = this.generateToken();
19+
task.token = this.cycleToken;
20+
console.log("new session", this.cycleToken);
21+
}
22+
if (task.lock) {
23+
this.tokenLocked = true;
24+
}
25+
task.execute().then((chainedTaskData) => {
26+
if (task.lock)
27+
this.unlock();
28+
if (!chainedTaskData) return;
29+
let chainedTask = chainedTaskData.task;
30+
let chainedToken = chainedTaskData.token;
31+
chainedTask.setToken(chainedToken);
32+
this.push(chainedTask);
33+
});
34+
}
35+
generateToken() {
36+
return Math.random().toString(16).slice(2);
37+
}
38+
unlock () {
39+
this.tokenLocked = false;
40+
}
41+
force(task) {
42+
task.token = this.cycleToken;
43+
this.push(task);
44+
}
45+
}
46+
47+
class ScheduledTask {
48+
constructor(func=null, args=[], token=null, lock=false, startNewSession=false, sleep=10) {
49+
this.token = token;
50+
this.startNewSession = startNewSession;
51+
this.sleep = sleep;
52+
this.func = func ? func : () => { };
53+
this.args = args;
54+
this.lock = lock;
55+
56+
}
57+
set(func, ...args) {
58+
this.func = func;
59+
this.args = args;
60+
return this;
61+
}
62+
setNewSession(bool) {
63+
this.startNewSession = bool;
64+
return this;
65+
}
66+
setLock(bool) {
67+
this.lock = bool;
68+
return this;
69+
}
70+
setSleep(ms) {
71+
this.sleep = ms;
72+
return this;
73+
}
74+
setToken(token) {
75+
this.token = token;
76+
return this;
77+
}
78+
execute() {
79+
return new Promise((resolve, reject) => {
80+
const res = this.func(...this.args);
81+
if (res instanceof ScheduledTask) {
82+
resolve({"task": res, "token": this.token});
83+
}
84+
resolve(null);
85+
});
86+
}
87+
}

0 commit comments

Comments
 (0)