70 lines
1.8 KiB
C#
70 lines
1.8 KiB
C#
using PathFinding;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
|
|
namespace Gameboard.ShogiUI.BoardState
|
|
{
|
|
[DebuggerDisplay("{WhichPiece} {Owner}")]
|
|
public abstract class Piece : IPlanarElement
|
|
{
|
|
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 bool IsRanged => WhichPiece switch
|
|
{
|
|
WhichPiece.Bishop => true,
|
|
WhichPiece.Rook => true,
|
|
WhichPiece.Lance => !IsPromoted,
|
|
_ => false,
|
|
};
|
|
|
|
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();
|
|
}
|
|
|
|
public abstract ICollection<Path> GetPaths();
|
|
|
|
public abstract Piece DeepClone();
|
|
|
|
public bool IsUpsideDown => Owner == WhichPlayer.Player2;
|
|
}
|
|
}
|