public string DrawBoard(ChessOwner perspective, ChessIconFormat format = ChessIconFormat.Text) { var text = new StringBuilder(); text.AppendLine("```"); text.AppendLine(DrawRanks(perspective)); bool isFlipped = perspective == ChessOwner.Black; for (int column = isFlipped ? Max : Min; isFlipped?column >= Min : column <= Max; column += isFlipped ? -1 : 1) { text.Append(column + 1); for (int row = isFlipped ? Max : Min; isFlipped?row >= Min : row <= Max; row += isFlipped ? -1 : 1) { ChessPiece piece = GetPiece(row, column); string tile = piece == null ? EmptyTile : ChessPiece.GetString(piece.Piece, piece.Owner, format); text.Append($" {tile}"); } text.AppendLine(); } text.AppendLine("```"); return(text.ToString()); }
public string DrawMoves(ChessPiece focus, ChessOwner perspective, ChessIconFormat format = ChessIconFormat.Text) { List <Coordinate> moves = GetMoves(focus); var text = new StringBuilder(); text.AppendLine("```"); text.AppendLine(DrawRanks(perspective)); bool isFlipped = perspective == ChessOwner.Black; for (int column = isFlipped ? Max : Min; isFlipped?column >= Min : column <= Max; column += isFlipped ? -1 : 1) { text.Append(column + 1); for (int row = isFlipped ? Max : Min; isFlipped?row >= Min : row <= Max; row += isFlipped ? -1 : 1) { ChessPiece piece = GetPiece(row, column); string tile = piece == null ? moves.Contains(new Coordinate(row, column)) ? "o" : EmptyTile : moves.Contains(new Coordinate(row, column)) && piece.Rank == row && piece.File == column ? "x" : ChessPiece.GetString(piece.Piece, perspective, format); text.Append($" {tile}"); } text.AppendLine(); } text.AppendLine("```"); return(text.ToString()); }
public static string GetString(ChessRank rank, ChessOwner player, ChessIconFormat format = ChessIconFormat.Text) { bool isBlack = player == ChessOwner.Black; bool isEmote = format == ChessIconFormat.Emote; string text = rank switch { ChessRank.Pawn when isEmote => isBlack ? "♙" : "♟", ChessRank.Pawn => "P", ChessRank.Knight when isEmote => isBlack ? "♘" : "♞", ChessRank.Knight => "N", ChessRank.Bishop when isEmote => isBlack ? "♗" : "♝", ChessRank.Bishop => "B", ChessRank.Rook when isEmote => isBlack ? "♖" : "♜", ChessRank.Rook => "R", ChessRank.Queen when isEmote => isBlack ? "♕" : "♛", ChessRank.Queen => "Q", ChessRank.King when isEmote => isBlack ? "♔" : "♚", ChessRank.King => "K", _ => throw new ArgumentException("Unknown rank") }; if (isBlack && !isEmote) { text = text.ToLower(); } return(text); }