Esempio n. 1
0
        public override string ToString()
        {
            var move = Lookups.MapSquareToRankFile(PieceToMove.Square) + Lookups.MapSquareToRankFile(ToSquare);

            if (PromotedTo.Type != PieceType.Empty)
            {
                move += PromotedTo.ToString();
            }

            return(move);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private Piece[] CreateBoard()
        {
            var squares = new Piece[120];

            for (int i = 0; i < squares.Length; i++)
            {
                squares[i] = new OffBoardPiece();
            }

            for (int i = 0; i < 64; i++)
            {
                squares[Lookups.Map64To120(i)] = new EmptyPiece();
            }

            return(squares);
        }
Esempio n. 4
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));
        }