// Copyright 1992 by Jon Dart.  All Rights Reserved.

#ifndef _BEARING_H
#define _BEARING_H
#include "board.h"
#include "move.h"

extern const int Direction[2];

extern const byte KnightSquares[64][8];

extern const byte KingSquares[64][8];

extern const byte BishopSquares[64][32];

extern const byte RookSquares[64][32];

extern const int RankIncr;	// add this to move 1 rank

class Bearing
{
     // Finds pseudo-legal moves for individual pieces, plus
     // related functions.

     public:
     
     enum { MaxBearSq = 28 };	     
     
     static Bitmap knight_attacks[64];
     static Bitmap pawn_attacks[64][2];
     static Bitmap king_attacks[64];
     static byte rank_attacks[256][8];
     static byte next_bit_left[256][8];
     static byte next_bit_right[256][8];
     static Bitmap unrot90[256][8];
     static Bitmap unrotda1[256][8];
     static Bitmap unrotda8[256][8];
     static int mobility[256][8];
     static int diagonal_length[64];
     static int Directions[64][64];
     
     // Initialize the bitmaps.  Call before using this class.
     static void init();

     static unsigned BearSq( const Board &board,
	 const Square loc, Square *squares);
     // Returns all squares to which a piece at location 'loc' can move.
     // It does not include castling moves, but does include en passant
     // captures and pawn promotions.  It doesn't check for pins, 
     // and hence may return some illegal moves.
	     
     static unsigned Captures( const Board &board,
	 const Square loc, Move *moves);
     // Returns moves for a piece at location 'loc'
     // that capture another piece or promote a pawn.
     // Enpassant captures are included.  No checks are made for
     // pins.
	     
     static unsigned Attack( const Board &board,
	 const Square loc, const ColorType side,
	 Square *squares);
     // returns a list of all squares on which pieces of color "side"
     // reside which attack the piece at "loc".  The function return
     // value is the number of such pieces.  If "loc" is empty,
     // returns all squares from which pieces can move to "loc".
     // En passant captures are not included.

     static BOOL Pinned( const Board &board, const Square loc,
	     Piece &PinnedByPiece, 
	     Square &PinnedBySquare,
	     int &dir);
     // returns TRUE if the piece at location 'square' is pinned. If it
     // is pinned, also returns PinnedByPiece = piece pinning piece at
     // 'square', PinnedBySquare = pinning piece's square, dir =
     // direction of pin.	     
     // We could call Attacks to get this information, but this is faster.
	     
};

#endif
