Sashite.Pin.Identifier (Sashite.Pin v3.1.0)
View SourceRepresents a parsed PIN (Piece Identifier Notation) identifier.
An Identifier encodes four attributes of a piece:
- Abbr: the piece name abbreviation (A-Z as uppercase atom)
- Side: the piece side (
:firstor:second) - State: the piece state (
:normal,:enhanced, or:diminished) - Terminal: whether the piece is terminal (
trueorfalse)
All structs are immutable. Transformation functions return new structs.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> pin.abbr
:K
iex> pin.side
:first
iex> pin = Sashite.Pin.Identifier.new(:R, :second, :enhanced)
iex> Sashite.Pin.Identifier.to_string(pin)
"+r"
Summary
Functions
Returns a new Identifier with diminished state.
Checks if the Identifier has diminished state.
Returns a new Identifier with enhanced state.
Checks if the Identifier has enhanced state.
Checks if the Identifier belongs to the first player.
Returns a new Identifier with the opposite side.
Creates a new Identifier instance.
Returns a new Identifier unmarked as terminal.
Checks if the Identifier has normal state.
Returns a new Identifier with normal state.
Checks if two Identifiers have the same abbreviation.
Checks if two Identifiers have the same side.
Checks if two Identifiers have the same state.
Checks if two Identifiers have the same terminal status.
Checks if the Identifier belongs to the second player.
Returns a new Identifier marked as terminal.
Returns the PIN string representation.
Returns a new Identifier with a different abbreviation.
Returns a new Identifier with a different side.
Returns a new Identifier with a different state.
Returns a new Identifier with a different terminal status.
Types
Functions
Returns a new Identifier with diminished state.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> diminished = Sashite.Pin.Identifier.diminish(pin)
iex> diminished.state
:diminished
Checks if the Identifier has diminished state.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first, :diminished)
iex> Sashite.Pin.Identifier.diminished?(pin)
true
iex> pin = Sashite.Pin.Identifier.new(:K, :first, :normal)
iex> Sashite.Pin.Identifier.diminished?(pin)
false
Returns a new Identifier with enhanced state.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> enhanced = Sashite.Pin.Identifier.enhance(pin)
iex> enhanced.state
:enhanced
Checks if the Identifier has enhanced state.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first, :enhanced)
iex> Sashite.Pin.Identifier.enhanced?(pin)
true
iex> pin = Sashite.Pin.Identifier.new(:K, :first, :normal)
iex> Sashite.Pin.Identifier.enhanced?(pin)
false
Checks if the Identifier belongs to the first player.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> Sashite.Pin.Identifier.first_player?(pin)
true
iex> pin = Sashite.Pin.Identifier.new(:K, :second)
iex> Sashite.Pin.Identifier.first_player?(pin)
false
Returns a new Identifier with the opposite side.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> flipped = Sashite.Pin.Identifier.flip(pin)
iex> flipped.side
:second
iex> pin = Sashite.Pin.Identifier.new(:K, :second)
iex> flipped = Sashite.Pin.Identifier.flip(pin)
iex> flipped.side
:first
Creates a new Identifier instance.
Validates all components through guards that expand to compile-time pattern matching — no runtime helper calls.
Parameters
abbr- Piece name abbreviation (:Ato:Z)side- Piece side (:firstor:second)state- Piece state (:normal,:enhanced, or:diminished), defaults to:normalterminal- Terminal status (trueorfalse), defaults tofalse
Examples
iex> Sashite.Pin.Identifier.new(:K, :first)
%Sashite.Pin.Identifier{abbr: :K, side: :first, state: :normal, terminal: false}
iex> Sashite.Pin.Identifier.new(:R, :second, :enhanced)
%Sashite.Pin.Identifier{abbr: :R, side: :second, state: :enhanced, terminal: false}
iex> Sashite.Pin.Identifier.new(:K, :first, :normal, true)
%Sashite.Pin.Identifier{abbr: :K, side: :first, state: :normal, terminal: true}Raises
ArgumentErrorif any attribute is invalid
Returns a new Identifier unmarked as terminal.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first, :normal, true)
iex> non_term = Sashite.Pin.Identifier.non_terminal(pin)
iex> non_term.terminal
false
Checks if the Identifier has normal state.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first, :normal)
iex> Sashite.Pin.Identifier.normal?(pin)
true
iex> pin = Sashite.Pin.Identifier.new(:K, :first, :enhanced)
iex> Sashite.Pin.Identifier.normal?(pin)
false
Returns a new Identifier with normal state.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first, :enhanced)
iex> normalized = Sashite.Pin.Identifier.normalize(pin)
iex> normalized.state
:normal
Checks if two Identifiers have the same abbreviation.
Examples
iex> pin1 = Sashite.Pin.Identifier.new(:K, :first)
iex> pin2 = Sashite.Pin.Identifier.new(:K, :second)
iex> Sashite.Pin.Identifier.same_abbr?(pin1, pin2)
true
iex> pin1 = Sashite.Pin.Identifier.new(:K, :first)
iex> pin2 = Sashite.Pin.Identifier.new(:Q, :first)
iex> Sashite.Pin.Identifier.same_abbr?(pin1, pin2)
false
Checks if two Identifiers have the same side.
Examples
iex> pin1 = Sashite.Pin.Identifier.new(:K, :first)
iex> pin2 = Sashite.Pin.Identifier.new(:Q, :first)
iex> Sashite.Pin.Identifier.same_side?(pin1, pin2)
true
iex> pin1 = Sashite.Pin.Identifier.new(:K, :first)
iex> pin2 = Sashite.Pin.Identifier.new(:K, :second)
iex> Sashite.Pin.Identifier.same_side?(pin1, pin2)
false
Checks if two Identifiers have the same state.
Examples
iex> pin1 = Sashite.Pin.Identifier.new(:K, :first, :enhanced)
iex> pin2 = Sashite.Pin.Identifier.new(:Q, :second, :enhanced)
iex> Sashite.Pin.Identifier.same_state?(pin1, pin2)
true
iex> pin1 = Sashite.Pin.Identifier.new(:K, :first, :enhanced)
iex> pin2 = Sashite.Pin.Identifier.new(:K, :first, :normal)
iex> Sashite.Pin.Identifier.same_state?(pin1, pin2)
false
Checks if two Identifiers have the same terminal status.
Examples
iex> pin1 = Sashite.Pin.Identifier.new(:K, :first, :normal, true)
iex> pin2 = Sashite.Pin.Identifier.new(:Q, :second, :enhanced, true)
iex> Sashite.Pin.Identifier.same_terminal?(pin1, pin2)
true
iex> pin1 = Sashite.Pin.Identifier.new(:K, :first, :normal, true)
iex> pin2 = Sashite.Pin.Identifier.new(:K, :first, :normal, false)
iex> Sashite.Pin.Identifier.same_terminal?(pin1, pin2)
false
Checks if the Identifier belongs to the second player.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :second)
iex> Sashite.Pin.Identifier.second_player?(pin)
true
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> Sashite.Pin.Identifier.second_player?(pin)
false
Returns a new Identifier marked as terminal.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> term = Sashite.Pin.Identifier.terminal(pin)
iex> term.terminal
true
Returns the PIN string representation.
Each valid combination has its own function clause, generated at compile time. The BEAM dispatches directly to the correct clause and returns a pre-computed binary literal — zero concatenation, zero allocation.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> Sashite.Pin.Identifier.to_string(pin)
"K"
iex> pin = Sashite.Pin.Identifier.new(:R, :second, :enhanced)
iex> Sashite.Pin.Identifier.to_string(pin)
"+r"
iex> pin = Sashite.Pin.Identifier.new(:K, :first, :normal, true)
iex> Sashite.Pin.Identifier.to_string(pin)
"K^"
iex> pin = Sashite.Pin.Identifier.new(:K, :first, :enhanced, true)
iex> Sashite.Pin.Identifier.to_string(pin)
"+K^"
Returns a new Identifier with a different abbreviation.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> queen = Sashite.Pin.Identifier.with_abbr(pin, :Q)
iex> queen.abbr
:QRaises
ArgumentErrorif the abbreviation is invalid
Returns a new Identifier with a different side.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> second = Sashite.Pin.Identifier.with_side(pin, :second)
iex> second.side
:secondRaises
ArgumentErrorif the side is invalid
Returns a new Identifier with a different state.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> enhanced = Sashite.Pin.Identifier.with_state(pin, :enhanced)
iex> enhanced.state
:enhancedRaises
ArgumentErrorif the state is invalid
Returns a new Identifier with a different terminal status.
Examples
iex> pin = Sashite.Pin.Identifier.new(:K, :first)
iex> term = Sashite.Pin.Identifier.with_terminal(pin, true)
iex> term.terminal
trueRaises
ArgumentErrorif the terminal is not a boolean