package board import ( "fmt" "strings" ) // MoveProp is defined as // type MoveProp uint16 // Available MoveProps const ( QueenSideCastle MoveProp = 1 << iota KingSideCastle Capture EnPassant Check Mate inCheck ) // Move is defined as type Move struct { Piece PieceType FromRank *Rank FromFile *File To Square PromoteTo PieceType Props MoveProp } func (m Move) String() string { out := "" if m.HasProp(KingSideCastle) { out += "O-O" } else if m.HasProp(QueenSideCastle) { out += "O-O-O" } else { if m.Piece != NoPieceType && m.Piece != Pawn { out += strings.ToUpper(m.Piece.String()) } if m.FromFile != nil { out += m.FromFile.String() } if m.FromRank != nil { out += m.FromRank.String() } if m.HasProp(Capture) { out += "x" } out += m.To.String() if m.PromoteTo != NoPieceType { out += fmt.Sprintf("=%s", m.PromoteTo.String()) } } if m.HasProp(Check) { out += "+" } else if m.HasProp(Mate) { out += "#" } return out } // AddProp adds the given MoveProp to this move. func (m *Move) AddProp(prop MoveProp) { m.Props = m.Props | prop } // HasProp returns true if this move has the given MoveProp. func (m Move) HasProp(prop MoveProp) bool { return m.Props&prop > 0 }