Download scripts/setup-rapfi.mjs from YunkunSong/llm-gomoku-benchmark: direct link, hf CLI and curl.
- Browser
- Download file 2.14 kB
-
https://huggingface.co/datasets/YunkunSong/llm-gomoku-benchmark/resolve/main/scripts/setup-rapfi.mjs
- Command line
-
hf download hf://datasets/YunkunSong/llm-gomoku-benchmark/scripts/setup-rapfi.mjs
-
curl -L -o setup-rapfi.mjs https://huggingface.co/datasets/YunkunSong/llm-gomoku-benchmark/resolve/main/scripts/setup-rapfi.mjs
2.14 kB
| import { spawnSync } from 'node:child_process'; | |
| import { randomUUID } from 'node:crypto'; | |
| import { mkdir, rm, writeFile } from 'node:fs/promises'; | |
| import { dirname, join } from 'node:path'; | |
| import { | |
| createRapfi, | |
| RAPFI_ARCHIVE_SHA256, | |
| RAPFI_DIR, | |
| RAPFI_FILES, | |
| RAPFI_TAG, | |
| RAPFI_URL, | |
| sha256, | |
| verifyRapfiInstall, | |
| } from '../src/rapfi.mjs'; | |
| async function install() { | |
| if (process.platform !== 'win32' || process.arch !== 'x64') { | |
| throw new Error('此安装程序支持 Windows x64 的 AVX2 版 Rapfi。'); | |
| } | |
| const installed = await verifyRapfiInstall().then(() => true, () => false); | |
| if (!installed) { | |
| await mkdir(RAPFI_DIR, { recursive: true }); | |
| const archivePath = join(dirname(RAPFI_DIR), 'Rapfi-' + RAPFI_TAG + '-' + randomUUID() + '.7z'); | |
| const response = await fetch(RAPFI_URL, { signal: AbortSignal.timeout(120_000) }); | |
| if (!response.ok) throw new Error('Rapfi 下载失败,HTTP ' + response.status); | |
| const bytes = Buffer.from(await response.arrayBuffer()); | |
| if (sha256(bytes) !== RAPFI_ARCHIVE_SHA256) throw new Error('Rapfi 官方压缩包校验失败。'); | |
| try { | |
| await writeFile(archivePath, bytes, { flag: 'wx' }); | |
| const extraction = spawnSync('tar.exe', [ | |
| '-xf', archivePath, '-C', RAPFI_DIR, ...Object.keys(RAPFI_FILES), | |
| ], { windowsHide: true, encoding: 'utf8', timeout: 30_000 }); | |
| if (extraction.error || extraction.status !== 0) { | |
| throw extraction.error ?? new Error(extraction.stderr || 'Rapfi 解压失败。'); | |
| } | |
| await verifyRapfiInstall(); | |
| } finally { | |
| await rm(archivePath, { force: true }); | |
| } | |
| } | |
| const engine = await createRapfi({ directory: RAPFI_DIR, maxNodes: 5_000 }); | |
| try { | |
| const result = await engine.evaluate({ moves: ['H8', 'I9', 'I8'], color: 2, played: 'O15' }); | |
| console.log('Rapfi ' + engine.metadata.version + ' 已就绪。'); | |
| console.log('Renju 检查:推荐 ' + result.bestMove + ',实下 O15 已成功复评。'); | |
| } finally { | |
| await engine.close(); | |
| } | |
| } | |
| try { | |
| await install(); | |
| } catch (error) { | |
| console.error(error.message); | |
| process.exitCode = 1; | |
| } | |