Example #1
0
 public void InvalidsquareConvertedToStringThrows(int square)
 {
     Assert.Throws <ArgumentException>(() => NotationHelper.GetSquareString(square));
 }
Example #2
0
        public string Write(Position position, bool shortForm = false)
        {
            var res = new StringBuilder();

            for (int rank = 0; rank < Constants.BoardRanks; rank++)
            {
                int gap = 0;
                for (int file = 0; file < Constants.BoardFiles; file++)
                {
                    var piece = position[rank * Constants.BoardFiles + file];
                    if (piece != Piece.None)
                    {
                        if (gap > 0)
                        {
                            res.Append(gap);
                            gap = 0;
                        }

                        char pieceChar = NotationHelper.GetPieceChar(piece);
                        res.Append(pieceChar);
                    }
                    else
                    {
                        gap++;
                    }
                }
                res.Append(gap > 0 ? gap.ToString() : string.Empty);
                if (rank < 7)
                {
                    res.Append('/');
                }
            }

            res.Append($" {(position.WhiteToMove ? 'w' : 'b')}");

            if (position.CurrentState[0] != Castling.None || position.CurrentState[1] != Castling.None)
            {
                res.Append(' ');
                res.Append(NotationHelper.GetCastlingOptionsString(position.CurrentState[0], position.IsChess960, position.Pieces[0].Rooks, position.Pieces[0].King).ToUpper());
                res.Append(NotationHelper.GetCastlingOptionsString(position.CurrentState[1], position.IsChess960, position.Pieces[1].Rooks, position.Pieces[1].King));
            }
            else
            {
                res.Append(" -");
            }

            if (position.CurrentState.EnPassantSquare > 0)
            {
                res.Append($" {NotationHelper.GetSquareString(position.CurrentState.EnPassantSquare)}");
            }
            else
            {
                res.Append(" -");
            }

            if (!shortForm)
            {
                res.Append($" {position.CurrentState.HalfMoveClock}");
                res.Append($" {position.TotalMoves}");
            }

            return(res.ToString());
        }
Example #3
0
 public void squareConvertedToString(int square, string expectedsquareString)
 {
     Assert.AreEqual(expectedsquareString, NotationHelper.GetSquareString(square));
 }