add move_str()
This commit is contained in:
45
src/move.c
45
src/move.c
@@ -88,6 +88,35 @@
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* move_str() - get a move string
|
||||
* @dst: destination memory
|
||||
* @move: move
|
||||
* @flags: moves selection and display options.
|
||||
*
|
||||
* Possible flags are:
|
||||
* M_PR_CAPT: print move if capture
|
||||
* M_PR_NCAPT: print move if non capture
|
||||
* M_PR_NUM: print also move number
|
||||
* M_PR_LONG: print long notation
|
||||
* M_PR_NL: print a newline after move
|
||||
* M_PR_EVAL: print move eval
|
||||
*/
|
||||
char *move_str(char *dst, const move_t move, __unused const int flags)
|
||||
{
|
||||
square_t from = move_from(move);
|
||||
square_t to = move_to(move);
|
||||
int len;
|
||||
sprintf(dst, "%s-%s%n", sq_to_string(from), sq_to_string(to), &len);
|
||||
|
||||
if (move & M_PROMOTION) {
|
||||
piece_t promoted = move_promoted(move);
|
||||
sprintf(dst + len, "=%s", piece_to_low(promoted));
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* moves_print() - print movelist moves.
|
||||
* @moves: &movelist_t moves list
|
||||
@@ -103,12 +132,10 @@
|
||||
*/
|
||||
void moves_print(movelist_t *moves, __unused int flags)
|
||||
{
|
||||
printf("%2d:", moves->nmoves);
|
||||
for (int m = 0; m < moves->nmoves; ++m) {
|
||||
square_t from = move_from(moves->move[m]);
|
||||
square_t to = move_to(moves->move[m]);
|
||||
printf(" %s-%s", sq_to_string(from), sq_to_string(to));
|
||||
}
|
||||
char str[16];
|
||||
//printf("%2d:", moves->nmoves);
|
||||
for (int m = 0; m < moves->nmoves; ++m)
|
||||
printf("%s ", move_str(str, moves->move[m], flags));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@@ -120,12 +147,16 @@ static int _moves_cmp_bysquare(const void *p1, const void *p2)
|
||||
square_t t1 = move_to(m1);
|
||||
square_t f2 = move_from(m2);
|
||||
square_t t2 = move_to(m2);
|
||||
|
||||
piece_t prom1 = move_promoted(m1);
|
||||
piece_t prom2 = move_promoted(m2);
|
||||
if (f1 < f2) return -1;
|
||||
if (f1 > f2) return 1;
|
||||
/* f1 == f2 */
|
||||
if (t1 < t2) return -1;
|
||||
if (t1 > t2) return 1;
|
||||
/* t1 == t2 */
|
||||
if (prom1 < prom2) return -1;
|
||||
if (prom1 > prom2) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
37
src/move.h
37
src/move.h
@@ -21,13 +21,13 @@
|
||||
/* move structure:
|
||||
* 3 2 2 1 1 1 1 1 1
|
||||
* 1 5 3 8 7 5 4 2 1 6 5 0
|
||||
* UUUUUUUU FFFFFF ppp ccc tttttt ffffff
|
||||
* UUUUUUUU FFFFFF ccc ppp tttttt ffffff
|
||||
*
|
||||
* bits len range type mask get desc
|
||||
* ffffff 6 0-5 square_t 3f &63 from
|
||||
* tttttt 6 6-11 square_t fc0 (>>6)&63 to
|
||||
* ccc 3 12-14 piece_type_t 7000 (>>12)&7 captured
|
||||
* ppp 3 15-17 piece_type_t 38000 (>>15)&7 promoted
|
||||
* ccc 3 12-14 piece_type_t 7000 (>>12)&7 captured
|
||||
* FFFFFF 6 18-23 move_flags_t fc0000 N/A flags
|
||||
* UUUUUUUU 8 24-31 unused fe000000 N/A future usage ?
|
||||
*/
|
||||
@@ -51,25 +51,11 @@ typedef struct __movelist_s {
|
||||
int curmove; /* current move (use) */
|
||||
} movelist_t;
|
||||
|
||||
|
||||
/* move flags */
|
||||
//#define M_FLAGS_BEG 18
|
||||
//#define M_HAS_FLAGS mask(M_FLAGS_BEG + 0) /* probably useless */
|
||||
//#define M_CAPTURE mask(M_FLAGS_BEG + 0)
|
||||
//#define M_EN_PASSANT mask(M_FLAGS_BEG + 1)
|
||||
//#define M_PROMOTION mask(M_FLAGS_BEG + 2)
|
||||
//#define M_CASTLE_K mask(M_FLAGS_BEG + 3) /* maybe only one ? */
|
||||
//#define M_CASTLE_Q mask(M_FLAGS_BEG + 4) /* maybe only one ? */
|
||||
//#define M_CHECK mask(M_FLAGS_BEG + 5) /* probably unknown/useless */
|
||||
|
||||
//#define M_FLAGS (M_CAPTURE | M_ENPASSANT | M_PROMOTION |
|
||||
// M_CASTLE_K | M_CASTLE_Q | M_CHECK)
|
||||
//#define M_NORMAL (~M_FLAGS)
|
||||
|
||||
static inline square_t move_from(move_t move)
|
||||
{
|
||||
return move & 077;
|
||||
}
|
||||
|
||||
static inline square_t move_to(move_t move)
|
||||
{
|
||||
return (move >> 6) & 077;
|
||||
@@ -77,12 +63,12 @@ static inline square_t move_to(move_t move)
|
||||
|
||||
static inline piece_t move_promoted(move_t move)
|
||||
{
|
||||
return (move >> 15) & 07;
|
||||
return (move >> 12) & 07;
|
||||
}
|
||||
|
||||
static inline piece_t move_captured(move_t move)
|
||||
static inline piece_type_t move_captured(move_t move)
|
||||
{
|
||||
return (move >> 12) & 07;
|
||||
return (move >> 15) & 07;
|
||||
}
|
||||
|
||||
static inline move_t move_make(square_t from, square_t to)
|
||||
@@ -103,13 +89,13 @@ static inline move_t move_make_capture(square_t from, square_t to)
|
||||
static inline move_t move_make_promote(square_t from, square_t to,
|
||||
piece_type_t promoted)
|
||||
{
|
||||
return move_make_flags(from, to, M_PROMOTION) | (promoted << 15);
|
||||
return move_make_flags(from, to, M_PROMOTION) | (promoted << 12);
|
||||
}
|
||||
|
||||
static inline move_t move_make_promote_capture(square_t from, square_t to,
|
||||
piece_type_t promoted)
|
||||
{
|
||||
return move_make_flags(from, to, M_CAPTURE | M_PROMOTION) | (promoted << 15);
|
||||
return move_make_flags(from, to, M_CAPTURE | M_PROMOTION) | (promoted << 12);
|
||||
}
|
||||
|
||||
/* moves_print flags
|
||||
@@ -118,6 +104,7 @@ static inline move_t move_make_promote_capture(square_t from, square_t to,
|
||||
#define M_PR_NCAPT 0x02
|
||||
#define M_PR_NUM 0x04
|
||||
#define M_PR_NL 0x08
|
||||
#define M_UCI 0x10 /* UCI style - e7e8q */
|
||||
#define M_PR_EVAL 0x20 /* separate captures */
|
||||
#define M_PR_SEPARATE 0x40 /* separate captures */
|
||||
#define M_PR_LONG 0x80
|
||||
@@ -126,9 +113,9 @@ static inline move_t move_make_promote_capture(square_t from, square_t to,
|
||||
//void moves_pool_stats();
|
||||
|
||||
//int move_print(int movenum, move_t *move, move_flags_t flags);
|
||||
|
||||
extern void moves_print(movelist_t *moves, int flags);
|
||||
extern void move_sort_by_sq(movelist_t *moves);
|
||||
char *move_str(char *dst, const move_t move, __unused const int flags);
|
||||
void moves_print(movelist_t *moves, int flags);
|
||||
void move_sort_by_sq(movelist_t *moves);
|
||||
|
||||
//extern int pseudo_moves_castle(pos_t *pos, bool color, bool doit, bool do_king);
|
||||
//int pseudo_moves_gen(pos_t *pos, piece_list_t *piece, bool doit, bool do_king);
|
||||
|
Reference in New Issue
Block a user