-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace-chess.js
More file actions
48 lines (37 loc) · 1.42 KB
/
Copy pathreplace-chess.js
File metadata and controls
48 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import fs from 'fs';
let file = fs.readFileSync('src/App.tsx', 'utf-8');
const imports = `import { Chess, Square } from 'chess.js';
import { StockfishEngine } from './StockfishEngine';
import { posToSquare, squareToPos, getBoard, PIECE_UNICODE, PieceType, Piece, Board, ChessPos } from './chessUtils';
`;
// Add imports after the last import
const lastImportIndex = file.lastIndexOf('import ');
const endOfLastImport = file.indexOf('\\n', lastImportIndex) + 1;
file = file.substring(0, endOfLastImport) + imports + file.substring(endOfLastImport);
const startMarker = "type PieceType = 'K'|'Q'|'R'|'B'|'N'|'P';";
const endMarker = "const ChessBoard = ({ ";
const startIndex = file.indexOf(startMarker);
const endIndex = file.indexOf(endMarker);
if (startIndex === -1 || endIndex === -1) {
console.error('Markers not found');
process.exit(1);
}
const newChessLogic = `
interface MoveRecord {
moveNumber: number;
player: 'w' | 'b';
from: ChessPos;
to: ChessPos;
piece: Piece;
captured: Piece | null;
fenBefore: string;
fenAfter: string;
evaluation: number;
bestMoves?: { move: string, val: number }[];
classification?: 'Brilliant' | 'Great' | 'Best' | 'Excellent' | 'Book' | 'Inaccuracy' | 'Mistake' | 'Blunder';
explanation?: string;
}
`;
file = file.substring(0, startIndex) + newChessLogic + file.substring(endIndex);
fs.writeFileSync('src/App.tsx', file);
console.log('Replaced chess logic and added imports');