?? fen.cpp
字號(hào):
// fen.cpp
// includes
#include <cctype>
#include <cstdlib>
#include "fen.h"
// "constants"
const char *const start_fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
// functions
// board_from_fen()
void board_from_fen(board_t *board, const char fen [])
{
int pos;
int file, rank, sq;
int c;
int i, len;
int piece;
int pawn;
board_clear(board);
pos = 0;
c = fen[pos];
// piece placement
for ( rank = (0xB); rank >= (0x4); rank-- )
{
for ( file = (0x4); file <= (0xB); )
{
if(c >= '1' && c <= '8')
{ // empty square(s)
len = c - '0';
for ( i = 0; i < len; i++ )
{
board->square[SQUARE_MAKE(file, rank)] = 0;
file++;
}
}
else
{ // piece
piece = piece_from_char(c);
board->square[SQUARE_MAKE(file, rank)] = piece;
file++;
}
c = fen[++pos];
}
if(rank > (0x4))
{
c = fen[++pos];
}
}
// active color
c = fen[++pos];
switch(c)
{
case 'w':
board->turn = 0;
break;
case 'b':
board->turn = 1;
break;
default:
break;
}
c = fen[++pos];
// castling
c = fen[++pos];
board->flags = 0;
if(c == '-')
{ // no castling rights
c = fen[++pos];
}
else
{
if(c == 'K')
{
if(board->square[(0x48)] == ((1 << 7) | (1 << 0)) && board->square[(0x4B)] == ((1 << 6) | (1 << 0)))
board->flags |= (1 << 0);
c = fen[++pos];
}
if(c == 'Q')
{
if(board->square[(0x48)] == ((1 << 7) | (1 << 0)) && board->square[(0x44)] == ((1 << 6) | (1 << 0)))
board->flags |= (1 << 1);
c = fen[++pos];
}
if(c == 'k')
{
if(board->square[(0xB8)] == ((1 << 7) | (1 << 1)) && board->square[(0xBB)] == ((1 << 6) | (1 << 1)))
board->flags |= (1 << 2);
c = fen[++pos];
}
if(c == 'q')
{
if(board->square[(0xB8)] == ((1 << 7) | (1 << 1)) && board->square[(0xB4)] == ((1 << 6) | (1 << 1)))
board->flags |= (1 << 3);
c = fen[++pos];
}
}
// en-passant
c = fen[++pos];
if(c == '-')
{ // no en-passant
sq = 0;
c = fen[++pos];
}
else
{
file = file_from_char(c);
c = fen[++pos];
rank = rank_from_char(c);
c = fen[++pos];
sq = SQUARE_MAKE(file, rank);
pawn = SQUARE_EP_DUAL(sq);
if(board->square[sq] != 0 || board->square[pawn] != PAWN_MAKE(COLOUR_OPP(board->turn))
|| (board->square[pawn - 1] != PAWN_MAKE(board->turn) && board->square[pawn + 1] != PAWN_MAKE(board->turn)))
{
sq = 0;
}
}
board->ep_square = sq;
// halfmove clock
board->ply_nb = 0;
if(c != ' ')
{
goto update;
}
c = fen[++pos];
if(!isdigit(c))
{
goto update;
}
board->ply_nb = atoi(&fen[pos]);
// board update
update:
board_init_list(board);
}
// end of fen.cpp
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -