summaryrefslogtreecommitdiff
path: root/public/sync_board.js
blob: 629cae6bb1377b8f47a81fb5b19873f6374ef783 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function sync_board(){
    let table = {1:'K', 2:'Q', 3:'R', 4:'B', 5:'N', 6:'p'}

    for(let i = 0; i < 8; i++){
        for(let j = 0; j < 8; j++){
            if(board[i][j] == 0) continue

            let square = document.getElementById(`${alphabet.charAt(j)}${8 - i}`)
            let piece = document.createElement('p')

            piece.classList.add(board[i][j] > 0 ? 'w' : 'b')
            square.append(piece)
            piece.append(table[Math.abs(board[i][j])])
        }
    }
}