commit b19e01ab9718b3c28d9b82050818be72d2a2667a
parent 2774374e8315ddbbe530f724c758096833bfc274
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 30 May 2023 23:25:19 -0700
chess promotion
Diffstat:
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/pkg/web/handlers/api/v1/chess.go b/pkg/web/handlers/api/v1/chess.go
@@ -298,6 +298,13 @@ func (g *ChessGame) DrawPlayerCard(roomName string, inChat, isBlack, isYourTurn
<input type="hidden" name="message" value="/pm {{ .Username }} /c move" />
{{ end }}
<button type="submit">Move</button>
+ <span style="color: white; margin-left: 20px;">Promo:</span>
+ <select name="promotion">
+ <option value="queen">Queen</option>
+ <option value="rook">Rook</option>
+ <option value="knight">Knight</option>
+ <option value="bishop">Bishop</option>
+ </select>
</form>
{{ else }}
<div style="width: 360px; height: 360px; background-image: url(data:image/png;base64,{{ .ImgB64 }})"></div>
@@ -445,12 +452,24 @@ func (b *Chess) SendMove(gameKey string, userID database.UserID, g *ChessGame, c
return errors.New("must select 2 squares")
}
+ promo := chess.Queen
+ switch c.Request().PostFormValue("promotion") {
+ case "queen":
+ promo = chess.Queen
+ case "rook":
+ promo = chess.Rook
+ case "knight":
+ promo = chess.Knight
+ case "bishop":
+ promo = chess.Bishop
+ }
+
var moveStr string
validMoves := g.Game.Position().ValidMoves()
var found bool
for _, move := range validMoves {
- if (move.S1() == selectedSquares[0] && move.S2() == selectedSquares[1]) ||
- (move.S1() == selectedSquares[1] && move.S2() == selectedSquares[0]) {
+ if (move.S1() == selectedSquares[0] && move.S2() == selectedSquares[1] && (move.Promo() == chess.NoPieceType || move.Promo() == promo)) ||
+ (move.S1() == selectedSquares[1] && move.S2() == selectedSquares[0] && (move.Promo() == chess.NoPieceType || move.Promo() == promo)) {
moveStr = chess.AlgebraicNotation{}.Encode(g.Game.Position(), move)
found = true
break