using System.Diagnostics; namespace Gameboard.ShogiUI.BoardState { [DebuggerDisplay("{WhichPiece} {Owner}")] public class Piece { public WhichPiece WhichPiece { get; } public WhichPlayer Owner { get; private set; } public bool IsPromoted { get; private set; } public Piece(WhichPiece piece, WhichPlayer owner) { WhichPiece = piece; Owner = owner; IsPromoted = false; } public bool CanPromote => !IsPromoted && WhichPiece != WhichPiece.King && WhichPiece != WhichPiece.GoldenGeneral; public string ShortName => WhichPiece switch { WhichPiece.King => " K ", WhichPiece.GoldenGeneral => " G ", WhichPiece.SilverGeneral => IsPromoted ? "^S^" : " S ", WhichPiece.Bishop => IsPromoted ? "^B^" : " B ", WhichPiece.Rook => IsPromoted ? "^R^" : " R ", WhichPiece.Knight => IsPromoted ? "^k^" : " k ", WhichPiece.Lance => IsPromoted ? "^L^" : " L ", WhichPiece.Pawn => IsPromoted ? "^P^" : " P ", _ => " ? ", }; public void ToggleOwnership() { Owner = Owner == WhichPlayer.Player1 ? WhichPlayer.Player2 : WhichPlayer.Player1; } public void Promote() => IsPromoted = true; public void Demote() => IsPromoted = false; public void Capture() { ToggleOwnership(); Demote(); } } }