dkforest

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

commit 1774f2738d1d9cab57ce6ef6a9f383a15bd95877
parent 81d83fd7bb46de5f36c9db0f95d8d2574ac49760
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat, 17 Jun 2023 17:05:38 -0700

simplify code

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

diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -712,13 +712,17 @@ func (b *Chess) SendMove(gameKey string, userID database.UserID, g *ChessGame, c fst := selectedSquares[0] scd := selectedSquares[1] + compareSquares := func(sq1, sq2 chess.Square, move *chess.Move) bool { + return (sq1 == move.S1() && sq2 == move.S2()) || + (sq1 == move.S2() && sq2 == move.S1()) + } + var moveStr string validMoves := game.Position().ValidMoves() var found bool var mov chess.Move for _, move := range validMoves { - if (move.S1() == fst && move.S2() == scd && (move.Promo() == chess.NoPieceType || move.Promo() == promo)) || - (move.S1() == scd && move.S2() == fst && (move.Promo() == chess.NoPieceType || move.Promo() == promo)) { + if compareSquares(fst, scd, move) && (move.Promo() == chess.NoPieceType || move.Promo() == promo) { moveStr = chess.AlgebraicNotation{}.Encode(game.Position(), move) found = true mov = *move