diff --git a/board.go b/board.go index a0e9fcb..a61718d 100644 --- a/board.go +++ b/board.go @@ -233,7 +233,7 @@ func (b *Board) update(m *Move) { } // check promotion if m.promo != NoPieceType { - newPiece := GetPiece(m.promo, p1.Color()) + newPiece := NewPiece(m.promo, p1.Color()) // remove pawn bbPawn := b.bbForPiece(p1) b.setBBForPiece(p1, bbPawn & ^s2BB) diff --git a/engine.go b/engine.go index f96d6cc..ff49d10 100644 --- a/engine.go +++ b/engine.go @@ -133,25 +133,25 @@ func squaresAreAttacked(pos *Position, sqs ...Square) bool { continue } // check queen attack vector - queenBB := pos.board.bbForPiece(GetPiece(Queen, otherColor)) + queenBB := pos.board.bbForPiece(NewPiece(Queen, otherColor)) bb := (diaAttack(occ, sq) | hvAttack(occ, sq)) & queenBB if bb != 0 { return true } // check rook attack vector - rookBB := pos.board.bbForPiece(GetPiece(Rook, otherColor)) + rookBB := pos.board.bbForPiece(NewPiece(Rook, otherColor)) bb = hvAttack(occ, sq) & rookBB if bb != 0 { return true } // check bishop attack vector - bishopBB := pos.board.bbForPiece(GetPiece(Bishop, otherColor)) + bishopBB := pos.board.bbForPiece(NewPiece(Bishop, otherColor)) bb = diaAttack(occ, sq) & bishopBB if bb != 0 { return true } // check knight attack vector - knightBB := pos.board.bbForPiece(GetPiece(Knight, otherColor)) + knightBB := pos.board.bbForPiece(NewPiece(Knight, otherColor)) bb = bbKnightMoves[sq] & knightBB if bb != 0 { return true @@ -173,7 +173,7 @@ func squaresAreAttacked(pos *Position, sqs ...Square) bool { } } // check king attack vector - kingBB := pos.board.bbForPiece(GetPiece(King, otherColor)) + kingBB := pos.board.bbForPiece(NewPiece(King, otherColor)) bb = bbKingMoves[sq] & kingBB if bb != 0 { return true diff --git a/piece.go b/piece.go index d79f987..1063ba1 100644 --- a/piece.go +++ b/piece.go @@ -128,7 +128,9 @@ var ( } ) -func GetPiece(t PieceType, c Color) Piece { +// NewPiece returns the piece matching the PieceType and Color. +// NoPiece is returned if the PieceType or Color isn't valid. +func NewPiece(t PieceType, c Color) Piece { for _, p := range allPieces { if p.Color() == c && p.Type() == t { return p