model

package
v0.0.0-...-ed91d75 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Black is one of the two chess colors
	Black = Color(iota)
	// White is one of the two chess colors
	White = Color(iota)
)
View Source
const (
	// Rook piece type
	Rook = PieceType(iota)
	// Knight piece type
	Knight = PieceType(iota)
	// Bishop piece type
	Bishop = PieceType(iota)
	// Queen piece type
	Queen = PieceType(iota)
	// King piece type
	King = PieceType(iota)
	// Pawn piece type
	Pawn = PieceType(iota)
)

Variables

This section is empty.

Functions

func AllMoves

func AllMoves(
	board *Board, color Color, previousMove Move, previousMover *Piece,
	allThreatened bool, king *Piece,
) map[Position]bool

AllMoves get all moves for a player or all threatening moves for a player

Types

type Board

type Board [8][8]*Piece

Board is a chess board of pieces

func (Board) Piece

func (board Board) Piece(pos Position) *Piece

Piece get a piece from the board

func (Board) String

func (board Board) String() string

type Color

type Color uint8

Color of a piece or player

type Game

type Game struct {
	// contains filtered or unexported fields
}

Game is a struct representing a chess game

func NewCustomGame

func NewCustomGame(serializableBoard SerializableBoard,
	blackKing Piece, whiteKing Piece, positionHistory map[string]uint8,
	blackPieces map[PieceType]uint8, whitePieces map[PieceType]uint8,
	turn Color, gameOver bool, result GameResult, previousMove Move,
	previousMover Piece, turnsSinceCaptureOrPawnMove uint8) *Game

NewCustomGame create a new custom game

func NewGame

func NewGame() *Game

NewGame create a new game

func NewGameNoPawns

func NewGameNoPawns() *Game

NewGameNoPawns create a new game with no pawns

func (*Game) BlackKing

func (game *Game) BlackKing() *Piece

BlackKing get the game's black king

func (*Game) BlackPieces

func (game *Game) BlackPieces() map[PieceType]uint8

BlackPieces get the game's black pieces

func (*Game) BoardString

func (game *Game) BoardString() string

BoardString get the board's string

func (*Game) GameOver

func (game *Game) GameOver() bool

GameOver get whether the game is over

func (*Game) GetBoard

func (game *Game) GetBoard() *Board

GetBoard get the game's board

func (*Game) GetSerializableBoard

func (game *Game) GetSerializableBoard() SerializableBoard

GetSerializableBoard get the game's board

func (*Game) MarshalBinary

func (game *Game) MarshalBinary() (data []byte, err error)

MarshalBinary represent the game as a byte array

func (*Game) Move

func (game *Game) Move(moveRequest MoveRequest) error

Move make a move

func (*Game) OnlyKing

func (game *Game) OnlyKing(color Color) bool

OnlyKing returns if the player has only a king

func (*Game) PointAdvantage

func (game *Game) PointAdvantage(color Color) int8

PointAdvantage get the color's point advantage

func (*Game) PositionHistory

func (game *Game) PositionHistory() map[string]uint8

PositionHistory get the game's position history

func (*Game) PreviousMove

func (game *Game) PreviousMove() Move

PreviousMove get the game's previous move

func (*Game) PreviousMover

func (game *Game) PreviousMover() *Piece

PreviousMover get the game's previous mover

func (*Game) Result

func (game *Game) Result() GameResult

Result get the game's result

func (*Game) SetGameResult

func (game *Game) SetGameResult(winner Color, draw bool)

SetGameResult set the game's result

func (*Game) Turn

func (game *Game) Turn() Color

Turn get the current turn

func (*Game) TurnsSinceCaptureOrPawnMove

func (game *Game) TurnsSinceCaptureOrPawnMove() uint8

TurnsSinceCaptureOrPawnMove get the game's number of turns since a capture or pawn move

func (*Game) WhiteKing

func (game *Game) WhiteKing() *Piece

WhiteKing get the game's white king

func (*Game) WhitePieces

func (game *Game) WhitePieces() map[PieceType]uint8

WhitePieces get the game's white pieces

type GameResult

type GameResult struct {
	Winner Color
	Draw   bool
}

GameResult is a struct representing the result of a game

type Move

type Move struct {
	X, Y int8
}

Move is a struct that represents a chess move

func (*Move) String

func (move *Move) String() string

type MoveRequest

type MoveRequest struct {
	Position  Position
	Move      Move
	PromoteTo *PieceType
}

MoveRequest is a move request that can be applied to a game

func (MoveRequest) String

func (mr MoveRequest) String() string

type Piece

type Piece struct {
	PieceType  PieceType
	Position   Position
	Color      Color
	MovesTaken uint16
}

Piece a chess piece

func NewPiece

func NewPiece(pieceType PieceType, position Position, color Color) *Piece

NewPiece return a new piece

func (*Piece) ClientString

func (piece *Piece) ClientString() string

ClientString return the piece's client string

func (*Piece) File

func (piece *Piece) File() uint8

File return the piece's file

func (*Piece) IsMoveValid

func (piece *Piece) IsMoveValid(
	board *Board, move Move, previousMove Move, previousMover *Piece,
	king *Piece, promoteTo *PieceType,
) bool

IsMoveValid determines whether a move is valid

func (*Piece) MarshalBinary

func (piece *Piece) MarshalBinary(
	board *Board, previousMove Move, previousMover *Piece, king *Piece,
) (data []byte, err error)

MarshalBinary return the piece's representation as a byte array

func (*Piece) Moves

func (piece *Piece) Moves(
	board *Board, previousMove Move, previousMover *Piece, allThreatened bool,
	king *Piece,
) []Position

Moves get all the valid moves or all the threatening moves for a piece

func (*Piece) Rank

func (piece *Piece) Rank() uint8

Rank return the piece's rank

func (*Piece) String

func (piece *Piece) String() string

String return the piece's string

func (*Piece) StringSimple

func (piece *Piece) StringSimple() string

StringSimple return the piece's simple string representation

func (*Piece) ValidMoves

func (piece *Piece) ValidMoves(
	board *Board, previousMove Move, previousMover *Piece,
	allThreatened bool, king *Piece,
) []Move

ValidMoves get all the valid moves for a piece or all threatening moves

func (*Piece) Value

func (piece *Piece) Value() int8

Value return the piece's point value

type PieceType

type PieceType uint8

PieceType the various piece types

type Position

type Position struct {
	File, Rank uint8
}

Position is a struct representing a chess piece's position

func NewPosition

func NewPosition(file, rank uint8) Position

NewPosition creates a new position

func (Position) String

func (pos Position) String() string

type SerializableBoard

type SerializableBoard []Piece

SerializableBoard is a chess board of pieces that can be serialized

Jump to

Keyboard shortcuts

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