-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): implement automated play
- Loading branch information
Showing
8 changed files
with
235 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { AfenPreset, Board } from '@decentm/allegiance-chess-core' | ||
import { randomBytes } from 'node:crypto' | ||
|
||
import { Bot } from '../src/engine' | ||
|
||
const b = new Board() | ||
|
||
b.importAFEN(AfenPreset.VanillaDefault) | ||
|
||
const _seed = randomBytes(8).toString('hex') | ||
|
||
console.log('Running performance benchmark...') | ||
const start = performance.now() | ||
|
||
let MOVES = 4 | ||
|
||
const history: number[] = [] | ||
|
||
const bot = new Bot() | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (MOVES > 0) { | ||
const moveStart = performance.now() | ||
|
||
const { index, score, seed } = bot.findBestMove(3, _seed) | ||
Check warning on line 25 in packages/bot/clinic/benchmark.ts GitHub Actions / lint
|
||
|
||
if (index === -1) { | ||
console.log('No moves!') | ||
break | ||
} | ||
|
||
const move = b.executeMoveIndex(index) | ||
|
||
history.push(performance.now() - moveStart) | ||
console.log('Move', MOVES, 'complete in', history.at(-1)) | ||
MOVES-- | ||
// const openings = Openings.getNamesByFen(b.toAFEN({ sections: ['positions'] })) | ||
|
||
// console.clear() | ||
// console.log(seed, Notation.writeNode(move), score, '\n') | ||
// console.log(b.toAFEN(), '\n') | ||
// console.log( | ||
// 'openings:', | ||
// openings.length < 10 ? openings.join(', ') : openings.length, | ||
// '\n' | ||
// ) | ||
// console.log(b.dump(), '\n') | ||
// console.log(b.getMoveHistory()) | ||
} | ||
|
||
console.log('Benchmark done in', performance.now() - start) | ||
console.log( | ||
'Average move time:', | ||
history.reduce((prev, cur) => prev + cur, 0) / history.length | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import test from 'ava' | ||
|
||
import { Bot } from '.' | ||
|
||
test('saves the knight', (t) => { | ||
t.timeout(Number.POSITIVE_INFINITY) | ||
|
||
const bot = new Bot() | ||
|
||
bot.board.importAFEN( | ||
'rnbqkbnr/ppppp3/8/5p>p1/6N1/7p/PPPPPP1P/RNBQKR>R1 w Qkq - 1 8' | ||
) | ||
|
||
const result = bot.findBestMove(3) | ||
|
||
t.true(result.path?.split(',')[0].startsWith('Ng4')) | ||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.