12 while (*s ==
' ') ++s;
13 if (s[0] <
'a' || s[0] >
'h' || s[1] <
'1' || s[1] >
'8')
return -1;
14 const int file = s[0] -
'a';
15 const int rank = s[1] -
'1';
16 return FR2SQ(file, rank);
21 c =
static_cast<char>(std::tolower(
static_cast<unsigned char>(c)));
27 default:
return EMPTY;
32 int outMoves[],
char labels[][8],
int maxOut) {
37 for (
int i = 0; i < list->
count && count < maxOut; ++i) {
39 if (
FROMSQ(m) != from)
continue;
44 const int to =
TOSQ(m);
51 case wQ:
case bQ: pc =
'Q';
break;
52 case wR:
case bR: pc =
'R';
break;
53 case wB:
case bB: pc =
'B';
break;
54 case wN:
case bN: pc =
'N';
break;
58 outMoves[count++] = m;
65 const char* destStr,
const int legalMoves[],
int nMoves) {
66 if (!destStr)
return NOMOVE;
70 while (destStr[di] && destStr[di] !=
'\n' && di < 7) { dst[di] = destStr[di]; ++di; }
73 char* eq = std::strchr(dst,
'=');
76 if (eq[1]) promChar = eq[1];
79 const char tail = dst[2];
80 if (tail==
'Q'||tail==
'q'||tail==
'R'||tail==
'r'||tail==
'B'||tail==
'b'||tail==
'N'||tail==
'n') {
87 if (to == -1)
return NOMOVE;
91 for (
int i = 0; i < nMoves && candN < 8; ++i) {
92 const int m = legalMoves[i];
97 if (candN == 0)
return NOMOVE;
99 const int m = cand[0];
101 for (
int i = 0; i < candN; ++i) {
102 const int pm = cand[i];
113 for (
int i = 0; i < candN; ++i) {
114 if (
PROMOTED(cand[i]) == want)
return cand[i];
119 for (
int i = 0; i < candN; ++i) {
int ParseSquare2(const char *s)
Parse "e2" style coordinate into a 120-based square index.
int LegalMovesFrom(S_BOARD *pos, int from, int outMoves[], char labels[][8], int maxOut)
Build list of legal moves that originate from from.
int ParsePromotionPiece(char c, int side)
Map promotion char ('q','r','b','n') to a piece code for the given side. Case-insensitive....
int MatchDestinationMove(S_BOARD *pos, int from, const char *destStr, const int legalMoves[], int nMoves)
Resolve a destination string ("e4", "e8=Q", "e8q") to a move.
int makeMove(S_BOARD *board, int move)
Make a move; returns non-zero if legal (king not left in check).
void takeMove(S_BOARD *board)
Undo the last made move.
void generateAllMoves(const S_BOARD *board, S_MOVELIST *moveList)
Generate all pseudo-legal moves for the side to move.
char * squareToString(const int square)
Convert a board square index to algebraic notation.
S_MOVE moves[MAXPOSITIONMOVES]