Author: Michel Langeveld
Date: 09:30:40 01/11/04
Go up one level in this thread
The attack function change made it 38.3% quicker, it is now as follows: 6 412 358329 -10 b1c3 i8h6 i1h3 b8c6 e2e4 e7e5 7 3086 2813188 18 b1c3 i8h6 i1h3 b8c6 e2e4 e7e5 f2f4 6 273 363232 -10 b1c3 i8h6 i1h3 b8c6 e2e4 e7e5 7 1901 2868337 18 b1c3 i8h6 i1h3 b8c6 e2e4 e7e5 f2f4 Did I squeeze it far enough? /* attack() returns TRUE if square sq is being attacked by side s and FALSE otherwise. */ BOOL attack(int sq, int s) { int j, p, o; int sq144, fromfield, fromfield144; //are we attacked by a pawn? if (s == LIGHT) { //attacked from left if (col[sq] != 0) { fromfield = sq + 9; if (piece[fromfield] == PAWN && color[fromfield] == s) return TRUE; } //attacked from right if (col[sq] != 9) { fromfield = sq + 11; if (piece[fromfield] == PAWN && color[fromfield] == s) return TRUE; } } else { //attacked from left if (col[sq] != 0) { fromfield = sq - 11; if (piece[fromfield] == PAWN && color[fromfield] == s) return TRUE; } //attacked from right if (col[sq] != 9) { fromfield = sq - 9; if (piece[fromfield] == PAWN && color[fromfield] == s) return TRUE; } } sq144 = mailbox80_to_144[sq]; //8 knight directions for (j = 0; j < 8; ++j) { o = offset[KNIGHT][j]; fromfield = mailbox144_to_80[sq144 + o]; //are we from board? if (fromfield == -1) continue; if (color[fromfield] == s) { p = piece[fromfield]; if (p == KNIGHT || p == ARCHBISHOP || p == CHANCELLOR) return TRUE; } } //bishops 4 directions (also valid for archbishop, queens) for (j = 0; j < 4; ++j) { o = offset[BISHOP][j]; for (fromfield144 = sq144;;) { fromfield144 += o; fromfield = mailbox144_to_80[fromfield144]; //are we still on board? if (fromfield == -1) break; //we have a piece if (color[fromfield] != EMPTY) { //is it an opponent piece? if (color[fromfield] == s) { p = piece[fromfield]; if (p == BISHOP || p == ARCHBISHOP || p == QUEEN) return TRUE; } //we can stop slider doesn't go further break; } } } //4 rook directions (also valid for chancelor, queens) for (j = 0; j < 4; ++j) { o = offset[ROOK][j]; for (fromfield144 = sq144;;) { fromfield144 += o; fromfield = mailbox144_to_80[fromfield144]; //are we still on board? if (fromfield == -1) break; //we have a piece if (color[fromfield] != EMPTY) { //is it an opponent piece? if (color[fromfield] == s) { p = piece[fromfield]; if (p == ROOK || p == CHANCELLOR || p == QUEEN) return TRUE; } //we can stop slider doesn't go further break; } } } //look this field is attacked by a king fromfield144 = mailbox80_to_144[kings[side]]; //we calculate a vector between the king of this attacking //color and the current field o = abs(fromfield144 - sq144); if (o == 1 || o == 11 || o == 12 || o == 13) { return TRUE; } return FALSE; }
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.