48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using PathFinding;
|
|
using System.Diagnostics;
|
|
|
|
namespace Gameboard.ShogiUI.BoardState.Pieces
|
|
{
|
|
[DebuggerDisplay("{WhichPiece} {Owner}")]
|
|
public abstract class Piece : IPlanarElement
|
|
{
|
|
protected MoveSet promotedMoveSet;
|
|
protected MoveSet moveSet;
|
|
|
|
public MoveSet MoveSet => IsPromoted ? promotedMoveSet : moveSet;
|
|
public abstract Piece DeepClone();
|
|
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)
|
|
{
|
|
WhichPiece = piece;
|
|
Owner = owner;
|
|
IsPromoted = false;
|
|
}
|
|
|
|
public bool CanPromote => !IsPromoted
|
|
&& WhichPiece != WhichPiece.King
|
|
&& WhichPiece != WhichPiece.GoldenGeneral;
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|