// converts a move to string notation for FEN void move_to_str(move_t mv, char *buf, size_t bufsize) { square_t f = from_square(mv); // from-square square_t t = to_square(mv); // to-square rot_t r = rot_of(mv); // rotation const char *orig_buf = buf; buf += square_to_str(f, buf, bufsize); if (f != t) { buf += square_to_str(t, buf, bufsize - (buf - orig_buf)); } else { switch (r) { case NONE: buf += square_to_str(t, buf, bufsize - (buf - orig_buf)); break; case RIGHT: buf += snprintf(buf, bufsize - (buf - orig_buf), "R"); break; case UTURN: buf += snprintf(buf, bufsize - (buf - orig_buf), "U"); break; case LEFT: buf += snprintf(buf, bufsize - (buf - orig_buf), "L"); break; default: tbassert(false, "Whoa, now. Whoa, I say.\n"); // Bad, bad, bad break; } } }
char *move_to_fullalg(board_t *board, move_t *move) { char *s = (char *) malloc(6); char prom[4] = "nbrq"; square_to_str(s, move->source); square_to_str(s + 2, move->destination); s[4] = '\0'; s[5] = '\0'; if ((PIECE(board->square[move->source]) == PAWN) && ((move->destination < 8) || (move->destination >= 56))) s[4] = prom[(move->promotion_piece - 2) / 2]; return s; }