game

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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 NewGame

func NewGame() *Game

NewGame returns an initial model of the game board.

func NewGameWithPosition

func NewGameWithPosition(position string) *Game

NewGameWithPosition returns an initial model of the game board with the specified FEN position.

func (*Game) Deselect

func (m *Game) Deselect() (tea.Model, tea.Cmd)

func (*Game) Init

func (m *Game) Init() tea.Cmd

Init Initializes the model

func (*Game) Notify

func (m *Game) Notify(from, to string, turn, check, checkmate bool) tea.Cmd

func (*Game) Position

func (g *Game) Position() string

Position returns the current FEN position of the board.

func (*Game) Select

func (m *Game) Select(square string) (tea.Model, tea.Cmd)

func (*Game) SetFlipped

func (g *Game) SetFlipped(flip bool)

SetFlipped sets the board to be flipped or not.

func (*Game) Update

func (m *Game) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Game) View

func (m *Game) View() string

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

type MoveMsg

type MoveMsg struct {
	From string
	To   string
}

MoveMsg is a message that controls the board from outside the model.

type NotifyMsg

type NotifyMsg struct {
	From      string
	To        string
	Turn      bool
	Check     bool
	Checkmate bool
}

NotifyMsg is a message that gets emitted when the user makes a move.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL