Hi
If my rook can check the king, then by calculation, the TO square is
(oppKing >> 3) + (from & 7) and/or
(from >> 3) + (oppKing & 7)
If my bishop can check the king, is there a formula for calculating the TO squares?
Grant
Calculating TO
Moderators: hgm, Rebel, chrisw
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Calculating TO
What exactly do you mean by "TO square": the square from which the rook can give check to the king?
And what is your board representation (it does not quite look like "0x88")?
Sven
And what is your board representation (it does not quite look like "0x88")?
Sven
-
- Posts: 67
- Joined: Mon Aug 06, 2007 4:42 pm
- Location: London, England
Re: Calculating TO
Sven
The TO square means the square/s that the rook moves to to check the king.
My board representation is A8=0, B8=1 ... H1=63, and I have a bitboard engine.
I just thought of trying a quick calculation to get my TO square in my generate checks function, which also does not require magics.
Grant
The TO square means the square/s that the rook moves to to check the king.
My board representation is A8=0, B8=1 ... H1=63, and I have a bitboard engine.
I just thought of trying a quick calculation to get my TO square in my generate checks function, which also does not require magics.
Grant
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Calculating TO
In case of bitboards, why don't you do an intersection (using precalculated tables) of all_bishop_targets[from] & all_bishop_targets[opp_king] that results in up to two squares, provided the bishop is not on the same diagonal as the opp_king already?
Same for rook: all_rook_targets[from] & all_rook_targets[opp_king], although I don't know whether the formula you gave wouldn't be slightly faster in the rook case.
For queen the same but there you may get up to four squares.
Sven
Same for rook: all_rook_targets[from] & all_rook_targets[opp_king], although I don't know whether the formula you gave wouldn't be slightly faster in the rook case.
For queen the same but there you may get up to four squares.
Sven
-
- Posts: 1922
- Joined: Thu Mar 09, 2006 12:51 am
- Location: Earth
Re: Calculating TO
That's actually 12.Sven Schüle wrote:For queen the same but there you may get up to four squares.
-
- Posts: 670
- Joined: Mon Dec 03, 2007 3:01 pm
- Location: Barcelona, Spain
Re: Calculating TO
assuming the definition:grant wrote:Sven
The TO square means the square/s that the rook moves to to check the king.
My board representation is A8=0, B8=1 ... H1=63, and I have a bitboard engine.
I just thought of trying a quick calculation to get my TO square in my generate checks function, which also does not require magics.
Grant
#define getDIA(sq) (7 - ((sq)&7) + ((sq)>>3))
#define getADIA(sq) (((sq)&7) + ((sq)>>3))
now getting the intersection of these two values is the problem:
one possible solution would be:
adia+3.5*(adia+dia-7)
but sofar I didn't come up with a solution to find out whether the two are intersecting at all
-
- Posts: 670
- Joined: Mon Dec 03, 2007 3:01 pm
- Location: Barcelona, Spain
Re: Calculating TO
to test whether they are intersecting:Edmund wrote:but sofar I didn't come up with a solution to find out whether the two are intersecting at all
(dia + adia - 7) = even
and
(dia + adia - 7) / 2 <= dia
maybe you can find an easier way Grant
-
- Posts: 67
- Joined: Mon Aug 06, 2007 4:42 pm
- Location: London, England
Re: Calculating TO
Sven
That is exactly what I was trying to avoid.
For rooks giving check, I simply lookup the bitboard containing all the squares the rook has to pass over to capture the king (if you see what I mean), and AND it with ALLOccupied. If the result is zero, a non-capture check is possible and the TO square can be calculated (as above).
Same with bishops but at the moment I have to use intersecting bitboards to get my TO squares.
Grant
That is exactly what I was trying to avoid.
For rooks giving check, I simply lookup the bitboard containing all the squares the rook has to pass over to capture the king (if you see what I mean), and AND it with ALLOccupied. If the result is zero, a non-capture check is possible and the TO square can be calculated (as above).
Same with bishops but at the moment I have to use intersecting bitboards to get my TO squares.
Grant
-
- Posts: 670
- Joined: Mon Dec 03, 2007 3:01 pm
- Location: Barcelona, Spain
Re: Calculating TO
so in short:
TO = (9*(sqA>>3 + sqA&7)+7*(sqB>>3 - sqB&7))/2
but be aware that TO has to be checked for 0 <= TO <= 63
and sqA and sqB must be on equal colored squares ((sqA+sqB) & 1) == 0
TO = (9*(sqA>>3 + sqA&7)+7*(sqB>>3 - sqB&7))/2
but be aware that TO has to be checked for 0 <= TO <= 63
and sqA and sqB must be on equal colored squares ((sqA+sqB) & 1) == 0
-
- Posts: 67
- Joined: Mon Aug 06, 2007 4:42 pm
- Location: London, England
Re: Calculating TO
Thanks Edmund
The rook calculation above should have read
(sqA & 56) + (sqB & 7) and/or
((sqB & 56) + (sqA & 7)
Oops.
Grant
The rook calculation above should have read
(sqA & 56) + (sqB & 7) and/or
((sqB & 56) + (sqA & 7)
Oops.
Grant