checkpoint
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
namespace Gameboard.ShogiUI.Sockets.Models
|
||||
using Gameboard.ShogiUI.BoardState;
|
||||
using Microsoft.FSharp.Core;
|
||||
using System;
|
||||
using ShogiApi = Gameboard.Shogi.Api.ServiceModels.Types;
|
||||
|
||||
namespace Gameboard.ShogiUI.Sockets.Models
|
||||
{
|
||||
public class Move
|
||||
{
|
||||
@@ -15,7 +20,29 @@
|
||||
PieceFromCaptured = move.PieceFromCaptured;
|
||||
IsPromotion = move.IsPromotion;
|
||||
}
|
||||
|
||||
public Move(ShogiApi.Move move)
|
||||
{
|
||||
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;
|
||||
}
|
||||
public ServiceModels.Socket.Types.Move ToServiceModel() => new ServiceModels.Socket.Types.Move
|
||||
{
|
||||
From = From.ToBoardNotation(),
|
||||
@@ -23,5 +50,38 @@
|
||||
PieceFromCaptured = PieceFromCaptured,
|
||||
To = To.ToBoardNotation()
|
||||
};
|
||||
public ShogiApi.Move ToApiModel()
|
||||
{
|
||||
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 BoardState.Move ToBoardModel()
|
||||
{
|
||||
return new BoardState.Move
|
||||
{
|
||||
From = new BoardVector(From.X, From.Y),
|
||||
IsPromotion = IsPromotion,
|
||||
PieceFromCaptured = Enum.TryParse<WhichPiece>(PieceFromCaptured, out var whichPiece) ? whichPiece : null,
|
||||
To = new BoardVector(To.X, To.Y)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user