Skip to content

Commit

Permalink
Merge branch 'barakmich-feat/expose_getPiece'
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Spears committed Aug 8, 2022
2 parents 6e59700 + bba8062 commit a469f11
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion board.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion piece.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a469f11

Please sign in to comment.