Slide 16
Slide 16 text
駒の可動域の表示: 掴んだ駒の可動域selectorの書込み
{
board: [
[“!香”, “!桂”, …, “!桂”, “!香”],
[“”, “!飛”, …, “馬”, “”],
…
[“”, “”, …, “飛”, “”],
[“香”, “桂”, … “桂”, “香”],
],
// mochigoma: (今回は省略),
history: [
“77->76”,
“33->34”,
“88->22 nari”
]
} satisfies Shogi
// 棋譜状態
let shogiState = atom({...})
// 掴んだ座標
let selectedPosState = atom({...})
// 掴んだ駒の可動域リスト
let movableState = selector({
key: "movableState",
get: ({ get }) => {
let {board} = get(shogiState)
let pos = get(selectedPosState)
return calculateMovable(board, pos)
}
})
// 駒コンポーネント
let Koma = ({x, y}: Pos) => {
let {board} = useRecoilValue(shogiState)
let movables = useRecoilValue(movableState)
let setSelectedPos =
useSetRecoilValue(selectedPosState)
return setSelectedPos({x, y})}>
{board[x][y]}
}