/*
    Copyright 2015 Harm Jetten

    This file is part of Moby Dam.

    Moby Dam is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Moby Dam is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Moby Dam.  If not, see <http://www.gnu.org/licenses/>.
*/

/* masks to find nearest piece in 'north' diagonals for possible king capture */
/* (relative to bitpos 63) */

#define RAYMASK_NW ((1ULL << 57) | (1ULL << 51) | (1ULL << 45) | (1ULL << 39) \
                  | (1ULL << 33) | (1ULL << 27) | (1ULL << 21))

#define RAYMASK_NE ((1ULL << 58) | (1ULL << 53) | (1ULL << 48) | (1ULL << 43) \
                  | (1ULL << 38) | (1ULL << 33) | (1ULL << 28) | (1ULL << 23))

/* masks to find nearest piece in 'south' diagonals for possible king capture */
/* (relative to bitpos 0) */

#define RAYMASK_SW ((1ULL <<  5) | (1ULL << 10) | (1ULL << 15) | (1ULL << 20) \
                  | (1ULL << 25) | (1ULL << 30) | (1ULL << 35) | (1ULL << 40))

#define RAYMASK_SE ((1ULL <<  6) | (1ULL << 12) | (1ULL << 18) | (1ULL << 24) \
                  | (1ULL << 30) | (1ULL << 36) | (1ULL << 42))

typedef struct bb {
    u64 white;          /* bit positions of white pieces */
    u64 black;          /* bit positions of black pieces */
    u64 kings;          /* bit positions of white and black kings */
    int side;           /* side to move, W or B */
    int moveinfo;       /* additional move info */
    struct bb *parent;  /* ptr to previous board in the tree */
} bitboard;

typedef struct {
    u8 square[32];      /* the long notation square numbers */
} lnentry;

typedef struct {
    lnentry move[128];  /* the long notation moves */
} lnlist;

typedef struct {
    int count;          /* number of moves generated */
    int npcapt;         /* number of pieces captured in each move */
    u64 frombit;        /* during movegen: starting position of captor */
    u64 empty;          /* during movegen: empty positions, including frombit */
    u64 oppbits;        /* during movegen: opponents at start of capture */
    u64 tp[32];         /* during movegen: turning points of capture */
    bitboard *bb;       /* ptr to old board */
    lnentry *lnptr;     /* ptr to long notation array */
    bitboard move[128]; /* the new boards resulting from the moves */
} movelist;

extern void gen_moves(bitboard *bb, movelist *listptr, lnentry *lnptr, bool genall);
