chess4js 1.0.0-beta.8 → 1.0.0-beta.9
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.
- package/README.md +114 -112
- package/chess4js.d.mts +3 -1
- package/chess4js.mjs +2294 -2239
- package/chess4js.mjs.map +1 -1
- package/kotlin-kotlin-stdlib.mjs +2208 -1445
- package/kotlin-kotlin-stdlib.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ hundred milliseconds on modern machines.
|
|
|
27
27
|
The library provides predefined instances for every square (A1, B1, ..., H8). You can import them directly:
|
|
28
28
|
|
|
29
29
|
```js
|
|
30
|
-
import {
|
|
30
|
+
import {A1, G4, D6} from "chess4js";
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
## Piece
|
|
@@ -56,7 +56,7 @@ import {WP, BK, WQ, BN} from "chess4js"
|
|
|
56
56
|
exist: `WHITE` and `BLACK`. You can import them directly:
|
|
57
57
|
|
|
58
58
|
```js
|
|
59
|
-
import {
|
|
59
|
+
import {WHITE, BLACK} from "chess4js"
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
## Bitboard
|
|
@@ -118,7 +118,7 @@ A non directly instantiable class that represents a move made on the board.
|
|
|
118
118
|
### Example
|
|
119
119
|
|
|
120
120
|
```js
|
|
121
|
-
import {
|
|
121
|
+
import {moveOf} from "chess4js"
|
|
122
122
|
|
|
123
123
|
const myMove = moveOf("e2e4");
|
|
124
124
|
```
|
|
@@ -129,9 +129,9 @@ Represents a specific board state. Instances of this class are immutable. Modify
|
|
|
129
129
|
inconsistent behavior. Use factory methods to generate new positions.
|
|
130
130
|
|
|
131
131
|
```js
|
|
132
|
-
import {
|
|
132
|
+
import {startpos, positionOf} from "chess4js"
|
|
133
133
|
|
|
134
|
-
const initialPosition = startpos();
|
|
134
|
+
const initialPosition = startpos();
|
|
135
135
|
const somePosition = positionOf("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
|
136
136
|
|
|
137
137
|
```
|
|
@@ -177,6 +177,7 @@ const somePosition = positionOf("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w K
|
|
|
177
177
|
| `moveFromString` | `move`: `String`, `notation`: `Notation` default `UCI` | `Position` | Retrieves the new Position that results from executing the move specified in the given notation. Throws a MoveException if the move is not legal. If no notation is provided, UCI notation is assumed. |
|
|
178
178
|
| `toString` | None | `string` | retrieves a nice string representation |
|
|
179
179
|
| `flipSide` | None | `Position` | Creates a new Position identical to the current one, but with the active side toggled. |
|
|
180
|
+
| `transpositionId` | None | `String` | Generates a unique string identifier for the current position, suitable for use as a key in a transposition table. |
|
|
180
181
|
|
|
181
182
|
### Factories
|
|
182
183
|
|
|
@@ -247,6 +248,7 @@ For the `Node` class:
|
|
|
247
248
|
| `endLineComment` | `Nullable<string>` | The end-of-line comment for the node, which follows a semicolon ; and goes until the end of the line. |
|
|
248
249
|
| `suffixAnnotations` | `Nullable<ReadonlyArray<number>>` | The list of suffix annotations (NAGs) for the node. |
|
|
249
250
|
| `parent` | `Nullable<Node>` | The parent node. It can only be null when it is the root node, which evidently cannot have a parent. |
|
|
251
|
+
| `id` | `number` | An id for the node. |
|
|
250
252
|
|
|
251
253
|
### Methods
|
|
252
254
|
|
|
@@ -288,7 +290,7 @@ For the `Node` class
|
|
|
288
290
|
### Example
|
|
289
291
|
|
|
290
292
|
```js
|
|
291
|
-
import {
|
|
293
|
+
import {strictMatch} from "chess4js";
|
|
292
294
|
|
|
293
295
|
const myGame = strictMatch(() => "someId");
|
|
294
296
|
myGame.setTag("white", "foo")
|
|
@@ -298,12 +300,12 @@ myGame.setTag("site", "foobared place")
|
|
|
298
300
|
myGame.setTag("date", "1999.06.10")
|
|
299
301
|
|
|
300
302
|
myGame.root.appendMove("e4")
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
303
|
+
.appendMove("e5")
|
|
304
|
+
.appendMove("Bc4")
|
|
305
|
+
.appendMove("Nc6")
|
|
306
|
+
.appendMove("Qh5")
|
|
307
|
+
.appendMove("Nf6")
|
|
308
|
+
.appendMove("Qxf7#")
|
|
307
309
|
|
|
308
310
|
```
|
|
309
311
|
|
|
@@ -321,7 +323,7 @@ A non-instantiable class that provides basic information about ECO classificatio
|
|
|
321
323
|
### Example
|
|
322
324
|
|
|
323
325
|
```javascript
|
|
324
|
-
import {
|
|
326
|
+
import {strictMatch} from "chess4js";
|
|
325
327
|
|
|
326
328
|
const myGame = strictMatch(() => "someId");
|
|
327
329
|
myGame.setTag("white", "foo")
|
|
@@ -331,14 +333,14 @@ myGame.setTag("site", "foobared place")
|
|
|
331
333
|
myGame.setTag("date", "1999.06.10")
|
|
332
334
|
|
|
333
335
|
myGame.root.appendMove("e4")
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
336
|
+
.appendMove("c5")
|
|
337
|
+
.appendMove("Nf3")
|
|
338
|
+
.appendMove("e6")
|
|
339
|
+
.appendMove("d4")
|
|
340
|
+
.appendMove("cxd4")
|
|
341
|
+
.appendMove("Nxd4")
|
|
342
|
+
.appendMove("Qb6")
|
|
343
|
+
|
|
342
344
|
const ecoInfo = myGame.ecoInfo.eco // "B40"
|
|
343
345
|
```
|
|
344
346
|
|
|
@@ -368,9 +370,9 @@ Represents a score in a tournament. It can't be directly instantiated, you need
|
|
|
368
370
|
#### Example
|
|
369
371
|
|
|
370
372
|
```javascript
|
|
371
|
-
import {
|
|
373
|
+
import {scoreOf} from "chess4js";
|
|
372
374
|
|
|
373
|
-
const hightScore = scoreOf("2.5");
|
|
375
|
+
const hightScore = scoreOf("2.5");
|
|
374
376
|
const lowScore = scoreOf("0.0");
|
|
375
377
|
|
|
376
378
|
hightScore.compareTo(lowScore) // 1
|
|
@@ -404,7 +406,7 @@ factory.
|
|
|
404
406
|
#### Example
|
|
405
407
|
|
|
406
408
|
```javascript
|
|
407
|
-
import {
|
|
409
|
+
import {playerOf} from "chess4js";
|
|
408
410
|
|
|
409
411
|
const foo = playerOf("foo", 1600);
|
|
410
412
|
const bar = playerOf("bar", 1600);
|
|
@@ -432,7 +434,7 @@ factory.
|
|
|
432
434
|
#### Example
|
|
433
435
|
|
|
434
436
|
```javascript
|
|
435
|
-
import {
|
|
437
|
+
import {matchOf, playerOf} from "chess4js";
|
|
436
438
|
|
|
437
439
|
const white = playerOf("foo", 1600);
|
|
438
440
|
const black = playerOf("bar", 1600);
|
|
@@ -482,74 +484,74 @@ behavior of a Swiss tournament, having a fixed number of rounds, for example. Ad
|
|
|
482
484
|
before the next one can be generated.
|
|
483
485
|
|
|
484
486
|
```javascript
|
|
485
|
-
import {
|
|
487
|
+
import {tournament, playerOf} from "./chess4js.mjs";
|
|
486
488
|
|
|
487
489
|
const myTournament = tournament("swiss");
|
|
488
490
|
|
|
489
491
|
function randomInt(min, max) {
|
|
490
|
-
|
|
492
|
+
return Math.floor(Math.random() * (max - min) + min);
|
|
491
493
|
}
|
|
492
494
|
|
|
493
495
|
function runMatch(match) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
} else {
|
|
505
|
-
if (random < ratio) {
|
|
506
|
-
match.outcome = "0-1";
|
|
507
|
-
} else if (random == ratio) {
|
|
508
|
-
match.outcome = "1/2-1/2";
|
|
496
|
+
const ratio = (match.white.currentElo - match.black.currentElo) / 100;
|
|
497
|
+
const random = Math.random();
|
|
498
|
+
if (match.white.currentElo >= match.black.currentElo) {
|
|
499
|
+
if (random < ratio) {
|
|
500
|
+
match.outcome = "1-0";
|
|
501
|
+
} else if (random == ratio) {
|
|
502
|
+
match.outcome = "1/2-1/2";
|
|
503
|
+
} else {
|
|
504
|
+
match.outcome = "0-1";
|
|
505
|
+
}
|
|
509
506
|
} else {
|
|
510
|
-
|
|
507
|
+
if (random < ratio) {
|
|
508
|
+
match.outcome = "0-1";
|
|
509
|
+
} else if (random == ratio) {
|
|
510
|
+
match.outcome = "1/2-1/2";
|
|
511
|
+
} else {
|
|
512
|
+
match.outcome = "1-0";
|
|
513
|
+
}
|
|
511
514
|
}
|
|
512
|
-
}
|
|
513
515
|
}
|
|
514
516
|
|
|
515
517
|
const minElo = 1800;
|
|
516
518
|
const maxElo = 2200;
|
|
517
519
|
|
|
518
520
|
const players = [
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
521
|
+
"William Smith",
|
|
522
|
+
"Jack Jones",
|
|
523
|
+
"Oliver Williams",
|
|
524
|
+
"Joshua Brown",
|
|
525
|
+
"Thomas Wilson",
|
|
526
|
+
"Lachlan Taylor",
|
|
527
|
+
"Cooper Johnson",
|
|
528
|
+
"Noah White",
|
|
529
|
+
"Ethan Martin",
|
|
530
|
+
"Lucas Anderson",
|
|
531
|
+
"James Thompson",
|
|
532
|
+
"Samuel Nguyen",
|
|
533
|
+
"Jacob Thomas",
|
|
534
|
+
"Liam Walker",
|
|
535
|
+
"Alexander Harris",
|
|
536
|
+
"Benjamin Lee",
|
|
535
537
|
].map((name) => {
|
|
536
|
-
|
|
538
|
+
return playerOf(name, randomInt(minElo, maxElo));
|
|
537
539
|
});
|
|
538
540
|
|
|
539
541
|
players.forEach((player) => {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
+
console.log(`adding player ${player.toString()}`);
|
|
543
|
+
myTournament.addPlayer(player);
|
|
542
544
|
});
|
|
543
545
|
|
|
544
546
|
while (!myTournament.completed) {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
547
|
+
console.log("next round");
|
|
548
|
+
myTournament.nextRound().forEach((match) => {
|
|
549
|
+
runMatch(match);
|
|
550
|
+
console.log(`${match.toString()}`);
|
|
551
|
+
});
|
|
550
552
|
}
|
|
551
553
|
|
|
552
|
-
console.log(myTournament.leaderboard.map(
|
|
554
|
+
console.log(myTournament.leaderboard.map(e => e.toString() + ` - ${e.score.toString()}`));
|
|
553
555
|
```
|
|
554
556
|
|
|
555
557
|
*Creating an arena tournament*
|
|
@@ -561,83 +563,83 @@ is only intended to show the class's behavior when used in arena mode; it is not
|
|
|
561
563
|
management of an arena tournament, which is typically more complex.
|
|
562
564
|
|
|
563
565
|
```javascript
|
|
564
|
-
import {
|
|
566
|
+
import {tournament, playerOf} from "./chess4js.mjs";
|
|
565
567
|
|
|
566
568
|
const myTournament = tournament("arena");
|
|
567
569
|
|
|
568
570
|
function randomInt(min, max) {
|
|
569
|
-
|
|
571
|
+
return Math.floor(Math.random() * (max - min) + min);
|
|
570
572
|
}
|
|
571
573
|
|
|
572
574
|
function runMatch(match) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
} else {
|
|
584
|
-
if (random < ratio) {
|
|
585
|
-
match.outcome = "0-1";
|
|
586
|
-
} else if (random == ratio) {
|
|
587
|
-
match.outcome = "1/2-1/2";
|
|
575
|
+
const ratio = (match.white.currentElo - match.black.currentElo) / 100;
|
|
576
|
+
const random = Math.random();
|
|
577
|
+
if (match.white.currentElo >= match.black.currentElo) {
|
|
578
|
+
if (random < ratio) {
|
|
579
|
+
match.outcome = "1-0";
|
|
580
|
+
} else if (random == ratio) {
|
|
581
|
+
match.outcome = "1/2-1/2";
|
|
582
|
+
} else {
|
|
583
|
+
match.outcome = "0-1";
|
|
584
|
+
}
|
|
588
585
|
} else {
|
|
589
|
-
|
|
586
|
+
if (random < ratio) {
|
|
587
|
+
match.outcome = "0-1";
|
|
588
|
+
} else if (random == ratio) {
|
|
589
|
+
match.outcome = "1/2-1/2";
|
|
590
|
+
} else {
|
|
591
|
+
match.outcome = "1-0";
|
|
592
|
+
}
|
|
590
593
|
}
|
|
591
|
-
}
|
|
592
594
|
}
|
|
593
595
|
|
|
594
596
|
const minElo = 1800;
|
|
595
597
|
const maxElo = 2200;
|
|
596
598
|
|
|
597
599
|
const players = [
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
600
|
+
"William Smith",
|
|
601
|
+
"Jack Jones",
|
|
602
|
+
"Oliver Williams",
|
|
603
|
+
"Joshua Brown",
|
|
604
|
+
"Thomas Wilson",
|
|
605
|
+
"Lachlan Taylor",
|
|
606
|
+
"Cooper Johnson",
|
|
607
|
+
"Noah White",
|
|
608
|
+
"Ethan Martin",
|
|
609
|
+
"Lucas Anderson",
|
|
610
|
+
"James Thompson",
|
|
611
|
+
"Samuel Nguyen",
|
|
612
|
+
"Jacob Thomas",
|
|
613
|
+
"Liam Walker",
|
|
614
|
+
"Alexander Harris",
|
|
615
|
+
"Benjamin Lee",
|
|
614
616
|
].map((name) => {
|
|
615
|
-
|
|
617
|
+
return playerOf(name, randomInt(minElo, maxElo));
|
|
616
618
|
});
|
|
617
619
|
|
|
618
620
|
players.forEach((player) => {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
+
console.log(`adding player ${player.toString()}`);
|
|
622
|
+
myTournament.addPlayer(player);
|
|
621
623
|
});
|
|
622
624
|
|
|
623
625
|
const gamesLimit = 100;
|
|
624
626
|
|
|
625
627
|
let gamesQueue = [];
|
|
626
628
|
|
|
627
|
-
while((myTournament.finishedMatches.length + myTournament.activeMatches.length) < gamesLimit) {
|
|
629
|
+
while ((myTournament.finishedMatches.length + myTournament.activeMatches.length) < gamesLimit) {
|
|
628
630
|
myTournament.nextRound();
|
|
629
|
-
myTournament.activeMatches.forEach(
|
|
631
|
+
myTournament.activeMatches.forEach((match) => gamesQueue.push(match))
|
|
630
632
|
if (gamesQueue.length > 0) {
|
|
631
|
-
for(let i = 0; i < (gamesQueue.length / 4 * 3); i++) {
|
|
633
|
+
for (let i = 0; i < (gamesQueue.length / 4 * 3); i++) {
|
|
632
634
|
runMatch(gamesQueue.pop());
|
|
633
635
|
}
|
|
634
636
|
}
|
|
635
637
|
gamesQueue = [];
|
|
636
638
|
}
|
|
637
639
|
|
|
638
|
-
myTournament.activeMatches.forEach(
|
|
640
|
+
myTournament.activeMatches.forEach((match) => runMatch(match));
|
|
639
641
|
|
|
640
642
|
myTournament.completed = true;
|
|
641
643
|
|
|
642
|
-
console.log(myTournament.leaderboard.map(
|
|
644
|
+
console.log(myTournament.leaderboard.map(e => e.toString() + ` - ${e.score.toString()}`));
|
|
643
645
|
```
|
package/chess4js.d.mts
CHANGED
|
@@ -72,7 +72,7 @@ export declare class Game {
|
|
|
72
72
|
toAnalysis(idSupplier?: () => Nullable<any>): Game;
|
|
73
73
|
deleteFromExclusive(node: Node): Node;
|
|
74
74
|
deleteFromInclusive(node: Node): Node;
|
|
75
|
-
deleteBefore(
|
|
75
|
+
deleteBefore(node: Node): Node;
|
|
76
76
|
updateEco(): void;
|
|
77
77
|
}
|
|
78
78
|
/** @deprecated $metadata$ is used for internal purposes, please don't use it in your code, because it can be removed at any moment */
|
|
@@ -107,6 +107,7 @@ export declare namespace Move.$metadata$ {
|
|
|
107
107
|
}
|
|
108
108
|
export declare class Node {
|
|
109
109
|
private constructor();
|
|
110
|
+
get id(): number;
|
|
110
111
|
get position(): Position;
|
|
111
112
|
get move(): Nullable<Move>;
|
|
112
113
|
get children(): ReadonlyArray<Node>;
|
|
@@ -244,6 +245,7 @@ export declare class Position {
|
|
|
244
245
|
move(move: Move): Position;
|
|
245
246
|
moveFromString(move: string, notation?: Notation): Position;
|
|
246
247
|
flipSide(): Position;
|
|
248
|
+
transpositionId(): string;
|
|
247
249
|
hashCode(): number;
|
|
248
250
|
equals(other: Nullable<any>): boolean;
|
|
249
251
|
toString(): string;
|