Chess-Challenge icon indicating copy to clipboard operation
Chess-Challenge copied to clipboard

Is there any way to get our Piece's attacking squares or get a square's attacking pieces?

Open Kaanavciexe opened this issue 2 years ago • 4 comments

I want to get our Piece's attacking squares or get a square's attacking pieces. For example my knight on f3 and i want to take its attacking squares for example e5, g5... IS there any way to do this?

Kaanavciexe avatar Jul 25 '23 12:07 Kaanavciexe

If you're willing to use bitboards, you can use ChessChallenge.Chess.Bits.KnightAttacks[knightSquare] to get the bitboard of all the knight's attacks

mcthouacbb avatar Jul 25 '23 13:07 mcthouacbb

You could also count the legal moves that start at the knights position. Don't know if that's exactly what your asking for

EikeSchwass avatar Jul 25 '23 15:07 EikeSchwass

I don't think you're allowed to use this namespace: ChessChallenge.Chess

TrevorMcCubbin avatar Jul 26 '23 04:07 TrevorMcCubbin

you can use the ChessChallenge.API.GetKnightAttacks to get the knights bitboard ChessChallenge.API is defiantly allowed where I also don't think ChessChallenge.Chess is allowed

if you want to see if it is attacking something it is a bit clunky in this situation as you need to test it against a square to see if it is attacking that square, I'm not sure how you can get it to list all squares in the bitboard (without looping all squares).

I'm am using it to check for attacks on specific pieces like this ulong Attacks = board.GetAllPieceLists(); OR ulong Attacks = p_board.GetPieceList(PieceType, IsWhite); to get specific pieces then loop through the pieces and use ChessChallenge.API.BitboardHelper.SquareIsSet(Attacks, piece.Square)

hope this helps, if anyone has a better way please post it here

ScottProgrammer avatar Jul 26 '23 13:07 ScottProgrammer