kaorahi / lizgoban

Leela Zero & KataGo visualizer
GNU General Public License v3.0
169 stars 28 forks source link

Support saving part of the board #114

Closed qcgm1978 closed 7 months ago

qcgm1978 commented 7 months ago

Can utilize the implemented ALT key selection function of part of the chessboard to support saving the selected content. For example, when saving the file, if an area is selected, save the area. The core code and video demonstration are as follows:

https://github.com/kaorahi/lizgoban/assets/3024299/9c4a5db0-a7d4-4f63-9a8a-05318c1dd361

function get_sgf_str({ board, size, coord_signs }) {
    if (!size) {
        size = get_board_size(board)
    }
    if (!coord_signs) {
        coord_signs = [0, 0]
    }
    const num = board.flat().filter(s => s.stone_color != 'empty').length
    const to_play = num % 2 ? 'W' : 'B'
    const sgfpos_name = "abcdefghijklmnopqrs"
    const header = `(;SZ[${size}]PL[${to_play}]`, footer = ')'
    const sgfpos = (k, sign) => sgfpos_name[sign > 0 ? k : size - k - 1]
    const [sj, si] = coord_signs
    const coords = (i, j) => '[' + sgfpos(j, sj) + sgfpos(i, si) + ']'
    const grids = board.flatMap((row, i) => row.map(({ stone_color }, j) => [stone_color, i, j]))
    const body = (color, prop) => {
        const s = grids.map(([c, i, j]) => (c === color ? coords(i, j) : '')).join('')
        return (s === '') ? '' : (prop + s)
    }
    const s = header + body('black', 'AB') + body('white', 'AW') + footer
    return s
}
kaorahi commented 7 months ago

Hmm, this feature seems more fitting for SGF editor apps rather than for AI analysis apps.

I'm not aiming to create an almighty Go tool in this project. Specifically, I've consciously chosen not to implement a full-featured SGF viewer/editor, game collection manager, etc.

You may prefer q5Go, that has almost everything one will expect of Go tools!

qcgm1978 commented 7 months ago

Cool. I think I'm finding such tool you mentioned. You're right. The feature is not suitable for this project.