using Gameboard.ShogiUI.Sockets.ServiceModels.Types; using Gameboard.ShogiUI.Sockets.Utilities; using System.Diagnostics; using System.Numerics; namespace Gameboard.ShogiUI.Sockets.Models { [DebuggerDisplay("{From} - {To}")] public class Move { public Vector2? From { get; } // TODO: Use string notation public bool IsPromotion { get; } public WhichPiece? PieceFromHand { get; } public Vector2 To { get; } public Move(Vector2 from, Vector2 to, bool isPromotion = false) { From = from; To = to; IsPromotion = isPromotion; } public Move(WhichPiece pieceFromHand, Vector2 to) { PieceFromHand = pieceFromHand; To = to; } /// /// Constructor to represent moving a piece on the Board to another position on the Board. /// /// Position the piece is being moved from. /// Position the piece is being moved to. /// If the moving piece should be promoted. public Move(string fromNotation, string toNotation, bool isPromotion = false) { From = NotationHelper.FromBoardNotation(fromNotation); To = NotationHelper.FromBoardNotation(toNotation); IsPromotion = isPromotion; } /// /// Constructor to represent moving a piece from the Hand to the Board. /// /// The piece being moved from the Hand to the Board. /// Position the piece is being moved to. /// If the moving piece should be promoted. public Move(WhichPiece pieceFromHand, string toNotation, bool isPromotion = false) { From = null; PieceFromHand = pieceFromHand; To = NotationHelper.FromBoardNotation(toNotation); IsPromotion = isPromotion; } public ServiceModels.Types.Move ToServiceModel() => new() { From = From.HasValue ? NotationHelper.ToBoardNotation(From.Value) : null, IsPromotion = IsPromotion, PieceFromCaptured = PieceFromHand.HasValue ? PieceFromHand : null, To = NotationHelper.ToBoardNotation(To) }; } }