Skip to content

Commit

Permalink
chess: add null move constant
Browse files Browse the repository at this point in the history
  • Loading branch information
e0ff committed Nov 26, 2023
1 parent 0452d8e commit d14bbfb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/chess/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
NormalMove MoveType = iota
CastleMove
EnPassantMove
Null
)

func (t MoveType) String() string {
Expand All @@ -21,6 +22,8 @@ func (t MoveType) String() string {
return "Castle"
case EnPassantMove:
return "En Passant"
case Null:
return "Null"
}

return "<unknown>"
Expand All @@ -47,6 +50,8 @@ type Move struct {
capturePiece Piece
}

var NullMove = NewMove(A1, A1, Null, NoMoveFlag)

// NewMove creates a new move with the given from and to.
func NewMove(from, to Square, moveType MoveType, flags MoveFlag) Move {
return Move{
Expand Down Expand Up @@ -121,6 +126,10 @@ func (m Move) IsIrreversible() bool {
}

func (m Move) String() string {
if m.Type() == Null {
return "0000"
}

str := m.From.ToAlgebraic() + m.To.ToAlgebraic()

if m.promotionPiece != EmptyPiece {
Expand Down

0 comments on commit d14bbfb

Please sign in to comment.