World Conquest Chronicles

World Conquest Chronicles

go-chess-models, v1.2

The library that implements checking and generating of chess moves.

Implementing individual checkings of moves for all types of pieces.

Change Log

  • implementing individual checkings of moves for all types of pieces.

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.

Examples

pieces.Knight.CheckMove():

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.NewKnight(models.Black, models.Position{File: 2, Rank: 2}),
    })

    moveOne := models.Move{
        Start:  models.Position{File: 2, Rank: 2},
        Finish: models.Position{File: 2, Rank: 3},
    }
    fmt.Printf("%+v: %v\n", moveOne, board.CheckMove(moveOne))

    moveTwo := models.Move{
        Start:  models.Position{File: 2, Rank: 2},
        Finish: models.Position{File: 4, Rank: 3},
    }
    fmt.Printf("%+v: %v\n", moveTwo, board.CheckMove(moveTwo))

    // Output:
    // {Start:{File:2 Rank:2} Finish:{File:2 Rank:3}}: illegal move
    // {Start:{File:2 Rank:2} Finish:{File:4 Rank:3}}: <nil>
}

Repository

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

Content: code.

License: MIT.