예제 #1
0
        /// <summary>
        /// Converts the ChessState to a FEN board
        /// </summary>
        /// <returns>FEN board</returns>
        public string ToFenBoard()
        {
            StringBuilder strBuild = new StringBuilder();

            strBuild.Append(CurrentBoard.ToPartialFenBoard());

            if (CurrentPlayerColor == ChessColor.White)
            {
                strBuild.Append(" w");
            }
            else
            {
                strBuild.Append(" b");
            }

            //place holder for castling (not currently supported)
            strBuild.Append(" " + CastlingToFen());

            //place holder for en passant (not currently supported)
            strBuild.Append(EnPassantToFen());

            //half and full moves
            strBuild.Append(" " + HalfMoves.ToString() + " " + FullMoves.ToString());


            return(strBuild.ToString());
        }
예제 #2
0
        public void Process(char c, ref IProcess step)
        {
            if ((c >= 'a') && (c <= 'h'))
            {
                if (this.result.EnPassantSquare != null)
                {
                    this.result.Error = true;
                    step = null;
                }
                this.result.EnPassantSquare = $"{c}";
            }
            else if ((c >= '1') && (c <= '8'))
            {
                if ((this.result.EnPassantSquare == null) ||
                    (this.result.EnPassantSquare.Length != 1)
                    )
                {
                    this.result.Error = true;
                    step = null;
                    return;
                }
                char ep = this.result.EnPassantSquare[0];
                if ((ep < 'a') || (ep > 'h'))
                {
                    this.result.Error = true;
                    step = null;
                }
                this.result.EnPassantSquare += $"{c}";
            }
            else if (c == '-')
            {
                if (this.processedChar)
                {
                    this.result.Error = true;
                    step = null;
                }
                this.result.EnPassantSquare = "-";
            }
            else if (c == ' ')
            {
                step = new HalfMoves(this.result);
            }
            else
            {
                this.result.Error = true;
                step = null;
            }

            this.processedChar = true;
        }