uci

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeMove

func DecodeMove(text string) (move common.Move, err error)

DecodeMove ...

It decodes a move from pure algebraic coordinate notation.

Example
package main

import (
	"fmt"

	"github.com/thewizardplusplus/go-chess-models/encoding/uci"
)

func main() {
	move, _ := uci.DecodeMove("d4c3")
	fmt.Printf("%+v\n", move)

}
Output:

{Start:{File:3 Rank:3} Finish:{File:2 Rank:2}}

func DecodePiece

func DecodePiece(fen rune, factory common.PieceFactory) (common.Piece, error)

DecodePiece ...

It decodes a piece from FEN (only a kind and a color, not a position).

func DecodePieceStorage

func DecodePieceStorage(
	fen string,
	pieceFactory common.PieceFactory,
	pieceStorageFactory PieceStorageFactory,
) (common.PieceStorage, error)

DecodePieceStorage ...

It decodes a piece storage from FEN.

Example
package main

import (
	"fmt"
	"sort"

	"github.com/thewizardplusplus/go-chess-models/boards"
	"github.com/thewizardplusplus/go-chess-models/common"
	"github.com/thewizardplusplus/go-chess-models/encoding/uci"
	"github.com/thewizardplusplus/go-chess-models/pieces"
)

type ByPosition []common.Piece

func (group ByPosition) Len() int {
	return len(group)
}

func (group ByPosition) Swap(i int, j int) {
	group[i], group[j] = group[j], group[i]
}

func (group ByPosition) Less(i int, j int) bool {
	a, b := group[i].Position(), group[j].Position()
	if a.File == b.File {
		return a.Rank < b.Rank
	}

	return a.File < b.File
}

func main() {
	const fen = "8/8/8/8/3B4/2r5/8/8"
	storage, _ := uci.DecodePieceStorage(fen, pieces.NewPiece, boards.NewMapBoard)
	pieces := storage.Pieces()
	sort.Sort(ByPosition(pieces))
	fmt.Printf("%+v\n", pieces)

}
Output:

[{Base:{kind:2 color:0 position:{File:2 Rank:2}}} {Base:{kind:3 color:1 position:{File:3 Rank:3}}}]

func DecodePosition

func DecodePosition(text string) (position common.Position, err error)

DecodePosition ...

It decodes a position from pure algebraic coordinate notation.

func EncodeMove

func EncodeMove(move common.Move) string

EncodeMove ...

It converts the move to pure algebraic coordinate notation.

Example
package main

import (
	"fmt"

	"github.com/thewizardplusplus/go-chess-models/common"
	"github.com/thewizardplusplus/go-chess-models/encoding/uci"
)

func main() {
	move := uci.EncodeMove(common.Move{
		Start:  common.Position{File: 3, Rank: 3},
		Finish: common.Position{File: 2, Rank: 2},
	})
	fmt.Printf("%v\n", move)

}
Output:

d4c3

func EncodePiece

func EncodePiece(piece common.Piece) string

EncodePiece ...

It converts the piece to FEN (only a kind and a color, not a position).

func EncodePieceStorage

func EncodePieceStorage(storage common.PieceStorage) string

EncodePieceStorage ...

It converts the piece storage to FEN.

Example
package main

import (
	"fmt"

	"github.com/thewizardplusplus/go-chess-models/boards"
	"github.com/thewizardplusplus/go-chess-models/common"
	"github.com/thewizardplusplus/go-chess-models/encoding/uci"
	"github.com/thewizardplusplus/go-chess-models/pieces"
)

func main() {
	board := boards.NewMapBoard(common.Size{Width: 5, Height: 5}, []common.Piece{
		pieces.NewRook(common.Black, common.Position{File: 2, Rank: 2}),
		pieces.NewBishop(common.White, common.Position{File: 3, Rank: 3}),
	})
	fen := uci.EncodePieceStorage(board)
	fmt.Printf("%v\n", fen)

}
Output:

5/3B1/2r2/5/5

func EncodePosition

func EncodePosition(position common.Position) string

EncodePosition ...

It converts the position to pure algebraic coordinate notation.

Types

type PieceStorageFactory

type PieceStorageFactory func(
	size common.Size,
	pieces []common.Piece,
) common.PieceStorage

PieceStorageFactory ...

Jump to

Keyboard shortcuts

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