[Tutor] checking diagonals on a chessboard
sanelson at gmail.com
Fri Apr 14 07:59:42 CEST 2006
On 4/13/06, Matthew Singletary <matt.singletary at gmail.com> wrote:
> I'm NOT looking for any answers, just some tips to an _elegant_ method to
> solve this.
My tutor/mentor and I wrote a chess program a while back - diaganols
were the hardest bit to get working!
Essentially diagonals are treated as though they were ranks and files
on a board rotated through 45 degrees. Doing bitboard lookups then
becomes fairly simple.
A bitboard solution to the n-queens problem would actually be rather
neat for a genetic algorithm, as the genes could correspond directly
to the bitboards. Both are just large integers.
If you haven't already, take a look at Bob Hyatt's bitboard paper.
In this case, though, it is probably simple enough to work out if two
pieces are on the same diagonal:
1. Find the difference in their ranks
2. Find the difference in their files
3. If the answer is the same (regardless of sign) then the pieces
share a diagonal.
More information about the Tutor