private GameModel MapToConfirmModel( Common.Game game, Common.SquareReference selectedSquareReference, Common.SquareReference endPosition) { //Common.SquareReference[] availableMoves = game.GetAvailableMoves(); return(new GameModel { CurrentPlayer = game.CurrentTurn, Opponent = game.CurrentTurn == Common.Color.Black ? Common.Color.White : Common.Color.Black, Board = new Models.Game.Board { Squares = game.Board.Squares .Select((row, rowIndex) => row.Select((square, columnIndex) => { // highlight any space or opponent piece // TODO add proper available move calculation!! bool canSelect = square.Piece.Color != game.CurrentTurn; string squareRef = square.Reference.ToString(); return new BoardSquare { PieceImage = ImageNameFromPiece(square.Piece), PieceName = square.Piece.Color + " " + square.Piece.PieceType, SquareColour = SquareColors[(rowIndex + columnIndex) % 2], CanSelect = false, Reference = square.Reference, ReferenceString = squareRef }; }) .ToArray() ).ToArray(), SelectedSquare = selectedSquareReference }, MoveHistory = MapToHistoricalMoves(game.Moves) }); }
private GameModel MapToChooseEndPositionModel(Common.Game game, Common.SquareReference selectedSquareReference) { Common.SquareReference[] availableMoves = game.GetAvailableMoves(selectedSquareReference).ToArray(); return(new GameModel { CurrentPlayer = game.CurrentTurn, Opponent = game.CurrentTurn == Common.Color.Black ? Common.Color.White : Common.Color.Black, InCheck = game.CurrentPlayerInCheck, Board = new Models.Game.Board { Squares = game.Board.Squares .Select((row, rowIndex) => row.Select((square, columnIndex) => { bool canSelect = availableMoves.Contains(square.Reference); string squareRef = square.Reference.ToString(); string selectUrl = canSelect ? Url.Action(nameof(Confirm), new { pieceSquareRef = selectedSquareReference.ToString(), endPosition = squareRef }) : null; return new BoardSquare { PieceImage = ImageNameFromPiece(square.Piece), PieceName = square.Piece.Color + " " + square.Piece.PieceType, SquareColour = SquareColors[(rowIndex + columnIndex) % 2], CanSelect = canSelect, Reference = square.Reference, SelectUrl = selectUrl, ReferenceString = squareRef }; }) .ToArray() ).ToArray(), SelectedSquare = selectedSquareReference }, MoveHistory = MapToHistoricalMoves(game.Moves) }); }