before deleting Rules
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Gameboard.ShogiUI.Rules;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using ServiceTypes = Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||
|
||||
@@ -7,28 +8,53 @@ namespace Gameboard.ShogiUI.Sockets.Models
|
||||
{
|
||||
public class BoardState
|
||||
{
|
||||
public Piece[,] Board { get; set; }
|
||||
public IReadOnlyCollection<Piece> Player1Hand { get; set; }
|
||||
public IReadOnlyCollection<Piece> Player2Hand { get; set; }
|
||||
// TODO: Create a custom 2D array implementation which removes the (x,y) or (y,x) ambiguity.
|
||||
public Piece?[,] Board { get; }
|
||||
public IReadOnlyCollection<Piece> Player1Hand { get; }
|
||||
public IReadOnlyCollection<Piece> Player2Hand { get; }
|
||||
/// <summary>
|
||||
/// Move is null in the first BoardState of a Session, before any moves have been made.
|
||||
/// </summary>
|
||||
public Move? Move { get; }
|
||||
|
||||
public BoardState() : this(new ShogiBoard()) { }
|
||||
|
||||
public BoardState(Piece?[,] board, IList<Piece> player1Hand, ICollection<Piece> player2Hand, Move move)
|
||||
{
|
||||
Board = board;
|
||||
Player1Hand = new ReadOnlyCollection<Piece>(player1Hand);
|
||||
}
|
||||
|
||||
public BoardState(ShogiBoard shogi)
|
||||
{
|
||||
Board = new Piece[9, 9];
|
||||
for (var x = 0; x < 9; x++)
|
||||
for (var y = 0; y < 9; y++)
|
||||
Board[x, y] = new Piece(shogi.Board[x, y]);
|
||||
{
|
||||
var piece = shogi.Board[x, y];
|
||||
if (piece != null)
|
||||
{
|
||||
Board[x, y] = new Piece(piece);
|
||||
}
|
||||
}
|
||||
|
||||
Player1Hand = shogi.Hands[WhichPlayer.Player1].Select(_ => new Piece(_)).ToList();
|
||||
Player2Hand = shogi.Hands[WhichPlayer.Player2].Select(_ => new Piece(_)).ToList();
|
||||
Move = new Move(shogi.MoveHistory[^1]);
|
||||
}
|
||||
|
||||
public ServiceTypes.BoardState ToServiceModel()
|
||||
{
|
||||
var board = new ServiceTypes.Piece[9, 9];
|
||||
Board = new Piece[9, 9];
|
||||
for (var x = 0; x < 9; x++)
|
||||
for (var y = 0; y < 9; y++)
|
||||
board[x, y] = Board[x, y].ToServiceModel();
|
||||
{
|
||||
var piece = Board[x, y];
|
||||
if (piece != null)
|
||||
{
|
||||
board[x, y] = piece.ToServiceModel();
|
||||
}
|
||||
}
|
||||
return new ServiceTypes.BoardState
|
||||
{
|
||||
Board = board,
|
||||
|
||||
Reference in New Issue
Block a user