ChessBuilder/Assets/ChessEngines/fairy-chess-server/variants.js
2025-03-14 00:51:53 -05:00

87 lines
No EOL
2 KiB
JavaScript

import fs from 'fs'
const pieceSetups = [
"nk", // 2 cells
"nkr", // 3 cells
"nkbr", // 4 cells
"rnkbr", // 5 cells
"rbnkqr", // 6 cells
"rnbkqnr", // 7 cells
"rnbqkbnr", // 8 cells (standard chess)
"rbnqknbnr", // 9 cells
"rnbnqknbnr", // 10 cells
"rnbnqknbnnr", // 11 cells
"rnnbnqknbnnr" // 12 cells
];
const files = "abcdefghijkl";
function generateVariant(width, height) {
if (width < 2 || width > 12) {
console.error("Width must be between 2 and 12");
return "";
}
if (height < 6 || height > 12) {
console.error("Height must be between 6 and 12");
return "";
}
const pieceSetup = pieceSetups[width - 2];
const emptyRanks = height - 4;
const whitePieces = pieceSetup.toUpperCase();
const blackPieces = pieceSetup.toLowerCase();
const whitePawns = "P".repeat(width);
const blackPawns = "p".repeat(width);
const emptyRank = width.toString();
let fenParts = [blackPieces, blackPawns];
for (let i = 0; i < emptyRanks; i++) {
fenParts.push(emptyRank);
}
fenParts.push(whitePawns, whitePieces);
const fen = fenParts.join("/") + " w - - 0 1";
const maxFile = files[width - 1];
return `[chessbuilder${width}x${height}:chess]
pieceToCharTable = PNBRQK..*@...........pnbrqk..*@...........
maxRank = ${height}
maxFile = ${maxFile}
startFen = ${fen}
walltype = * # Duck wall
walltype = @ # Stone wall
wallingRule = static
wallOrMove = false
mobilityRegion = *:@
prohibitedMove = *@
`;
}
function generateAllVariants() {
let allVariants = "";
let count = 0;
for (let height = 6; height <= 12; height++) {
for (let width = 2; width <= 12; width++) {
const variant = generateVariant(width, height);
allVariants += variant + "\n";
count++;
}
}
fs.writeFileSync('chessbuilder_variants.ini', allVariants);
console.log(`Generated ${count} variants and saved to chessbuilder_variants.ini`);
return allVariants;
}
generateAllVariants();