Fixed accidentally building the board from player2 perspective.
This commit is contained in:
40
Gameboard.ShogiUI.Sockets/Models/BoardState.cs
Normal file
40
Gameboard.ShogiUI.Sockets/Models/BoardState.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Gameboard.ShogiUI.Rules;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ServiceTypes = Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||
|
||||
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; }
|
||||
|
||||
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]);
|
||||
|
||||
Player1Hand = shogi.Hands[WhichPlayer.Player1].Select(_ => new Piece(_)).ToList();
|
||||
Player2Hand = shogi.Hands[WhichPlayer.Player2].Select(_ => new Piece(_)).ToList();
|
||||
}
|
||||
|
||||
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();
|
||||
return new ServiceTypes.BoardState
|
||||
{
|
||||
Board = board,
|
||||
Player1Hand = Player1Hand.Select(_ => _.ToServiceModel()).ToList(),
|
||||
Player2Hand = Player2Hand.Select(_ => _.ToServiceModel()).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
using Gameboard.ShogiUI.BoardState;
|
||||
using Gameboard.ShogiUI.Rules;
|
||||
using Microsoft.FSharp.Core;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using BoardStateMove = Gameboard.ShogiUI.Rules.Move;
|
||||
using ShogiApi = Gameboard.Shogi.Api.ServiceModels.Types;
|
||||
|
||||
namespace Gameboard.ShogiUI.Sockets.Models
|
||||
@@ -13,7 +14,6 @@ namespace Gameboard.ShogiUI.Sockets.Models
|
||||
public Coords To { get; set; }
|
||||
public bool IsPromotion { get; set; }
|
||||
|
||||
public Move() { }
|
||||
public Move(ServiceModels.Socket.Types.Move move)
|
||||
{
|
||||
From = Coords.FromBoardNotation(move.From);
|
||||
@@ -74,9 +74,9 @@ namespace Gameboard.ShogiUI.Sockets.Models
|
||||
};
|
||||
return target;
|
||||
}
|
||||
public BoardState.Move ToBoardModel()
|
||||
public BoardStateMove ToBoardModel()
|
||||
{
|
||||
return new BoardState.Move
|
||||
return new BoardStateMove
|
||||
{
|
||||
From = new Vector2(From.X, From.Y),
|
||||
IsPromotion = IsPromotion,
|
||||
|
||||
27
Gameboard.ShogiUI.Sockets/Models/Piece.cs
Normal file
27
Gameboard.ShogiUI.Sockets/Models/Piece.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
|
||||
using BoardStatePiece = Gameboard.ShogiUI.Rules.Pieces.Piece;
|
||||
|
||||
namespace Gameboard.ShogiUI.Sockets.Models
|
||||
{
|
||||
public class Piece
|
||||
{
|
||||
public WhichPiece WhichPiece { get; set; }
|
||||
|
||||
public bool IsPromoted { get; set; }
|
||||
|
||||
public Piece(BoardStatePiece piece)
|
||||
{
|
||||
WhichPiece = (WhichPiece)piece.WhichPiece;
|
||||
IsPromoted = piece.IsPromoted;
|
||||
}
|
||||
|
||||
public ServiceModels.Socket.Types.Piece ToServiceModel()
|
||||
{
|
||||
return new ServiceModels.Socket.Types.Piece
|
||||
{
|
||||
IsPromoted = IsPromoted,
|
||||
WhichPiece = WhichPiece
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Gameboard.ShogiUI.Sockets/Models/Player.cs
Normal file
12
Gameboard.ShogiUI.Sockets/Models/Player.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Gameboard.ShogiUI.Sockets.Models
|
||||
{
|
||||
public class Player
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public Player(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user