dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 3a8c6f50fe7481980a451095636009629f8a6b85
parent 57b0e46cbe45128df1aa929635549ab265bcdd23
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 15 Jun 2023 12:25:59 -0700

cleanup

Diffstat:
Mpkg/web/handlers/chess.go | 22++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go @@ -575,6 +575,18 @@ func squareCoord(sq chess.Square, isFlipped bool) (int, int) { return x, y } +func initPiecesCache(game *chess.Game) map[string]chess.Square { + piecesCache := make(map[string]chess.Square) + pos := game.Positions()[0] + for i := 0; i < 64; i++ { + sq := chess.Square(i) + if pos.Board().Piece(sq) != chess.NoPiece { + piecesCache["piece_"+sq.String()] = sq + } + } + return piecesCache +} + func ChessGameHandler(c echo.Context) error { debugChess := true @@ -606,14 +618,8 @@ func ChessGameHandler(c echo.Context) error { game := g.Game - piecesCache1 := make(map[string]chess.Square) - pos := game.Positions()[0] - for i := 0; i < 64; i++ { - sq := chess.Square(i) - if pos.Board().Piece(sq) != chess.NoPiece { - piecesCache1["piece_"+sq.String()] = sq - } - } + // Keep track of where on the board a piece was last seen + piecesCache1 := initPiecesCache(game) isFlipped := authUser.ID == g.Player2.ID