Ejemplo n.º 1
0
        public Piece[] ParseRankAndFile()
        {
            var squares = CreateBoard();

            const int rankSections = 8;
            int       rank         = 7;

            for (int rankSectionNdx = 0; rankSectionNdx < rankSections; rankSectionNdx++)
            {
                int file    = 0;
                var section = _sections[rankSectionNdx];
                foreach (char pieceIdentifier in section)
                {
                    var countOfPieces = 1;

                    Piece piece;
                    int   boardNdx = Lookups.FileRankToSquare(file, rank);
                    if (pieceIdentifier >= '1' && pieceIdentifier <= '8')
                    {
                        int.TryParse(pieceIdentifier.ToString(CultureInfo.CurrentCulture), out countOfPieces);
                        piece = new EmptyPiece {
                            Square = boardNdx
                        };
                    }
                    else
                    {
                        piece        = Lookups.FenPieceLookup[pieceIdentifier]();
                        piece.Square = boardNdx;
                    }

                    squares[boardNdx] = piece;
                    file++;

                    for (var count = 1; count < countOfPieces; count++)
                    {
                        boardNdx          = Lookups.FileRankToSquare(file, rank);
                        squares[boardNdx] = new EmptyPiece {
                            Square = boardNdx
                        };
                        file++;
                    }
                }
                rank--;
                if (file > 8)
                {
                    throw new Exception("FEN has found a file larger than eight");
                }
            }
            return(squares);
        }
Ejemplo n.º 2
0
        public int ParseEnPassantSection()
        {
            string section = _sections[EnPassantSection];

            if (section == "-")
            {
                return(0);
            }

            if (section.Length != 2)
            {
                throw new Exception("EnPassant section must be two characters in length");
            }

            int file = section[0] - 'a';
            int rank = section[1] - '1';

            return(Lookups.FileRankToSquare(file, rank));
        }