using Gameboard.ShogiUI.Sockets.ServiceModels.Types; using System; using System.Text; using System.Text.RegularExpressions; namespace Gameboard.ShogiUI.Sockets.Extensions { public static class ModelExtensions { public static string GetShortName(this Models.Piece self) { var name = self.WhichPiece switch { WhichPiece.King => " K ", WhichPiece.GoldGeneral => " G ", WhichPiece.SilverGeneral => self.IsPromoted ? "^S " : " S ", WhichPiece.Bishop => self.IsPromoted ? "^B " : " B ", WhichPiece.Rook => self.IsPromoted ? "^R " : " R ", WhichPiece.Knight => self.IsPromoted ? "^k " : " k ", WhichPiece.Lance => self.IsPromoted ? "^L " : " L ", WhichPiece.Pawn => self.IsPromoted ? "^P " : " P ", _ => " ? ", }; if (self.Owner == WhichPlayer.Player2) name = Regex.Replace(name, @"([^\s]+)\s", "$1."); return name; } public static string PrintStateAsAscii(this Models.Shogi self) { var builder = new StringBuilder(); builder.Append(" Player 2(.)"); builder.AppendLine(); for (var y = 8; y >= 0; y--) { builder.Append("- "); for (var x = 0; x < 8; x++) builder.Append("- - "); builder.Append("- -"); builder.AppendLine(); builder.Append('|'); for (var x = 0; x < 9; x++) { var piece = self.Board[x, y]; if (piece == null) { builder.Append(" "); } else { builder.AppendFormat("{0}", piece.GetShortName()); } builder.Append('|'); } builder.AppendLine(); } builder.Append("- "); for (var x = 0; x < 8; x++) builder.Append("- - "); builder.Append("- -"); builder.AppendLine(); builder.Append(" Player 1"); return builder.ToString(); } } }