romstad / Chess.jl

Julia chess programming library.
https://romstad.github.io/Chess.jl/dev/
Other
103 stars 17 forks source link

Possible Bug in "ismovecheck()" #18

Closed cesch97 closed 3 years ago

cesch97 commented 3 years ago

When trying to call ismovecheck() during a tree search I stumbled across the error

LoadError: MethodError: no method matching bishoplike(::PieceColor)
Closest candidates are:
  bishoplike(::Board) at /home/fabio/.julia/packages/Chess/86E71/src/board.jl:600
  bishoplike(::Board, ::PieceColor) at /home/fabio/.julia/packages/Chess/86E71/src/board.jl:625
MethodError: no method matching bishoplike(::PieceColor)
Closest candidates are:
  bishoplike(::Board) at /home/fabio/.julia/packages/Chess/86E71/src/board.jl:600
  bishoplike(::Board, ::PieceColor) at /home/fabio/.julia/packages/Chess/86E71/src/board.jl:625

The functions bishoplike() and rooklike() take indeed a board and a color as argument but only a color is passed.

# src/board.jl:1263

# En passant checks
if moveisep(b, m)
    capsq = Square(file(t), rank(f))
    newocc = occ - f + t - capsq
    if !isempty(bishopattacks(newocc, ksq) ∩ bishoplike(us))
        return true
    end
    if !isempty(rookattacks(newocc, ksq) ∩ rooklike(us))
        return true
    end
end

I just added the board to the functions args and now it seems to work fine

# En passant checks
if moveisep(b, m)
    capsq = Square(file(t), rank(f))
    newocc = occ - f + t - capsq
    if !isempty(bishopattacks(newocc, ksq) ∩ bishoplike(b, us))
        return true
    end
    if !isempty(rookattacks(newocc, ksq) ∩ rooklike(b, us))
        return true
    end
end
romstad commented 3 years ago

Thank you! Fixed now.