World Conquest Chronicles

World Conquest Chronicles

go-chess-cli, v1.1

The chess program with a terminal-based interface.

Improvements of displaying (including displaying pieces by Unicode and displaying a board in the wide mode) and restricting a deep of searching.

Change Log

  • displaying:
    • pieces by Unicode (optional);
    • board in the wide mode (optional);
    • misc.:
      • marking searching process;
      • placing a human side at bottom;
  • automatic random selecting a human color (optional);
  • restricting move searching by a deep.

Features

  • displaying a board:
    • by symbols (to choose):
      • ASCII;
      • Unicode;
    • by size (to choose):
      • terse;
      • wide;
    • misc.:
      • marking searching process;
      • placing a human side at bottom;
  • interacting via text commands (moves in pure algebraic coordinate notation);
  • options:
    • initial position in Forsyth–Edwards notation;
    • human color (i.e. a computer can move first):
      • support automatic random selecting (optional);
    • move searching restrictions:
    • displaying:
      • switching between ASCII/Unicode modes;
      • switching between terse/wide modes.

Usage

$ go-chess-cli -h | -help | --help
$ go-chess-cli [options]

Options:

  • -h, -help, --help — show the help message and exit;
  • -cacheSize ITEMS — maximal cache size (default: 1000000, i.e. one million);
  • -color {random|black|white} — human color (default: random);
  • -deep INTEGER — search deep (default: 5);
  • -duration DURATION — search duration (e.g. 72h3m0.5s; default: 5s);
  • -fen STRING — board in FEN (default: rnbqk/ppppp/5/PPPPP/RNBQK, i.e. Gardner's minichess);
  • -unicode {false|true} — use Unicode to display pieces (default: true; for inverting use -unicode=false);
  • -wide {false|true} — display the board wide (default: true; for inverting use -wide=false).

Examples

ascii.DecodeColor():

package main

import (
    "fmt"

    "github.com/thewizardplusplus/go-chess-cli/encoding/ascii"
)

func main() {
    color, _ := ascii.DecodeColor("white")
    fmt.Printf("%v\n", color)

    // Output: 1
}

ascii.EncodeColor():

package main

import (
    "fmt"

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

func main() {
    color := ascii.EncodeColor(models.White)
    fmt.Printf("%v\n", color)

    // Output: white
}

ascii.PieceStorageEncoder.EncodePieceStorage():

package main

import (
    "fmt"

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

func main() {
    const fen = "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R"
    storage, _ := uci.DecodePieceStorage(fen, pieces.NewPiece, models.NewBoard)
    encoder := ascii.NewPieceStorageEncoder(
        uci.EncodePiece,
        "x",
        ascii.Margins{},
        models.Black,
    )
    fmt.Printf("%v\n", encoder.EncodePieceStorage(storage))

    // Output:
    // 8rxxxkxxr
    // 7pxppqpbx
    // 6bnxxpnpx
    // 5xxxPNxxx
    // 4xpxxPxxx
    // 3xxNxxQxp
    // 2PPPBBPPP
    // 1RxxxKxxR
    //  abcdefgh
}

ascii.PieceStorageEncoder.EncodePieceStorage() with margins:

package main

import (
    "fmt"

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

func main() {
    margins := ascii.Margins{
        Piece: ascii.PieceMargins{
            HorizontalMargins: ascii.HorizontalMargins{
                Left: 1,
            },
        },
        Legend: ascii.LegendMargins{
            Rank: ascii.HorizontalMargins{
                Right: 1,
            },
        },
    }

    const fen = "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R"
    storage, _ := uci.DecodePieceStorage(fen, pieces.NewPiece, models.NewBoard)
    encoder := ascii.NewPieceStorageEncoder(
        uci.EncodePiece,
        "x",
        margins,
        models.Black,
    )
    fmt.Printf("%v\n", encoder.EncodePieceStorage(storage))

    // Output:
    // 8  r x x x k x x r
    // 7  p x p p q p b x
    // 6  b n x x p n p x
    // 5  x x x P N x x x
    // 4  x p x x P x x x
    // 3  x x N x x Q x p
    // 2  P P P B B P P P
    // 1  R x x x K x x R
    //    a b c d e f g h
}

unicode.EncodePiece():

package main

import (
    "fmt"

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

func main() {
    fen := unicode.EncodePiece(pieces.NewBishop(models.White, models.Position{}))
    fmt.Printf("%v\n", fen)

    // Output: ♗
}

Repository

Link: https://github.com/thewizardplusplus/go-chess-cli/tree/v1.1.

Content: code.

License: MIT.

Screenshots

With ASCII symbols in the wide mode

With Unicode symbols in the terse mode