2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 /* move in SAN notation */
23 san_move(int move
, char *buf
)
28 int piece
, cap_piece
, promote_piece
, type
;
29 int move_legal
, move_check
, move_mate
;
32 assert(move_is_legal(move
));
37 from
= GET_FROM(move
);
40 cap_piece
= CAP_PIECE(move
);
41 promote_piece
= GET_PROMOTE(move
);
42 type
= GET_TYPE(move
);
44 move_legal
= move_check
= move_mate
= FALSE
;
46 gen_legal_moves(&moves
);
48 for (i
= 0; i
< moves
.count
; i
++) {
49 if (make_move(moves
.move
[i
], FALSE
)) {
50 if (move
== moves
.move
[i
]) {
53 if (IS_CHECKED(brd
.wtm
)) {
56 if (!gen_legal_moves(&moves
))
69 if (type
& TYPE_CASTLE
) {
70 if (to
== G1
|| to
== G8
)
71 sprintf(buf
, "%s", "O-O");
73 sprintf(buf
, "%s", "O-O-O");
76 if (cap_piece
|| (type
& TYPE_ENPASSANT
))
77 sprintf(buf
, "%cx%s", (char) (_FILE(from
) + 'a'), char_board
[to
]);
79 sprintf(buf
, "%s", char_board
[to
]);
81 sprintf(tmp
, "=%c", char_pieces
[promote_piece
]);
85 sprintf(buf
, "%c", char_pieces
[piece
]);
87 gen_legal_moves(&moves
);
89 for (i
= 0; i
< moves
.count
; i
++) {
90 if (move
!= moves
.move
[i
]) {
91 if (piece
== PIECE(moves
.move
[i
]) && to
== GET_TO(moves
.move
[i
])) {
92 /* move is ambiguous */
93 if (_FILE(from
) == _FILE(GET_FROM(moves
.move
[i
])))
94 sprintf(tmp
, "%c", (char) (_RANK(from
) + '1'));
96 sprintf(tmp
, "%c", (char) (_FILE(from
) + 'a'));
104 sprintf(tmp
, "x%s", char_board
[to
]);
106 sprintf(tmp
, "%s", char_board
[to
]);