before deleting Rules
This commit is contained in:
@@ -1,88 +1,41 @@
|
||||
using Gameboard.ShogiUI.Rules;
|
||||
using Microsoft.FSharp.Core;
|
||||
using System;
|
||||
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||
using System.Numerics;
|
||||
using BoardStateMove = Gameboard.ShogiUI.Rules.Move;
|
||||
using ShogiApi = Gameboard.Shogi.Api.ServiceModels.Types;
|
||||
|
||||
namespace Gameboard.ShogiUI.Sockets.Models
|
||||
{
|
||||
public class Move
|
||||
{
|
||||
public string PieceFromCaptured { get; set; }
|
||||
public Coords From { get; set; }
|
||||
public Coords To { get; set; }
|
||||
public Coords? From { get; set; }
|
||||
public bool IsPromotion { get; set; }
|
||||
public WhichPiece? PieceFromHand { get; set; }
|
||||
public Coords To { get; set; }
|
||||
|
||||
public Move(ServiceModels.Socket.Types.Move move)
|
||||
public Move(Coords from, Coords to, bool isPromotion)
|
||||
{
|
||||
From = Coords.FromBoardNotation(move.From);
|
||||
To = Coords.FromBoardNotation(move.To);
|
||||
PieceFromCaptured = move.PieceFromCaptured;
|
||||
IsPromotion = move.IsPromotion;
|
||||
From = from;
|
||||
To = to;
|
||||
IsPromotion = isPromotion;
|
||||
}
|
||||
public Move(ShogiApi.Move move)
|
||||
|
||||
public Move(WhichPiece pieceFromHand, Coords to)
|
||||
{
|
||||
string pieceFromCaptured = null;
|
||||
if (move.PieceFromCaptured != null)
|
||||
{
|
||||
pieceFromCaptured = move.PieceFromCaptured.Value switch
|
||||
{
|
||||
ShogiApi.WhichPieceName.Bishop => "",
|
||||
ShogiApi.WhichPieceName.GoldenGeneral => "G",
|
||||
ShogiApi.WhichPieceName.King => "K",
|
||||
ShogiApi.WhichPieceName.Knight => "k",
|
||||
ShogiApi.WhichPieceName.Lance => "L",
|
||||
ShogiApi.WhichPieceName.Pawn => "P",
|
||||
ShogiApi.WhichPieceName.Rook => "R",
|
||||
ShogiApi.WhichPieceName.SilverGeneral => "S",
|
||||
_ => ""
|
||||
};
|
||||
}
|
||||
From = new Coords(move.Origin.X, move.Origin.Y);
|
||||
To = new Coords(move.Destination.X, move.Destination.Y);
|
||||
IsPromotion = move.IsPromotion;
|
||||
PieceFromCaptured = pieceFromCaptured;
|
||||
PieceFromHand = pieceFromHand;
|
||||
To = to;
|
||||
}
|
||||
|
||||
public ServiceModels.Socket.Types.Move ToServiceModel() => new()
|
||||
{
|
||||
From = From.ToBoardNotation(),
|
||||
From = From?.ToBoardNotation(),
|
||||
IsPromotion = IsPromotion,
|
||||
PieceFromCaptured = PieceFromCaptured,
|
||||
To = To.ToBoardNotation()
|
||||
To = To.ToBoardNotation(),
|
||||
PieceFromCaptured = PieceFromHand
|
||||
};
|
||||
public ShogiApi.Move ToApiModel()
|
||||
|
||||
public Rules.Move ToRulesModel()
|
||||
{
|
||||
var pieceFromCaptured = PieceFromCaptured switch
|
||||
{
|
||||
"B" => new FSharpOption<ShogiApi.WhichPieceName>(ShogiApi.WhichPieceName.Bishop),
|
||||
"G" => new FSharpOption<ShogiApi.WhichPieceName>(ShogiApi.WhichPieceName.GoldenGeneral),
|
||||
"K" => new FSharpOption<ShogiApi.WhichPieceName>(ShogiApi.WhichPieceName.King),
|
||||
"k" => new FSharpOption<ShogiApi.WhichPieceName>(ShogiApi.WhichPieceName.Knight),
|
||||
"L" => new FSharpOption<ShogiApi.WhichPieceName>(ShogiApi.WhichPieceName.Lance),
|
||||
"P" => new FSharpOption<ShogiApi.WhichPieceName>(ShogiApi.WhichPieceName.Pawn),
|
||||
"R" => new FSharpOption<ShogiApi.WhichPieceName>(ShogiApi.WhichPieceName.Rook),
|
||||
"S" => new FSharpOption<ShogiApi.WhichPieceName>(ShogiApi.WhichPieceName.SilverGeneral),
|
||||
_ => null
|
||||
};
|
||||
var target = new ShogiApi.Move
|
||||
{
|
||||
Origin = new ShogiApi.BoardLocation { X = From.X, Y = From.Y },
|
||||
Destination = new ShogiApi.BoardLocation { X = To.X, Y = To.Y },
|
||||
IsPromotion = IsPromotion,
|
||||
PieceFromCaptured = pieceFromCaptured
|
||||
};
|
||||
return target;
|
||||
}
|
||||
public BoardStateMove ToBoardModel()
|
||||
{
|
||||
return new BoardStateMove
|
||||
{
|
||||
From = new Vector2(From.X, From.Y),
|
||||
IsPromotion = IsPromotion,
|
||||
PieceFromCaptured = Enum.TryParse<WhichPiece>(PieceFromCaptured, out var whichPiece) ? whichPiece : null,
|
||||
To = new Vector2(To.X, To.Y)
|
||||
};
|
||||
return PieceFromHand != null
|
||||
? new Rules.Move((Rules.WhichPiece)PieceFromHand, new Vector2(To.X, To.Y))
|
||||
: new Rules.Move(new Vector2(From!.X, From.Y), new Vector2(To.X, To.Y), IsPromotion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user