mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Last touches to from_fen()
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
839088205e
commit
c2048136ec
1 changed files with 24 additions and 16 deletions
|
@ -25,6 +25,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <map>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
@ -42,6 +43,18 @@ using std::string;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
|
struct PieceLetters : std::map<char, Piece> {
|
||||||
|
|
||||||
|
PieceLetters() {
|
||||||
|
|
||||||
|
operator[]('K') = WK; operator[]('k') = BK;
|
||||||
|
operator[]('Q') = WQ; operator[]('q') = BQ;
|
||||||
|
operator[]('R') = WR; operator[]('r') = BR;
|
||||||
|
operator[]('B') = WB; operator[]('b') = BB;
|
||||||
|
operator[]('N') = WN; operator[]('n') = BN;
|
||||||
|
operator[]('P') = WP; operator[]('p') = BP;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Variables
|
//// Variables
|
||||||
|
@ -142,15 +155,12 @@ void Position::from_fen(const string& fen) {
|
||||||
6) Fullmove number: The number of the full move. It starts at 1, and is incremented after Black's move.
|
6) Fullmove number: The number of the full move. It starts at 1, and is incremented after Black's move.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const string pieceLetters = "KQRBNPkqrbnp";
|
static PieceLetters pieceLetters;
|
||||||
static const Piece pieces[] = { WK, WQ, WR, WB, WN, WP, BK, BQ, BR, BB, BN, BP };
|
|
||||||
|
|
||||||
|
char token;
|
||||||
|
std::istringstream ss(fen);
|
||||||
Rank rank = RANK_8;
|
Rank rank = RANK_8;
|
||||||
File file = FILE_A;
|
File file = FILE_A;
|
||||||
size_t idx;
|
|
||||||
|
|
||||||
std::istringstream ss(fen);
|
|
||||||
char token;
|
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
@ -159,8 +169,7 @@ void Position::from_fen(const string& fen) {
|
||||||
{
|
{
|
||||||
if (isdigit(token))
|
if (isdigit(token))
|
||||||
{
|
{
|
||||||
// Skip the given number of files
|
file += token - '0'; // Skip the given number of files
|
||||||
file += token - '1' + 1;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (token == '/')
|
else if (token == '/')
|
||||||
|
@ -170,11 +179,10 @@ void Position::from_fen(const string& fen) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = pieceLetters.find(token);
|
if (pieceLetters.find(token) == pieceLetters.end())
|
||||||
if (idx == string::npos)
|
|
||||||
goto incorrect_fen;
|
goto incorrect_fen;
|
||||||
|
|
||||||
put_piece(pieces[idx], make_square(file, rank));
|
put_piece(pieceLetters[token], make_square(file, rank));
|
||||||
file++;
|
file++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,15 +213,15 @@ void Position::from_fen(const string& fen) {
|
||||||
Square fenEpSquare = make_square(file_from_char(col), rank_from_char(row));
|
Square fenEpSquare = make_square(file_from_char(col), rank_from_char(row));
|
||||||
Color them = opposite_color(sideToMove);
|
Color them = opposite_color(sideToMove);
|
||||||
|
|
||||||
if (attacks_from<PAWN>(fenEpSquare, them) & this->pieces(PAWN, sideToMove))
|
if (attacks_from<PAWN>(fenEpSquare, them) & pieces(PAWN, sideToMove))
|
||||||
st->epSquare = fenEpSquare;
|
st->epSquare = fenEpSquare;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5-6. Halfmove clock and fullmove number are not parsed
|
// 5-6. Halfmove clock and fullmove number are not parsed
|
||||||
|
|
||||||
// Various initialisations
|
// Various initialisations
|
||||||
castleRightsMask[make_square(initialKFile, RANK_1)] ^= (WHITE_OO|WHITE_OOO);
|
castleRightsMask[make_square(initialKFile, RANK_1)] ^= WHITE_OO | WHITE_OOO;
|
||||||
castleRightsMask[make_square(initialKFile, RANK_8)] ^= (BLACK_OO|BLACK_OOO);
|
castleRightsMask[make_square(initialKFile, RANK_8)] ^= BLACK_OO | BLACK_OOO;
|
||||||
castleRightsMask[make_square(initialKRFile, RANK_1)] ^= WHITE_OO;
|
castleRightsMask[make_square(initialKRFile, RANK_1)] ^= WHITE_OO;
|
||||||
castleRightsMask[make_square(initialKRFile, RANK_8)] ^= BLACK_OO;
|
castleRightsMask[make_square(initialKRFile, RANK_8)] ^= BLACK_OO;
|
||||||
castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO;
|
castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO;
|
||||||
|
|
Loading…
Add table
Reference in a new issue