Before changing Piece[,] to Dictionary<string,Piece>

This commit is contained in:
2021-07-26 06:28:56 -05:00
parent f8f779e84c
commit 178cb00253
73 changed files with 1537 additions and 1418 deletions

View File

@@ -0,0 +1,64 @@
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.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 void PrintStateAsAscii(this Models.Shogi self)
{
var builder = new StringBuilder();
builder.Append(" Player 2(.)");
builder.AppendLine();
for (var y = 0; y < 9; 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[y, x];
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");
Console.WriteLine(builder.ToString());
}
}
}