js-chess-engine 2.1.4 → 2.2.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.
- package/README.md +11 -15
- package/dist/ai/AIEngine.d.ts +17 -4
- package/dist/ai/AIEngine.d.ts.map +1 -1
- package/dist/ai/AIEngine.js +58 -10
- package/dist/ai/AIEngine.js.map +1 -1
- package/dist/ai/Evaluator.d.ts +8 -80
- package/dist/ai/Evaluator.d.ts.map +1 -1
- package/dist/ai/Evaluator.js +132 -465
- package/dist/ai/Evaluator.js.map +1 -1
- package/dist/ai/MoveOrdering.d.ts +9 -50
- package/dist/ai/MoveOrdering.d.ts.map +1 -1
- package/dist/ai/MoveOrdering.js +58 -144
- package/dist/ai/MoveOrdering.js.map +1 -1
- package/dist/ai/Search.d.ts +13 -47
- package/dist/ai/Search.d.ts.map +1 -1
- package/dist/ai/Search.js +193 -387
- package/dist/ai/Search.js.map +1 -1
- package/dist/ai/TranspositionTable.d.ts +2 -2
- package/dist/ai/TranspositionTable.d.ts.map +1 -1
- package/dist/ai/TranspositionTable.js +41 -12
- package/dist/ai/TranspositionTable.js.map +1 -1
- package/dist/core/MoveGenerator.d.ts.map +1 -1
- package/dist/core/MoveGenerator.js +97 -74
- package/dist/core/MoveGenerator.js.map +1 -1
- package/dist/core/Position.d.ts +0 -14
- package/dist/core/Position.d.ts.map +1 -1
- package/dist/core/Position.js +63 -59
- package/dist/core/Position.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -14
- package/dist/index.js.map +1 -1
- package/dist/types/ai.types.d.ts +1 -1
- package/dist/types/ai.types.d.ts.map +1 -1
- package/dist/utils/conversion.d.ts +5 -4
- package/dist/utils/conversion.d.ts.map +1 -1
- package/dist/utils/conversion.js +27 -13
- package/dist/utils/conversion.js.map +1 -1
- package/dist/utils/environment.d.ts +1 -1
- package/dist/utils/environment.d.ts.map +1 -1
- package/dist/utils/environment.js +1 -3
- package/dist/utils/environment.js.map +1 -1
- package/dist/utils/fen.d.ts.map +1 -1
- package/dist/utils/fen.js +20 -0
- package/dist/utils/fen.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|

|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
Complete TypeScript chess engine without dependencies for Node.js >=24 and browsers. Includes configurable AI with difficulty levels 1-
|
|
6
|
+
Complete TypeScript chess engine without dependencies for Node.js >=24 and browsers. Includes configurable AI with difficulty levels 1-5.
|
|
7
7
|
|
|
8
8
|
**⚠️ Upgrading from v1?** See [Breaking Changes](#breaking-changes-from-v1) section at the end of this document
|
|
9
9
|
|
|
@@ -174,7 +174,7 @@ game.removePiece('E5')
|
|
|
174
174
|
`game.aiMove(level)` - Calculate and perform the best move for the current player using AI. **Returns only the move** (v1 API compatible).
|
|
175
175
|
|
|
176
176
|
Params:
|
|
177
|
-
- `level` AILevel (_optional_) - AI difficulty level (1-
|
|
177
|
+
- `level` AILevel (_optional_) - AI difficulty level (1-5). See [Computer AI](#computer-ai) section. Default: 3
|
|
178
178
|
|
|
179
179
|
Returns: `HistoryEntry` - The played move (e.g., `{"E2": "E4"}`)
|
|
180
180
|
|
|
@@ -195,7 +195,7 @@ const board = game.exportJson()
|
|
|
195
195
|
|
|
196
196
|
Params:
|
|
197
197
|
- `options` object (_optional_) - Configuration options:
|
|
198
|
-
- `level` number (_optional_) - AI difficulty level (1-
|
|
198
|
+
- `level` number (_optional_) - AI difficulty level (1-5). See [Computer AI](#computer-ai) section. Default: `3`
|
|
199
199
|
- `play` boolean (_optional_) - Whether to apply the move to the game. Default: `true`. If `false`, returns the move without modifying the game state, and `board` will contain the current state (before the move).
|
|
200
200
|
- `ttSizeMB` number (_optional_) - Transposition table size in MB (0 to disable, 0.25-256). Default: **auto-scaled by AI level**. See [Auto-Scaling Transposition Table](#transposition-table) for details.
|
|
201
201
|
|
|
@@ -382,7 +382,7 @@ const config2: BoardConfig = move(config1, 'E7', 'E5')
|
|
|
382
382
|
|
|
383
383
|
Params:
|
|
384
384
|
- `boardConfiguration` BoardConfig | string (_mandatory_) - Board [configuration](#board-configuration)
|
|
385
|
-
- `level` AILevel (_optional_) - AI difficulty level (1-
|
|
385
|
+
- `level` AILevel (_optional_) - AI difficulty level (1-5). Default: 3
|
|
386
386
|
|
|
387
387
|
Returns: `HistoryEntry` - The played move (e.g., `{"E2": "E4"}`)
|
|
388
388
|
|
|
@@ -403,7 +403,7 @@ console.log(move) // {"E2": "E4"}
|
|
|
403
403
|
Params:
|
|
404
404
|
- `boardConfiguration` BoardConfig | string (_mandatory_) - Board [configuration](#board-configuration)
|
|
405
405
|
- `options` object (_optional_) - Configuration options:
|
|
406
|
-
- `level` number (_optional_) - AI difficulty level (1-
|
|
406
|
+
- `level` number (_optional_) - AI difficulty level (1-5). Default: `3`
|
|
407
407
|
- `play` boolean (_optional_) - Whether to apply the move to the board. Default: `true`. If `false`, returns the move without modifying the board state, and `board` will contain the current state (before the move).
|
|
408
408
|
- `ttSizeMB` number (_optional_) - Transposition table size in MB (0 to disable, 0.25-256). Default: **auto-scaled by AI level**. See [Auto-Scaling Transposition Table](#transposition-table) for details.
|
|
409
409
|
|
|
@@ -521,18 +521,17 @@ console.log(newConfig)
|
|
|
521
521
|
|
|
522
522
|
### Computer AI
|
|
523
523
|
|
|
524
|
-
The engine includes a sophisticated AI based on the Minimax algorithm with alpha-beta pruning, enhanced with advanced performance optimizations. There are
|
|
524
|
+
The engine includes a sophisticated AI based on the Minimax algorithm with alpha-beta pruning, enhanced with advanced performance optimizations. There are five difficulty levels:
|
|
525
525
|
|
|
526
526
|
| Level | Alias | Description | Search Depth |
|
|
527
527
|
| :---: | :---------------- | :----------------------------------- | :----------: |
|
|
528
528
|
| 1 | Beginner | Very weak play, minimal lookahead | 1-2 ply |
|
|
529
529
|
| 2 | Easy | Suitable for new chess players | 2-3 ply |
|
|
530
|
-
| 3 | Intermediate | Balanced difficulty (default) | 3-
|
|
531
|
-
| 4 | Advanced | Strong play with deeper search |
|
|
532
|
-
| 5 | Expert | Very strong play, deep search |
|
|
533
|
-
| 6 | Master | Maximum difficulty and search depth | 6-7 ply |
|
|
530
|
+
| 3 | Intermediate | Balanced difficulty (default) | 3-5 ply |
|
|
531
|
+
| 4 | Advanced | Strong play with deeper search | 3-6 ply |
|
|
532
|
+
| 5 | Expert | Very strong play, deep search | 4-6 ply (max) |
|
|
534
533
|
|
|
535
|
-
**Performance:** Response time increases
|
|
534
|
+
**Performance:** Response time increases with level (deeper search + larger transposition table). Exact timings vary a lot by CPU, position complexity, and cache size, so the repo includes a benchmark script—run `npm run benchmark` to measure performance on your machine.
|
|
536
535
|
|
|
537
536
|
```typescript
|
|
538
537
|
import { Game } from 'js-chess-engine'
|
|
@@ -546,7 +545,6 @@ game.aiMove(2) // Easy
|
|
|
546
545
|
game.aiMove(3) // Intermediate (default)
|
|
547
546
|
game.aiMove(4) // Advanced
|
|
548
547
|
game.aiMove(5) // Expert
|
|
549
|
-
game.aiMove(6) // Master
|
|
550
548
|
```
|
|
551
549
|
|
|
552
550
|
**Implementation Highlights:**
|
|
@@ -568,7 +566,6 @@ The engine automatically adjusts cache size based on AI level and environment:
|
|
|
568
566
|
| 3 | 8 MB | 4 MB | Balanced (default) |
|
|
569
567
|
| 4 | 16 MB | 8 MB | Strong tactical play |
|
|
570
568
|
| 5 | 32 MB | 16 MB | Very strong play |
|
|
571
|
-
| 6 | 64 MB | 32 MB | Maximum strength |
|
|
572
569
|
|
|
573
570
|
Lower levels use less memory for faster responses, higher levels use more for better move quality. Browser cache sizes are appropriate for modern devices (2024+). Override with `ttSizeMB` option if needed.
|
|
574
571
|
|
|
@@ -699,7 +696,7 @@ ai(config, 3) // Returns: { move: {"E2": "E4"}, board: {...} }
|
|
|
699
696
|
### 4. AI Difficulty Levels Changed
|
|
700
697
|
|
|
701
698
|
- **v1:** Levels 0-4 (0=easiest, 4=hardest)
|
|
702
|
-
- **v2:** Levels 1-
|
|
699
|
+
- **v2:** Levels 1-5 (1=easiest, 5=hardest)
|
|
703
700
|
|
|
704
701
|
**Migration:**
|
|
705
702
|
- Level 0 → Level 1 (Beginner)
|
|
@@ -707,7 +704,6 @@ ai(config, 3) // Returns: { move: {"E2": "E4"}, board: {...} }
|
|
|
707
704
|
- Level 2 → Level 3 (Intermediate, default)
|
|
708
705
|
- Level 3 → Level 4 (Advanced)
|
|
709
706
|
- Level 4 → Level 5 (Expert)
|
|
710
|
-
- New: Level 6 (Master)
|
|
711
707
|
|
|
712
708
|
The default level has changed from `2` to `3` to maintain similar difficulty in the middle range.
|
|
713
709
|
|
package/dist/ai/AIEngine.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { InternalBoard, InternalMove } from '../types';
|
|
|
7
7
|
import { AILevel } from '../types/ai.types';
|
|
8
8
|
/**
|
|
9
9
|
* AI difficulty level configuration
|
|
10
|
-
* Maps AI levels (1-
|
|
10
|
+
* Maps AI levels (1-5) to search depths
|
|
11
11
|
*/
|
|
12
12
|
interface LevelConfig {
|
|
13
13
|
baseDepth: number;
|
|
@@ -25,18 +25,31 @@ export declare class AIEngine {
|
|
|
25
25
|
* Find the best move for the current position
|
|
26
26
|
*
|
|
27
27
|
* @param board - Current board state
|
|
28
|
-
|
|
28
|
+
* @param level - AI difficulty level (1-5, default 3)
|
|
29
29
|
* @param ttSizeMB - Transposition table size in MB (0 to disable, 0.25-256 MB, auto-scaled by level)
|
|
30
30
|
* @returns Best move found by the AI
|
|
31
31
|
*/
|
|
32
32
|
findBestMove(board: InternalBoard, level?: AILevel, ttSizeMB?: number): InternalMove | null;
|
|
33
33
|
/**
|
|
34
|
-
|
|
34
|
+
* Get the search depth for a given AI level
|
|
35
35
|
*
|
|
36
|
-
|
|
36
|
+
* @param level - AI level (1-5)
|
|
37
37
|
* @returns Depth configuration
|
|
38
38
|
*/
|
|
39
39
|
static getLevelDepth(level: AILevel): LevelConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Adaptive depth heuristic.
|
|
42
|
+
*
|
|
43
|
+
* Contract:
|
|
44
|
+
* - Input: board + baseDepth (from level)
|
|
45
|
+
* - Output: adjusted depth (>= 1)
|
|
46
|
+
*
|
|
47
|
+
* Heuristic goals:
|
|
48
|
+
* - Never search shallower than the requested level depth.
|
|
49
|
+
* - If there are very few root legal moves (tactical / constrained), allow +1.
|
|
50
|
+
* - If the position is simplified (few pieces), allow +1 or +2.
|
|
51
|
+
*/
|
|
52
|
+
private getAdaptiveDepth;
|
|
40
53
|
}
|
|
41
54
|
export {};
|
|
42
55
|
//# sourceMappingURL=AIEngine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIEngine.d.ts","sourceRoot":"","sources":["../../src/ai/AIEngine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"AIEngine.d.ts","sourceRoot":"","sources":["../../src/ai/AIEngine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAK5C;;;GAGG;AACH,UAAU,WAAW;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACzB;AAgBD;;;GAGG;AACH,qBAAa,QAAQ;IACjB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,aAAa,CAAc;;IAMnC;;;;;;;OAOG;IACH,YAAY,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,GAAE,OAAW,EAAE,QAAQ,GAAE,MAAW,GAAG,YAAY,GAAG,IAAI;IAuBlG;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW;IAIjD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,gBAAgB;CA6B3B"}
|
package/dist/ai/AIEngine.js
CHANGED
|
@@ -7,17 +7,20 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.AIEngine = void 0;
|
|
9
9
|
const Search_1 = require("./Search");
|
|
10
|
+
const MoveGenerator_1 = require("../core/MoveGenerator");
|
|
11
|
+
const types_1 = require("../types");
|
|
10
12
|
/**
|
|
11
13
|
* AI level to depth mapping
|
|
12
14
|
* Based on v1 behavior for compatibility
|
|
13
15
|
*/
|
|
14
16
|
const LEVEL_CONFIG = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
// NOTE: Depth is the single biggest speed lever.
|
|
18
|
+
// These values are intentionally conservative for browser-friendliness.
|
|
19
|
+
1: { baseDepth: 1, extendedDepth: 1 }, // Beginner
|
|
20
|
+
2: { baseDepth: 2, extendedDepth: 1 }, // Easy
|
|
21
|
+
3: { baseDepth: 3, extendedDepth: 2 }, // Intermediate (default)
|
|
22
|
+
4: { baseDepth: 3, extendedDepth: 3 }, // Advanced
|
|
23
|
+
5: { baseDepth: 4, extendedDepth: 2 }, // Expert
|
|
21
24
|
};
|
|
22
25
|
/**
|
|
23
26
|
* AI Engine class
|
|
@@ -33,7 +36,7 @@ class AIEngine {
|
|
|
33
36
|
* Find the best move for the current position
|
|
34
37
|
*
|
|
35
38
|
* @param board - Current board state
|
|
36
|
-
|
|
39
|
+
* @param level - AI difficulty level (1-5, default 3)
|
|
37
40
|
* @param ttSizeMB - Transposition table size in MB (0 to disable, 0.25-256 MB, auto-scaled by level)
|
|
38
41
|
* @returns Best move found by the AI
|
|
39
42
|
*/
|
|
@@ -45,19 +48,64 @@ class AIEngine {
|
|
|
45
48
|
}
|
|
46
49
|
// Get depth configuration for this level
|
|
47
50
|
const config = LEVEL_CONFIG[level];
|
|
51
|
+
// Pick an effective depth based on current position complexity.
|
|
52
|
+
// This keeps early/midgame conservative, but lets endgames search deeper.
|
|
53
|
+
const effectiveDepth = this.getAdaptiveDepth(board, config.baseDepth, config.extendedDepth);
|
|
48
54
|
// Perform search
|
|
49
|
-
const result = this.search.findBestMove(board,
|
|
55
|
+
const result = this.search.findBestMove(board, effectiveDepth);
|
|
50
56
|
return result ? result.move : null;
|
|
51
57
|
}
|
|
52
58
|
/**
|
|
53
|
-
|
|
59
|
+
* Get the search depth for a given AI level
|
|
54
60
|
*
|
|
55
|
-
|
|
61
|
+
* @param level - AI level (1-5)
|
|
56
62
|
* @returns Depth configuration
|
|
57
63
|
*/
|
|
58
64
|
static getLevelDepth(level) {
|
|
59
65
|
return LEVEL_CONFIG[level];
|
|
60
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Adaptive depth heuristic.
|
|
69
|
+
*
|
|
70
|
+
* Contract:
|
|
71
|
+
* - Input: board + baseDepth (from level)
|
|
72
|
+
* - Output: adjusted depth (>= 1)
|
|
73
|
+
*
|
|
74
|
+
* Heuristic goals:
|
|
75
|
+
* - Never search shallower than the requested level depth.
|
|
76
|
+
* - If there are very few root legal moves (tactical / constrained), allow +1.
|
|
77
|
+
* - If the position is simplified (few pieces), allow +1 or +2.
|
|
78
|
+
*/
|
|
79
|
+
getAdaptiveDepth(board, baseDepth, allowedExtendedDepth) {
|
|
80
|
+
// Root branching factor (legal moves only)
|
|
81
|
+
const rootMoves = (0, MoveGenerator_1.generateLegalMoves)(board).length;
|
|
82
|
+
// Material simplification proxy: count non-empty pieces.
|
|
83
|
+
// (Mailbox is Int8Array, so iterating it is cheap.)
|
|
84
|
+
let pieceCount = 0;
|
|
85
|
+
for (const p of board.mailbox) {
|
|
86
|
+
if (p !== types_1.Piece.EMPTY)
|
|
87
|
+
pieceCount++;
|
|
88
|
+
}
|
|
89
|
+
let depth = baseDepth;
|
|
90
|
+
// Simplified endgames: search deeper.
|
|
91
|
+
// 32 pieces = starting position. Kings-only = 2.
|
|
92
|
+
if (pieceCount <= 10)
|
|
93
|
+
depth += 2;
|
|
94
|
+
else if (pieceCount <= 18)
|
|
95
|
+
depth += 1;
|
|
96
|
+
// Constrained positions: deeper can be affordable and tactically valuable.
|
|
97
|
+
if (rootMoves <= 12)
|
|
98
|
+
depth += 1;
|
|
99
|
+
// Safety rails
|
|
100
|
+
if (depth < baseDepth)
|
|
101
|
+
depth = baseDepth;
|
|
102
|
+
if (depth < 1)
|
|
103
|
+
depth = 1;
|
|
104
|
+
const maxDepth = baseDepth + Math.max(0, allowedExtendedDepth);
|
|
105
|
+
if (depth > maxDepth)
|
|
106
|
+
depth = maxDepth;
|
|
107
|
+
return depth;
|
|
108
|
+
}
|
|
61
109
|
}
|
|
62
110
|
exports.AIEngine = AIEngine;
|
|
63
111
|
//# sourceMappingURL=AIEngine.js.map
|
package/dist/ai/AIEngine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIEngine.js","sourceRoot":"","sources":["../../src/ai/AIEngine.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAIH,qCAAkC;
|
|
1
|
+
{"version":3,"file":"AIEngine.js","sourceRoot":"","sources":["../../src/ai/AIEngine.ts"],"names":[],"mappings":"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"}
|
package/dist/ai/Evaluator.d.ts
CHANGED
|
@@ -1,88 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Fast, deterministic evaluation.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Design goals:
|
|
5
|
+
* - Cheap (called at every leaf).
|
|
6
|
+
* - Stable (no expensive strategic features).
|
|
7
|
+
* - Returns a score from the perspective of `playerColor`.
|
|
6
8
|
*/
|
|
7
9
|
import { InternalBoard, InternalColor } from '../types';
|
|
8
10
|
import { Score } from '../types/ai.types';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
export declare const SCORE_MIN = -1000;
|
|
13
|
-
export declare const SCORE_MAX = 1000;
|
|
11
|
+
export declare const SCORE_MIN: Score;
|
|
12
|
+
export declare const SCORE_MAX: Score;
|
|
14
13
|
export declare class Evaluator {
|
|
15
|
-
|
|
16
|
-
* Evaluate a position from the perspective of the specified color
|
|
17
|
-
*
|
|
18
|
-
* @param board - Board to evaluate
|
|
19
|
-
* @param playerColor - Color to evaluate for (positive = good for this color)
|
|
20
|
-
* @param depth - Current search depth (used for mate scoring)
|
|
21
|
-
* @returns Score in centipawns (positive = good for playerColor)
|
|
22
|
-
*/
|
|
23
|
-
static evaluate(board: InternalBoard, playerColor: InternalColor, depth?: number): Score;
|
|
24
|
-
/**
|
|
25
|
-
* Evaluate rook activity
|
|
26
|
-
* Rewards rooks on open/semi-open files and 7th rank
|
|
27
|
-
*
|
|
28
|
-
* @param board - Board to evaluate
|
|
29
|
-
* @param playerColor - Color to evaluate for
|
|
30
|
-
* @returns Rook activity score
|
|
31
|
-
*/
|
|
32
|
-
private static evaluateRookActivity;
|
|
33
|
-
/**
|
|
34
|
-
* Evaluate king position in endgame
|
|
35
|
-
* In endgames, king should be centralized and active
|
|
36
|
-
*
|
|
37
|
-
* @param board - Board to evaluate
|
|
38
|
-
* @param playerColor - Color to evaluate for
|
|
39
|
-
* @returns Endgame king activity score
|
|
40
|
-
*/
|
|
41
|
-
private static evaluateEndgameKing;
|
|
42
|
-
/**
|
|
43
|
-
* Get king square for a color
|
|
44
|
-
*/
|
|
45
|
-
private static getKingSquare;
|
|
46
|
-
/**
|
|
47
|
-
* Evaluate passed pawns
|
|
48
|
-
* A passed pawn has no enemy pawns in front of it or on adjacent files
|
|
49
|
-
*
|
|
50
|
-
* @param board - Board to evaluate
|
|
51
|
-
* @param playerColor - Color to evaluate for
|
|
52
|
-
* @returns Passed pawn bonus score
|
|
53
|
-
*/
|
|
54
|
-
private static evaluatePassedPawns;
|
|
55
|
-
/**
|
|
56
|
-
* Evaluate material balance
|
|
57
|
-
*
|
|
58
|
-
* @param board - Board to evaluate
|
|
59
|
-
* @param playerColor - Color to evaluate for
|
|
60
|
-
* @returns Material score
|
|
61
|
-
*/
|
|
62
|
-
private static evaluateMaterial;
|
|
63
|
-
/**
|
|
64
|
-
* Evaluate piece-square table bonuses
|
|
65
|
-
*
|
|
66
|
-
* @param board - Board to evaluate
|
|
67
|
-
* @param playerColor - Color to evaluate for
|
|
68
|
-
* @returns Positional score
|
|
69
|
-
*/
|
|
70
|
-
private static evaluatePieceSquareTables;
|
|
71
|
-
/**
|
|
72
|
-
* Evaluate castling status
|
|
73
|
-
* Rewards having castled, which is a key strategic concept
|
|
74
|
-
*
|
|
75
|
-
* @param board - Board to evaluate
|
|
76
|
-
* @param playerColor - Color to evaluate for
|
|
77
|
-
* @returns Castling bonus score
|
|
78
|
-
*/
|
|
79
|
-
private static evaluateCastling;
|
|
80
|
-
/**
|
|
81
|
-
* Get total material value on the board (used for endgame detection)
|
|
82
|
-
*
|
|
83
|
-
* @param board - Board to evaluate
|
|
84
|
-
* @returns Total material value
|
|
85
|
-
*/
|
|
86
|
-
static getTotalMaterialValue(board: InternalBoard): number;
|
|
14
|
+
static evaluate(board: InternalBoard, playerColor: InternalColor, plyFromRoot?: number): Score;
|
|
87
15
|
}
|
|
88
16
|
//# sourceMappingURL=Evaluator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Evaluator.d.ts","sourceRoot":"","sources":["../../src/ai/Evaluator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Evaluator.d.ts","sourceRoot":"","sources":["../../src/ai/Evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAS,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG1C,eAAO,MAAM,SAAS,EAAE,KAAkB,CAAC;AAC3C,eAAO,MAAM,SAAS,EAAE,KAAiB,CAAC;AAwH1C,qBAAa,SAAS;IAClB,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,GAAE,MAAU,GAAG,KAAK;CAuBpG"}
|