ExChess.Move (ExChess v0.1.0)

View Source

ExChess.Move is the struct used to represent a move's starting position (:from_square), destination (:to_square), and promotion type.

Summary

Types

The piece type that a pawn should be promoted to when it is being moved to the last rank.

t()

ExChess.Move is the struct used to represent a move's starting position (:from_square), destination (:to_square), and promotion type.

Types

promotion()

@type promotion() :: :q | :r | :b | :n

The piece type that a pawn should be promoted to when it is being moved to the last rank.

The values are similar to ExChess.Piece's color() type, except it does not support :p and :k as values, as those are not valid promotions.

t()

@type t() :: %ExChess.Move{
  from: ExChess.Square.t(),
  promotion: promotion(),
  to: ExChess.Square.t()
}

ExChess.Move is the struct used to represent a move's starting position (:from_square), destination (:to_square), and promotion type.

Functions

new(from, to, promotion \\ :q)

@spec new(ExChess.Square.t(), ExChess.Square.t(), promotion()) :: t()

Creates a new ExChess.Move struct.

Examples

With promotion

iex> first_square = ExChess.Square.new(0, 1)
iex> second_square = ExChess.Square.new(0, 2)
iex> ExChess.Move.new(first_square, second_square, :n)
%ExChess.Move{to: %ExChess.Square{file: 0, rank: 2}, from: %ExChess.Square{file: 0, rank: 1}, promotion: :n}

With default promotion

iex> first_square = ExChess.Square.new(0, 1)
iex> second_square = ExChess.Square.new(0, 2)
iex> ExChess.Move.new(first_square, second_square)
%ExChess.Move{to: %ExChess.Square{file: 0, rank: 2}, from: %ExChess.Square{file: 0, rank: 1}, promotion: :q}