Skip to content

Instantly share code, notes, and snippets.

@dolegi
Created November 20, 2019 14:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dolegi/cf9ea558df692b0e844af9c93831988b to your computer and use it in GitHub Desktop.
Fen Parser
// const fen = 'k1K5/8/8/8/8/8/8/1Q6'
const fen = '2r3k1/1q1nbppp/r3p3/3pP3/pPpP4/P1Q2N2/2RN1PPP/2R4K'
const rows = fen.split('/')
const board = []
let i = 0
rows.forEach(row => {
const squares = row.split('')
board[i] = []
squares.forEach(square => {
const asNumber = parseInt(square)
if (isNaN(asNumber)) {
board[i].push(square)
} else {
for (let j = 0; j < asNumber; j++) {
board[i].push(' ')
}
}
})
i++
})
console.log(board)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment