Public
Edited
May 27, 2023
Insert cell
Insert cell
{ // Testing
const fen = 'rnbqkbnr/pppppppp/4B12/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';
return (compressFEN(fen))
}
Insert cell
function compressFEN(fen) {
// Create an empty array to store the compressed FEN data
let compressedFEN = [];
// Split the FEN string into an array of pieces
let pieces = fen.split(' ')[0].split('/');
// Iterate over the pieces array
for (let i = 0; i < pieces.length; i++) {
// Split the row string into an array of characters
let row = pieces[i].split('');
// Iterate over the row array
for (let j = 0; j < row.length; j++) {
// Get the piece code
let pieceCode = getPieceCode(row[j]);
// Add the piece code to the array
// console.log({i,j, piece: row[j]})
if (isNaN(row[j])) {
compressedFEN.push(pieceCode);
}
}
}
console.log({compressedFEN})
// Add the separator
compressedFEN.push(0b1111);
// Iterate over the pieces array
for (let i = 0; i < pieces.length; i++) {
// Split the row string into an array of characters
let row = pieces[i].split('');
row.forEach((e,i)=>isNaN(e)?e:row[i]="1".repeat(e).split(''));
row = row.flat();
// Iterate over the row array
for (let j = 0; j < row.length; j++) {
// Get the cell code
let cellCode = getCellCode(i, j);
// Add the cell code to the array
console.log({i,j, piece: row[j], cellCode})
if (isNaN(row[j])) {
compressedFEN.push(cellCode);
}
}
}
// Return the compressed chess position
return compressedFEN;
}

Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more