summaryrefslogtreecommitdiff
path: root/pkg/ui/views/game_moves.go
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-04-17 16:11:34 +0200
committerSanto Cariotti <santo@dcariotti.me>2025-04-17 16:11:34 +0200
commit95da822f025b544f700729afc676ba0f3c981154 (patch)
tree89b07c3a4e8797e67cb08e8f6603b7e7eae3b0e1 /pkg/ui/views/game_moves.go
parent56c7e99b59a52f19598d33a46aea0516bd4d609f (diff)
Outcome for a game
Diffstat (limited to 'pkg/ui/views/game_moves.go')
-rw-r--r--pkg/ui/views/game_moves.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/pkg/ui/views/game_moves.go b/pkg/ui/views/game_moves.go
index de2ef94..2fa7c9e 100644
--- a/pkg/ui/views/game_moves.go
+++ b/pkg/ui/views/game_moves.go
@@ -6,6 +6,7 @@ import (
"github.com/boozec/rahanna/internal/network"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
+ "github.com/notnil/chess"
)
// UpdateMovesListMsg is a message to update the moves list
@@ -44,9 +45,13 @@ func (m GameModel) handleUpdateMovesListMsg() GameModel {
if m.isMyTurn() && m.game != nil {
var items []list.Item
for _, move := range m.chessGame.ValidMoves() {
+ var promo string
+ if move.Promo().String() != "" {
+ promo = " " + move.Promo().String()
+ }
items = append(
items,
- item{title: fmt.Sprintf("%s → %s", move.S1().String(), move.S2().String())},
+ item{title: fmt.Sprintf("%s → %s%s", move.S1().String(), move.S2().String(), promo)},
)
}
m.availableMovesList.SetItems(items)
@@ -60,12 +65,18 @@ func (m GameModel) handleUpdateMovesListMsg() GameModel {
}
func (m GameModel) handleChessMoveMsg(msg ChessMoveMsg) (GameModel, tea.Cmd) {
- m.turn++
err := m.chessGame.MoveStr(string(msg))
+ cmds := []tea.Cmd{m.getMoves(), m.updateMovesListCmd()}
if err != nil {
m.err = err
} else {
+ m.turn++
m.err = nil
}
- return m, tea.Batch(m.getMoves(), m.updateMovesListCmd())
+
+ if m.chessGame.Outcome() != chess.NoOutcome {
+ cmds = append(cmds, m.endGame())
+ }
+
+ return m, tea.Batch(cmds...)
}