pawn

package module
v0.0.0-...-8ccc9df Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2017 License: MIT Imports: 10 Imported by: 0

README

Build Status Coverage Status

pawn

Learning Go by implementing chess

PGN Replayer Demo

Demo

Documentation

Index

Constants

View Source
const (
	WhiteWin Outcome = "1-0"
	BlackWin         = "0-1"
	Draw             = "1/2-1/2"
)
View Source
const (
	A File = "a"
	B      = "b"
	C      = "c"
	D      = "d"
	E      = "e"
	F      = "f"
	G      = "g"
	H      = "h"
)

Variables

View Source
var (
	ErrorMoveByWrongColor = errors.New("pawn: move by wrong color")
	ErrorInvalidPosition  = errors.New("pawn: invalid position")
)
View Source
var (
	A1 = Position{A, 1}
	A2 = Position{A, 2}
	A3 = Position{A, 3}
	A4 = Position{A, 4}
	A5 = Position{A, 5}
	A6 = Position{A, 6}
	A7 = Position{A, 7}
	A8 = Position{A, 8}
	B1 = Position{B, 1}
	B2 = Position{B, 2}
	B3 = Position{B, 3}
	B4 = Position{B, 4}
	B5 = Position{B, 5}
	B6 = Position{B, 6}
	B7 = Position{B, 7}
	B8 = Position{B, 8}
	C1 = Position{C, 1}
	C2 = Position{C, 2}
	C3 = Position{C, 3}
	C4 = Position{C, 4}
	C5 = Position{C, 5}
	C6 = Position{C, 6}
	C7 = Position{C, 7}
	C8 = Position{C, 8}
	D1 = Position{D, 1}
	D2 = Position{D, 2}
	D3 = Position{D, 3}
	D4 = Position{D, 4}
	D5 = Position{D, 5}
	D6 = Position{D, 6}
	D7 = Position{D, 7}
	D8 = Position{D, 8}
	E1 = Position{E, 1}
	E2 = Position{E, 2}
	E3 = Position{E, 3}
	E4 = Position{E, 4}
	E5 = Position{E, 5}
	E6 = Position{E, 6}
	E7 = Position{E, 7}
	E8 = Position{E, 8}
	F1 = Position{F, 1}
	F2 = Position{F, 2}
	F3 = Position{F, 3}
	F4 = Position{F, 4}
	F5 = Position{F, 5}
	F6 = Position{F, 6}
	F7 = Position{F, 7}
	F8 = Position{F, 8}
	G1 = Position{G, 1}
	G2 = Position{G, 2}
	G3 = Position{G, 3}
	G4 = Position{G, 4}
	G5 = Position{G, 5}
	G6 = Position{G, 6}
	G7 = Position{G, 7}
	G8 = Position{G, 8}
	H1 = Position{H, 1}
	H2 = Position{H, 2}
	H3 = Position{H, 3}
	H4 = Position{H, 4}
	H5 = Position{H, 5}
	H6 = Position{H, 6}
	H7 = Position{H, 7}
	H8 = Position{H, 8}
)
View Source
var NoPiece = Piece{}

Functions

This section is empty.

Types

type AlgebraicNotation

type AlgebraicNotation string

func (AlgebraicNotation) DestinationPosition

func (an AlgebraicNotation) DestinationPosition() Position

func (AlgebraicNotation) IsCastle

func (an AlgebraicNotation) IsCastle() bool

func (AlgebraicNotation) IsCastleKingSide

func (an AlgebraicNotation) IsCastleKingSide() bool

func (AlgebraicNotation) IsCastleQueenSide

func (an AlgebraicNotation) IsCastleQueenSide() bool

func (AlgebraicNotation) IsCheck

func (an AlgebraicNotation) IsCheck() bool

func (AlgebraicNotation) IsCheckMate

func (an AlgebraicNotation) IsCheckMate() bool

func (AlgebraicNotation) IsPromotion

func (an AlgebraicNotation) IsPromotion() bool

func (AlgebraicNotation) Material

func (an AlgebraicNotation) Material() Material

func (AlgebraicNotation) OriginDisambiguated

func (an AlgebraicNotation) OriginDisambiguated() bool

func (AlgebraicNotation) OriginFile

func (an AlgebraicNotation) OriginFile() File

func (AlgebraicNotation) OriginRank

func (an AlgebraicNotation) OriginRank() Rank

func (AlgebraicNotation) PromotedTo

func (an AlgebraicNotation) PromotedTo() Material

func (AlgebraicNotation) Takes

func (an AlgebraicNotation) Takes() bool

type AlgebraiclyNotated

type AlgebraiclyNotated interface {
	AN() string
	FAN() string
}

type Board

type Board struct {
	Squares []*Square
	// contains filtered or unexported fields
}

func NewBoard

func NewBoard() *Board

func (*Board) MoveFromAlgebraic

func (b *Board) MoveFromAlgebraic(an AlgebraicNotation) (Move, error)

func (Board) Rows

func (b Board) Rows() [][]*Square

Returns 8 rows of 8 squares each starting at the top left and moving down

func (Board) SquareAtPosition

func (b Board) SquareAtPosition(position Position) *Square

func (Board) SquaresForPiece

func (b Board) SquaresForPiece(piece Piece) []*Square

type Color

type Color string
const (
	Black Color = "Black"
	White Color = "White"
)

type Direction

type Direction int
const (
	Up Direction = iota
	Down
	Left
	Right
	UpLeftDiagonal
	UpRightDiagonal
	DownLeftDiagonal
	DownRightDiagonal
)

type File

type File string
var NilFile File

type Game

type Game struct {
	Board
	Moves []Move
}

type Material

type Material uint8
const (
	Pawn Material = iota + 1
	Rook
	Bishop
	Knight
	Queen
	King
)

func (Material) AN

func (m Material) AN() string

type Move

type Move struct {
	Piece
	From  Position
	To    Position
	Takes bool
}

type Movetext

type Movetext struct {
	Moves []*MovetextMove
}

func (Movetext) String

func (m Movetext) String() string

func (Movetext) Turns

func (m Movetext) Turns() []AlgebraicNotation

type MovetextMove

type MovetextMove struct {
	Number    uint8
	WhiteMove AlgebraicNotation
	BlackMove AlgebraicNotation
}

func (MovetextMove) String

func (m MovetextMove) String() string

type Outcome

type Outcome string

type PGN

type PGN struct {
	Tags
	Movetext
	Outcome
}

func NewPGN

func NewPGN() PGN

func ParseAllPGNFromFilePath

func ParseAllPGNFromFilePath(str string) []PGN

func ParsePGN

func ParsePGN(str string) PGN

Parses a string containing Portable Game Notation and returns a PGN struct

Spec: https://www.chessclub.com/user/help/PGN-spec

func (PGN) MatchUp

func (p PGN) MatchUp() string

func (PGN) String

func (p PGN) String() string

type PGNParser

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

func NewPGNParser

func NewPGNParser() *PGNParser

func NewPGNParserFromReader

func NewPGNParserFromReader(r io.Reader) *PGNParser

func (*PGNParser) ParseAll

func (p *PGNParser) ParseAll() []PGN

func (*PGNParser) ParseFromString

func (p *PGNParser) ParseFromString(str string) PGN

type Path

type Path []Position

type Piece

type Piece struct {
	Color
	Material
}

func (Piece) AN

func (p Piece) AN() string

func (Piece) FAN

func (p Piece) FAN() string

type Position

type Position struct {
	File // vertical columns a through h from queenside to kingside
	Rank // horizontal rows 1 to 8 from White's side of the board
}

func (Position) AN

func (p Position) AN() string

func (Position) Jump

func (p Position) Jump(directions ...Direction) (Position, error)

func (Position) OneMove

func (p Position) OneMove(direction Direction) Path

func (Position) Path

func (p Position) Path(direction Direction) Path

type Rank

type Rank uint8
var NilRank Rank

type Square

type Square struct {
	Position
	Piece
}

func AllSquares

func AllSquares() []*Square

func NewSquare

func NewSquare(position Position) *Square

func (Square) AN

func (s Square) AN() string

func (Square) String

func (s Square) String() string

type Tags

type Tags map[string]string

func (Tags) String

func (t Tags) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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