chess

package module
v0.0.0-...-6879a08 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 8 Imported by: 0

README

Chess

Library for analysing and playing chess games programmatically. Direct translation of chess.js to Go.

Represents a game with the 0x88 chess board representation.

Why?

I know there's a library called notnil/chess for Go too, but I found one function not available in that package, the .Moves() function (That is available in chess.js) to count for mobility for one side.

So I directly translated the Chess.js library to Go. Also provides function for validating FENs and prettier move representation.

holy hell

En passant still doesn't work properly (look at test "TestPositionsPgn") The captured pawn is still not taken off the board. (Wrong square set to nil & I tried for a while but didn't see a change)

Usage

  • Get the package
go get github.com/Dev-Siri/chess
  • Start using it ¯\_(ツ)_/¯
package main

import (
  "log"
  "fmt"

  "github.com/Dev-Siri/chess"
)

func main() {
  game, err := chess.NewGame()

  if err != nil {
    log.Fatalf(err)
  }

  game2, err := chess.NewGameFromFen("Or start from a FEN position")

  if err != nil {
    log.Fatalf(err)
  }

  // Make a move
  move, _ := game.Move("e4")

  // Print position
  fmt.Println(move.Pgn())
  fmt.Println(move.Fen())
}

License

This project is MIT Licensed, see LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateFen

func ValidateFen(fen string) error

Types

type Chess

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

func NewGame

func NewGame() (*Chess, error)

func NewGameFromFen

func NewGameFromFen(fen string) (*Chess, error)

func (*Chess) Ascii

func (c *Chess) Ascii() string

func (*Chess) Attackers

func (c *Chess) Attackers(square string, attackedBy string) []string

func (*Chess) Board

func (c *Chess) Board() [][]*schemas.Square

func (*Chess) Clear

func (c *Chess) Clear(preserveHeaders bool)

func (*Chess) DeleteComments

func (c *Chess) DeleteComments() []schemas.Comment

func (*Chess) Fen

func (c *Chess) Fen() string

func (*Chess) Get

func (c *Chess) Get(square string) *schemas.Piece

func (*Chess) GetCastlingRights

func (c *Chess) GetCastlingRights(color string) *schemas.CastlingRights

func (*Chess) GetComment

func (c *Chess) GetComment() string

func (*Chess) GetComments

func (c *Chess) GetComments() []schemas.Comment

func (*Chess) Header

func (c *Chess) Header(headers map[string]string) map[string]string

func (*Chess) IsAttacked

func (c *Chess) IsAttacked(square string, attackedBy string) bool

func (*Chess) IsCheck

func (c *Chess) IsCheck() bool

func (*Chess) IsCheckmate

func (c *Chess) IsCheckmate() bool

func (*Chess) IsDraw

func (c *Chess) IsDraw() bool

func (*Chess) IsGameOver

func (c *Chess) IsGameOver() bool

func (*Chess) IsInsufficientMaterial

func (c *Chess) IsInsufficientMaterial() bool

func (*Chess) IsStalemate

func (c *Chess) IsStalemate() bool

func (*Chess) IsThreeFoldRepetition

func (c *Chess) IsThreeFoldRepetition() bool

func (*Chess) Load

func (c *Chess) Load(fen string, skipValidation bool, preserveHeaders bool) error

func (*Chess) LoadPgn

func (c *Chess) LoadPgn(pgn string, strict bool, newlineChar string) error

func (*Chess) Move

func (c *Chess) Move(move string, strict bool) (*schemas.Move, error)

func (*Chess) MoveNumber

func (c *Chess) MoveNumber() int

func (*Chess) Moves

func (c *Chess) Moves(square string, piece string) ([]string, []schemas.Move)

func (*Chess) Perft

func (c *Chess) Perft(depth int) int

func (*Chess) Pgn

func (c *Chess) Pgn(newline string, maxWidth int) string

func (*Chess) Put

func (c *Chess) Put(pieceType string, color string, square string) bool

func (*Chess) Reset

func (c *Chess) Reset() error

func (*Chess) SetCastlingRights

func (c *Chess) SetCastlingRights(color string, rights map[string]bool) bool

func (*Chess) SetComment

func (c *Chess) SetComment(comment string)

func (*Chess) SquareColor

func (c *Chess) SquareColor(square string) string

func (*Chess) Turn

func (c *Chess) Turn() string

func (*Chess) Undo

func (c *Chess) Undo() *schemas.Move

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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