position

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package position provides functionality to work with chess positions. It defines the Position type, which represents a square on a chessboard, and provides methods to create, validate, and manipulate positions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File int8
const (
	FileNull File = iota

	FileA
	FileB
	FileC
	FileD
	FileE
	FileF
	FileG
	FileH

	FileI
	FileJ
	FileK
	FileL
	FileM
	FileN
	FileO
	FileP

	FileMin = FileA

	FileMax = FileP
)

func FileFromString

func FileFromString(str string) File

FileFromString returns a File from the specified string. The string must be a single character from "a" to "p" (case-insensitive). If the input is invalid, the function returns FileNull.

func (File) IsNull

func (f File) IsNull() bool

IsNull reports whether the file is FileNull.

func (File) String

func (f File) String() string

String returns the string representation of the file. If the file is null or invalid, it returns an empty string. Otherwise, it returns the alphabetic representation, e.g., "a" for FileA, "b" for FileB, and so on.

func (File) Validate

func (f File) Validate() error

Validate checks whether the file value is within the range from FileNull to FileMax. Returns an error if the value is invalid; otherwise returns nil. FileNull is considered valid.

type Position

type Position struct {
	File File `json:"file"`
	Rank Rank `json:"rank"`
}

Position represents the coordinates of a square on a chessboard.

func (Position) IsEmpty

func (p Position) IsEmpty() bool

IsEmpty checks if the position contains both File and Rank null values.

func (Position) IsFull

func (p Position) IsFull() bool

IsFull checks if the position contains both File and Rank not empty values.

func (Position) String

func (p Position) String() string

String returns the string representation of the position. If the position is empty, it returns an empty string. For example, Position{FileE, Rank4} will be converted to "e4".

func (*Position) UnmarshalJSON

func (p *Position) UnmarshalJSON(data []byte) error

func (Position) Validate

func (p Position) Validate() error

Validate checks if the position contains both File and Rank values not exceeding their maximum limits.

type Rank

type Rank int8
const (
	RankNull Rank = iota

	Rank1
	Rank2
	Rank3
	Rank4
	Rank5
	Rank6
	Rank7
	Rank8

	Rank9
	Rank10
	Rank11
	Rank12
	Rank13
	Rank14
	Rank15
	Rank16

	RankMin = Rank1

	RankMax = Rank16
)

func (Rank) IsNull

func (r Rank) IsNull() bool

IsNull reports whether the rank is RankNull.

func (Rank) String

func (r Rank) String() string

String returns the string representation of the rank. If the rank is null or invalid, it returns an empty string. Otherwise, it returns the numeric representation, e.g., "1" for Rank1, "2" for Rank2, and so on.

func (Rank) Validate

func (r Rank) Validate() error

Validate checks whether the rank value is within the range from RankNull to RankMax. Returns an error if the value is invalid; otherwise returns nil. RankNull is considered valid.

Jump to

Keyboard shortcuts

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