using System.Diagnostics; namespace Shogi.Domain { [DebuggerDisplay("{WhichPiece} {Owner}")] public class Piece { public WhichPiece WhichPiece { get; } public WhichPlayer Owner { get; private set; } public bool IsPromoted { get; private set; } public bool IsUpsideDown => Owner == WhichPlayer.Player2; public Piece(WhichPiece piece, WhichPlayer owner, bool isPromoted = false) { WhichPiece = piece; Owner = owner; IsPromoted = isPromoted; } public Piece(Piece piece) : this(piece.WhichPiece, piece.Owner, piece.IsPromoted) { } public bool CanPromote => !IsPromoted && WhichPiece != WhichPiece.King && WhichPiece != WhichPiece.GoldGeneral; public void ToggleOwnership() { Owner = Owner == WhichPlayer.Player1 ? WhichPlayer.Player2 : WhichPlayer.Player1; } public void Promote() => IsPromoted = CanPromote; public void Demote() => IsPromoted = false; public void Capture() { ToggleOwnership(); Demote(); } } }