/* move generator hes@log-sv.se 890318
Modified: 890606 NEWMOVE Levels 1-6 for easier debugging */
/* init taxi and dist data */
d
= abs(column
[a
]-column
[b
]);
distdata
[a
][b
] = (d
> di
? d
: di
);
struct sqdata posdata
[3][8][64][64];
static short direc
[8][8] = {
0, 0, 0, 0, 0, 0, 0, 0, /* no_piece = 0 */
-10,-11, -9, 0, 0, 0, 0, 0, /* wpawn = 1 */
-21,-19,-12, -8, 21, 19, 12, 8, /* knight = 2 */
-11, -9, 11, 9, 0, 0, 0, 0, /* bishop = 3 */
-10, -1, 10, 1, 0, 0, 0, 0, /* rook = 4 */
-11, -9,-10, -1, 11, 9, 10, 1, /* queen = 5 */
-11, -9,-10, -1, 11, 9, 10, 1, /* king = 6 */
0, 0, 0, 0, 0, 0, 0, 0};/* no_piece = 7 */
static short dc
[3] = {-1,1,0};
static short max_steps
[8] = {0,2,1,7,7,7,1,0};
static short unmap
[120] = {
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1, 0, 1, 2, 3, 4, 5, 6, 7,-1,
-1, 8, 9,10,11,12,13,14,15,-1,
-1,16,17,18,19,20,21,22,23,-1,
-1,24,25,26,27,28,29,30,31,-1,
-1,32,33,34,35,36,37,38,39,-1,
-1,40,41,42,43,44,45,46,47,-1,
-1,48,49,50,51,52,53,54,55,-1,
-1,56,57,58,59,60,61,62,63,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
void Initialize_moves() {
short c
,ptyp
,po
,p0
,d
,di
,s
;
for(ptyp
=0;ptyp
<8;ptyp
++)
posdata
[c
][ptyp
][po
][p0
].nextpos
= po
;
posdata
[c
][ptyp
][po
][p0
].nextdir
= po
;
/* dest is a function of dir and step */
for(ptyp
=1;ptyp
<7;ptyp
++)
p
= posdata
[c
][ptyp
][unmap
[po
]];
if (dc
[c
]*direc
[ptyp
][d
] != 0) {
for(s
=0;s
<max_steps
[ptyp
];s
++) {
p0
= p0
+ dc
[c
]*direc
[ptyp
][d
];
/* break if (off board) or
(pawns move two steps from home square) */
(ptyp
== pawn
&& s
>0 && (d
>0 || Stboard
[unmap
[po
]] != ptyp
)))
/* sort dest in number of steps order */
if (steps
[sorted
[di
-1]] < s
)
sorted
[di
] = sorted
[di
-1];
/* update posdata, pawns have two threads (capture and no capture) */
for(s
=0;s
<steps
[0];s
++) {
p
[p0
].nextpos
= dest
[0][s
];
p
[p0
].nextdir
= dest
[d
][0];
p
[p0
].nextdir
= dest
[sorted
[0]][0];
for(s
=0;s
<steps
[sorted
[d
]];s
++) {
p
[p0
].nextpos
= dest
[sorted
[d
]][s
];
p
[p0
].nextdir
= dest
[sorted
[d
+1]][0];
/* else is already initialised */
printf("Ptyp:%d Position:%d\n{",ptyp
,unmap
[po
]);
for(p0
=0;p0
<63;p0
++) printf("%d,",p
[p0
].nextpos
);
printf("%d};\n",p
[63].nextpos
);
for(p0
=0;p0
<63;p0
++) printf("%d,",p
[p0
].nextdir
);
printf("%d};\n",p
[63].nextdir
);
See if any piece with color 'side' ataks sq. First check pawns
Then Queen, Bishop, Rook and King and last Knight.
register struct sqdata
*p
;
p
= posdata
[1-side
][pawn
][sq
];
u
= p
[sq
].nextdir
; /* follow captures thread */
if (board
[u
] == pawn
&& color
[u
] == side
) return(true);
if (distance(sq
,PieceList
[side
][0]) == 1) return(true);
/* try a queen bishop capture */
p
= posdata
[side
][bishop
][sq
];
if (color
[u
] == neutral
) {
(board
[u
] == queen
|| board
[u
] == bishop
))
/* try a queen rook capture */
p
= posdata
[side
][rook
][sq
];
if (color
[u
] == neutral
) {
(board
[u
] == queen
|| board
[u
] == rook
))
/* try a knight capture */
p
= posdata
[side
][knight
][sq
];
if (color
[u
] == neutral
) {
if (color
[u
] == side
&& board
[u
] == knight
) return(true);
Find Bishop and Rook mobility, XRAY attacks, and pins. Increment the
hung[] array if a pin is found.
register short u
,piece
,pin
;
register struct sqdata
*p
;
p
= posdata
[color
[sq
]][piece
][sq
];
pin
= -1; /* start new direction */
if (color
[u
] == neutral
) {
if (p
[u
].nextpos
== p
[u
].nextdir
) pin
= -1; /* oops new direction */
if (board
[u
] == pawn
|| board
[u
] == king
)
if (p
[u
].nextpos
!= p
[u
].nextdir
)
pin
= u
; /* not on the edge and on to find a pin */
else if (color
[u
] == c2
&& (board
[u
] > piece
|| atk2
[u
] == 0))
atk1
[pin
] > control
[board
[pin
]]+1)
pin
= -1; /* new direction */
pin
= -1; /* new direction */
CaptureList(side
,xside
,ply
)
register struct sqdata
*p
;
TrPnt
[ply
+1] = TrPnt
[ply
];
node
= &Tree
[TrPnt
[ply
]];
for (i
= 0; i
<= PieceCnt
[side
]; i
++)
p
= posdata
[side
][piece
][sq
];
u
= p
[sq
].nextdir
; /* follow captures thread */
node
->f
= sq
; node
->t
= u
;
node
->score
= value
[board
[u
]] + svalue
[board
[u
]] - piece
;
node
->f
= sq
; node
->t
= u
;
node
->score
= value
[board
[u
]] + svalue
[board
[u
]] - piece
;
GenMoves(ply
,sq
,side
,xside
)
Generate moves for a piece. The moves are taken from the
precalulated array posdata. If the board is free, next move
is choosen from nextpos else from nextdir.
register struct sqdata
*p
;
p
= posdata
[side
][piece
][sq
];
u
= p
[sq
].nextdir
; /* follow captures thread */
if (color
[u
] == xside
) LinkMove(ply
,sq
,u
,xside
);
u
= p
[sq
].nextpos
; /* and follow no captures thread */
if (color
[u
] == neutral
&& (u
!= sq
+16 || color
[u
-8] == neutral
)
&& (u
!= sq
-16 || color
[u
+8] == neutral
)) {
LinkMove(ply
,sq
,u
,xside
);
if (color
[u
] == neutral
) {
LinkMove(ply
,sq
,u
,xside
);
if (color
[u
] == xside
) LinkMove(ply
,sq
,u
,xside
);