Before changing Piece[,] to Dictionary<string,Piece>
This commit is contained in:
@@ -1,27 +1,59 @@
|
||||
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||
using PathFinding;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Gameboard.ShogiUI.Sockets.Models
|
||||
{
|
||||
public class Piece
|
||||
[DebuggerDisplay("{WhichPiece} {Owner}")]
|
||||
public class Piece : IPlanarElement
|
||||
{
|
||||
public bool IsPromoted { get; }
|
||||
public WhichPlayer Owner { get; }
|
||||
public WhichPiece WhichPiece { get; }
|
||||
public WhichPlayer Owner { get; private set; }
|
||||
public bool IsPromoted { get; private set; }
|
||||
public bool IsUpsideDown => Owner == WhichPlayer.Player2;
|
||||
|
||||
public Piece(bool isPromoted, WhichPlayer owner, WhichPiece whichPiece)
|
||||
public Piece(WhichPiece piece, WhichPlayer owner, bool isPromoted = false)
|
||||
{
|
||||
IsPromoted = isPromoted;
|
||||
WhichPiece = piece;
|
||||
Owner = owner;
|
||||
WhichPiece = whichPiece;
|
||||
IsPromoted = isPromoted;
|
||||
}
|
||||
|
||||
public Piece(Rules.Pieces.Piece piece)
|
||||
public bool CanPromote => !IsPromoted
|
||||
&& WhichPiece != WhichPiece.King
|
||||
&& WhichPiece != WhichPiece.GoldGeneral;
|
||||
|
||||
public void ToggleOwnership()
|
||||
{
|
||||
IsPromoted = piece.IsPromoted;
|
||||
Owner = (WhichPlayer)piece.Owner;
|
||||
WhichPiece = (WhichPiece)piece.WhichPiece;
|
||||
Owner = Owner == WhichPlayer.Player1
|
||||
? WhichPlayer.Player2
|
||||
: WhichPlayer.Player1;
|
||||
}
|
||||
|
||||
public void Promote() => IsPromoted = CanPromote;
|
||||
|
||||
public void Demote() => IsPromoted = false;
|
||||
|
||||
public void Capture()
|
||||
{
|
||||
ToggleOwnership();
|
||||
Demote();
|
||||
}
|
||||
|
||||
// TODO: There is no reason to make "new" MoveSets every time this property is accessed.
|
||||
public MoveSet MoveSet => WhichPiece switch
|
||||
{
|
||||
WhichPiece.King => new MoveSet(this, MoveSets.King),
|
||||
WhichPiece.GoldGeneral => new MoveSet(this, MoveSets.GoldGeneral),
|
||||
WhichPiece.SilverGeneral => new MoveSet(this, IsPromoted ? MoveSets.GoldGeneral : MoveSets.SilverGeneral),
|
||||
WhichPiece.Bishop => new MoveSet(this, IsPromoted ? MoveSets.PromotedBishop : MoveSets.Bishop),
|
||||
WhichPiece.Rook => new MoveSet(this, IsPromoted ? MoveSets.PromotedRook : MoveSets.Rook),
|
||||
WhichPiece.Knight => new MoveSet(this, IsPromoted ? MoveSets.GoldGeneral : MoveSets.Knight),
|
||||
WhichPiece.Lance => new MoveSet(this, IsPromoted ? MoveSets.GoldGeneral : MoveSets.Lance),
|
||||
WhichPiece.Pawn => new MoveSet(this, IsPromoted ? MoveSets.GoldGeneral : MoveSets.Pawn),
|
||||
_ => throw new System.NotImplementedException()
|
||||
};
|
||||
|
||||
public ServiceModels.Socket.Types.Piece ToServiceModel()
|
||||
{
|
||||
return new ServiceModels.Socket.Types.Piece
|
||||
|
||||
Reference in New Issue
Block a user