Documentation
¶
Index ¶
- type Game
- func (m *Game) Deselect() (tea.Model, tea.Cmd)
- func (m *Game) Init() tea.Cmd
- func (m *Game) Notify(from, to string, turn, check, checkmate bool) tea.Cmd
- func (g *Game) Position() string
- func (m *Game) Select(square string) (tea.Model, tea.Cmd)
- func (g *Game) SetFlipped(flip bool)
- func (m *Game) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m *Game) View() string
- type MoveMsg
- type NotifyMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game stores the state of the chess game.
It tracks the board, legal moves, and the selected piece. It also keeps track of the subset of legal moves for the currently selected piece
func NewGameWithPosition ¶
NewGameWithPosition returns an initial model of the game board with the specified FEN position.
func (*Game) SetFlipped ¶
SetFlipped sets the board to be flipped or not.
func (*Game) View ¶
View converts a FEN string into a human readable chess board. All pieces and empty squares are arranged in a grid-like pattern. The selected piece is highlighted and the legal moves for the selected piece are indicated by a dot (.) for empty squares. Pieces that may be captured by the selected piece are highlighted.
For example, if the user selects the white pawn on E2 we indicate that they can move to E3 and E4 legally.
┌───┬───┬───┬───┬───┬───┬───┬───┐ 8 │ ♖ │ ♘ │ ♗ │ ♕ │ ♔ │ ♗ │ ♘ │ ♖ │ ├───┼───┼───┼───┼───┼───┼───┼───┤ 7 │ ♙ │ ♙ │ ♙ │ ♙ │ ♙ │ ♙ │ ♙ │ ♙ │ ├───┼───┼───┼───┼───┼───┼───┼───┤ 6 │ │ │ │ │ │ │ │ │ ├───┼───┼───┼───┼───┼───┼───┼───┤ 5 │ │ │ │ │ │ │ │ │ ├───┼───┼───┼───┼───┼───┼───┼───┤ 4 │ │ │ │ │ . │ │ │ │ ├───┼───┼───┼───┼───┼───┼───┼───┤ 3 │ │ │ │ │ . │ │ │ │ ├───┼───┼───┼───┼───┼───┼───┼───┤ 2 │ ♟ │ ♟ │ ♟ │ ♟ │ ♟ │ ♟ │ ♟ │ ♟ │ ├───┼───┼───┼───┼───┼───┼───┼───┤ 1 │ ♜ │ ♞ │ ♝ │ ♛ │ ♚ │ ♝ │ ♞ │ ♜ │ └───┴───┴───┴───┴───┴───┴───┴───┘ A B C D E F G H