gochess

package module
v0.0.0-...-975bdbf Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2013 License: MIT Imports: 7 Imported by: 1

README

About

This is a library in Go for parsing chess games in PGN

Installing

$ go get github.com/anastasop/gochess

Documentation

See http://go.pkgdoc.org/github.com/anastasop/gochess

Or run:

$ godoc github.com/anastasop/gochess

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Board

type Board struct {
	MoveWhite  bool
	MoveNumber uint8
	// contains filtered or unexported fields
}

Board represents a chess board and tracks pieces positions. It provides methods to move pieces and export board positions as FEN and GBR

func NewBoard

func NewBoard() *Board

NewBoard returns a Board object initialized with the standard starting position

func NewBoardFromFen

func NewBoardFromFen(fen string) (*Board, error)

NewBoardFromFen returns a Board object initialized with the position of fen

func (*Board) Fen

func (b *Board) Fen() string

Fen returns the board position as a standard FEN string see http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation

func (*Board) Gbr

func (b *Board) Gbr() string

Gbr returns the GBR code for the position see http://en.wikipedia.org/wiki/GBR_code

func (*Board) LastMove

func (b *Board) LastMove() (san string, white bool, number uint8)

LastMove returns the last move made on the board. In other words the position on the board resulted after this move

func (*Board) MakeMove

func (b *Board) MakeMove(san string) error

MakeMove makes a move on the board If the move is illegal like a king move to a checked square or the move is ambiguous as if two pieces can move to the same square, then it returns an error and the board does not record the move. The board keeps track of which color moved previously and alternates

func (*Board) SetTurn

func (b *Board) SetTurn(whiteMove bool)

SetTurn sets who makes the next move

func (*Board) String

func (b *Board) String() string

String is equivalent to Fen()

type Game

type Game struct {
	// Tags is a map with the PGN tags. The keys are the tag keys
	Tags map[string]string
	// Moves is initialized after calling ParseMovesText. It contains
	// all the variations of the game as a tree of plies
	Moves Variation
	// PGNText is a verbatim copy of the game PGN
	PGNText []byte
	// MovesText contains just the game moves section from the PGN
	MovesText []byte
}

Game represents a single parsed PGN game

func (*Game) ParseMovesText

func (game *Game) ParseMovesText() error

ParseMovesText parses the moves text of a game and converts it to a tree of plies. It must be called explicitly for each game

type Parser

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

Parser is a parser for the PGN chess games notation

func NewParser

func NewParser(input io.Reader) *Parser

NewParser returns a new Parser for the input ReadCloser The input stream must contain PGN data. It is not safe(yet) for concurrent access by multiple goroutines

func (*Parser) NextGame

func (p *Parser) NextGame() (*Game, error)

NextGame is an iterator for games. It returns a non-nil error on IO failure otherwise it returns a parsed game. On EOF it returns nil, nil

type Ply

type Ply struct {
	// SAN is the text of the move like e4 or Nf3
	SAN string
	// Nags are pgn annotation for the move
	Nags []uint8
	// Comment is the comment for the move
	Comment string
	// Variations is a slice of alternative moves at this point.
	// In PGN they are represented as RAVs parenthesized variations
	Variations []Variation
}

Ply is a single move by white or black

type Variation

type Variation struct {
	// MoveNumber the move number at which the variation applies
	MoveNumber uint8
	// WhiteMove if true the variation starts with a ply by white, else by black
	WhiteMove bool
	// Plies is a slice with the plies of the variation
	Plies []*Ply
	// Result is the result of the variation. It is one of 1-0, 0-1, 1/2-1/2, *
	Result string
	// Comment has the comments from the PGN that apply to the variation as
	// a whole and do not apply to specific plies
	Comment string
}

Variation represents a singles variation i.e a move sequence in the game

Jump to

Keyboard shortcuts

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