While writing the isUnderAttack() function I was wondering about what makes a good chess engine? I realised that it is not only by using the best algorithms and well-informed heuristic functions, but that all the small optimisations also adds up! For example, the method that I just mentioned checks to see if a particular square is under attack. As this function gets called during move generation (for castling) it needs to be pretty fast!
I suspect that by simply changing the order in which pieces are checked as potential attackers for the square can make a difference. My current order is bishops/queens, rooks/queens, knights, pawns, king. The ordering is derived from the fact that the pieces that hinder castling is usually bishops, followed by rooks (I get queens for free!) . If a valid attacker is found, the function returns straight away, skipping all the others.
Once I get Vicki to play valid chess, I can start experimenting with these to determine the actual difference that such a seemingly insignificant change could bring.