game

package
v0.0.0-...-2cefbdd Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CaptureSign          = "x"
	KingCheckSign        = "+"
	CheckmateSign        = "#"
	DrawOfferMove        = "="
	DrawOfferRejectMove  = "!"
	KingSideCastligMove  = "0-0"
	QueenSideCastligMove = "0-0-0"
)
View Source
const (
	Rook   = "R"
	Knight = "N"
	Bishop = "B"
	King   = "K"
	Queen  = "Q"
	Pawn   = "P"
	Empty  = "0"
)

Variables

This section is empty.

Functions

func BlackFigure

func BlackFigure(char string) string

func BoardColumnToFile

func BoardColumnToFile(col int) string

func BoardFileToColumn

func BoardFileToColumn(char string) int

func BoardRankToRow

func BoardRankToRow(char string) int

func BoardRowToRank

func BoardRowToRank(row int) string

func ColoredFigure

func ColoredFigure(char string, isWhite bool) string

func ExecuteMove

func ExecuteMove(board *Board, move *Move, isWhite bool)

func IsFigureType

func IsFigureType(char string, fig string) bool

func IsGameWon

func IsGameWon(board *Board, isWhite bool) bool

func IsKingCheck

func IsKingCheck(board *Board, isWhite bool) bool

func IsPlayersFigure

func IsPlayersFigure(char string, isWhite bool) bool

func IsValidFigure

func IsValidFigure(char string) bool

func MakeStartingBoard

func MakeStartingBoard() string

func ValidateMove

func ValidateMove(board *Board, move *Move, isWhite bool, moveHistory *[]Move) error

func WhiteFigure

func WhiteFigure(char string) string

Types

type Board

type Board [8][8]string

type Game

type Game struct {
	Board Board
	Moves []Move
}

func MakeGame

func MakeGame(tiles string, moves []string) (*Game, error)

func (*Game) GetTiles

func (g *Game) GetTiles() string

func (*Game) MakeMove

func (g *Game) MakeMove(move string, isWhite bool) (string, bool, error)

MakeMove godoc The move parameter represents the moving of a single figure on board and should be in following format: (figure_char)(file)?(rank)?(capture_sign)?(file)(rank)(promoted_figure_char)(king_check_sign|checkmate_sign)?

The x represents that this move captures opponents figure and + at the end that this move is king check for opponent. (e.g. Qa3, Nxf3, Bxc4+, R3xa6+)

The move can also be a request for draw by containing only = (equals sign) or rejection of draw ! (exclamation mark)

This function returns following values (normalized move, is game won, error)

type Move

type Move struct {
	Figure              string
	FigureFile          string
	FigureRank          string
	DestinationFile     string
	DestinationRank     string
	PromotedToFigure    string
	IsCapture           bool
	IsKingSideCastling  bool
	IsQueenSideCastling bool
	IsKingCheck         bool
}

func (*Move) String

func (m *Move) String() string

Jump to

Keyboard shortcuts

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