public void InvalidPieceConvertedToTheCharThrows(int piece) { Assert.Throws <ArgumentException>(() => NotationHelper.GetPieceChar(piece)); }
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()); }
public void PieceConvertedToTheChar(int piece, char expectedChar) { Assert.AreEqual(expectedChar, NotationHelper.GetPieceChar(piece)); }