World Conquest Chronicles

World Conquest Chronicles

go-chess-models, v1.4

The library that implements checking and generating of chess moves.

Serialization models to Forsyth–Edwards Notation and refactoring.

Change Log

Features

  • representing the board as an associative array of pieces with their positions as keys;
  • immutable applicating moves to the board via copying the latter;
  • checkings of moves:
    • universal;
    • individual for all types of pieces;
  • generating moves via filtering from all possible ones;
  • using an abstraction of a piece;
  • Forsyth–Edwards Notation:
    • parsing:
      • of a piece kind;
      • of a piece color;
      • of a board;
    • serialization:
      • of a piece kind;
      • of a piece color;
      • of a board.

Examples

chessmodels.ParsePiece():

package main

import (
    "fmt"

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

func main() {
    kind, color, _ := models.ParsePiece('B')
    fmt.Printf("%v %v\n", kind, color)

    // Output: 3 1
}

chessmodels.Kind.ToFEN():

package main

import (
    "fmt"

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

func main() {
    fen, _ := models.Bishop.ToFEN(models.White)
    fmt.Printf("%c\n", fen)

    // Output: B
}

chessmodels.Board.ToFEN():

package main

import (
    "fmt"

    models "github.com/thewizardplusplus/go-chess-models"
    "github.com/thewizardplusplus/go-chess-models/pieces"
)

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

    // Output: 5/3B1/2r2/5/5
}

Repository

Link: https://github.com/thewizardplusplus/go-chess-models/tree/v1.4.

Content: code.

License: MIT.