1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| // check if a rook is legal for the active color
function IsRoqueLegal(CP: TChessPanel; Roque: TChessRoque): boolean; stdcall;
{
Les conditions suivantes sont nécessaires pour pouvoir roquer :
1. aucune pièce ne se trouve entre le roi et la tour concernée ;
2. le roi et la tour concernée n'ont encore jamais joué ;
3. le roi n'est pas en échec ;
4. la case traversée par le roi n'est contrôlée par aucune pièce adverse.
The followong conditions must be valid before a rook can happen:
1. no other piece must be present between the king and the concerned rook
2. the king and the concerned rook must never have moved
3. the king must not actually be menaced
4. the case traversed by the king must not be menaced by any adverse piece
}
var
col: integer;
begin
result := false; // technical error
try
case Roque of
crSmall: begin // petit roque du joueur dont c'est le tour
if CP.NextMove=ccWhite then begin
// 1. aucune pièce ne se trouve entre le roi et la tour concernée ;
if (CP.Piece[4,0]<>cpKing) and (CP.Color[4,0]<>ccWhite) then exit;
if (CP.Piece[5,0]<>cpNone) then exit;
if (CP.Piece[6,0]<>cpNone) then exit;
if (CP.Piece[7,0]<>cpRook) and (CP.Color[7,0]<>ccWhite) then exit;
// 2. le roi et la tour concernée n'ont encore jamais joué ;
if CP.WhiteKingMoved then exit;
if CP.RightWhiteRookMoved then exit;
// 3. le roi n'est pas en échec ;
// 4. la case traversée par le roi n'est contrôlée par aucune pièce adverse.
for col:=4 to 6 do if DoesPieceMenaceField(CP,col,0,ccBlack) then exit;
end else begin
// 1. aucune pièce ne se trouve entre le roi et la tour concernée ;
if (CP.Piece[4,7]<>cpKing) and (CP.Color[4,7]<>ccBlack) then exit;
if (CP.Piece[5,7]<>cpNone) then exit;
if (CP.Piece[6,7]<>cpNone) then exit;
if (CP.Piece[7,7]<>cpRook) and (CP.Color[7,7]<>ccBlack) then exit;
// 2. le roi et la tour concernée n'ont encore jamais joué ;
if CP.BlackKingMoved then exit;
if CP.RightBlackRookMoved then exit;
// 3. le roi n'est pas en échec ;
// 4. la case traversée par le roi n'est contrôlée par aucune pièce adverse.
for col:=4 to 6 do if DoesPieceMenaceField(CP,col,7,ccWhite) then exit;
end;
end;
crLarge: begin // grand roque du joueur dont c'est le tour
if CP.NextMove=ccWhite then begin
// 1. aucune pièce ne se trouve entre le roi et la tour concernée ;
if (CP.Piece[4,0]<>cpKing) and (CP.Color[4,0]<>ccWhite) then exit;
if (CP.Piece[3,0]<>cpNone) then exit;
if (CP.Piece[2,0]<>cpNone) then exit;
if (CP.Piece[1,0]<>cpNone) then exit;
if (CP.Piece[0,0]<>cpRook) and (CP.Color[0,0]<>ccWhite) then exit;
// 2. le roi et la tour concernée n'ont encore jamais joué ;
if CP.WhiteKingMoved then exit;
if CP.LeftWhiteRookMoved then exit;
// 3. le roi n'est pas en échec ;
// 4. la case traversée par le roi n'est contrôlée par aucune pièce adverse.
for col:=1 to 4 do if DoesPieceMenaceField(CP,col,0,ccBlack) then exit;
end else begin
// 1. aucune pièce ne se trouve entre le roi et la tour concernée ;
if (CP.Piece[4,7]<>cpKing) and (CP.Color[4,7]<>ccBlack) then exit;
if (CP.Piece[3,7]<>cpNone) then exit;
if (CP.Piece[2,7]<>cpNone) then exit;
if (CP.Piece[1,7]<>cpNone) then exit;
if (CP.Piece[0,7]<>cpRook) and (CP.Color[0,7]<>ccBlack) then exit;
// 2. le roi et la tour concernée n'ont encore jamais joué ;
if CP.BlackKingMoved then exit;
if CP.LeftBlackRookMoved then exit;
// 3. le roi n'est pas en échec ;
// 4. la case traversée par le roi n'est contrôlée par aucune pièce adverse.
for col:=1 to 4 do if DoesPieceMenaceField(CP,col,7,ccWhite) then exit;
end;
end;
end;
result := true;
except
end;
end; |
Partager