checkpoint

This commit is contained in:
2021-02-23 18:03:23 -06:00
parent 8d79c75616
commit f644795cd3
38 changed files with 1451 additions and 177 deletions

View File

@@ -0,0 +1,53 @@
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();
}
}
}