using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing; using System.Drawing; namespace Shogi.Domain.Other; public class Rules where TPiece : Enum { private Vector2 boardSize; private TPiece theKing; private Dictionary> piecePaths; /// /// Begin a new set of rules. If any rules already exist, this method will erase them. /// /// The size of the game board in tiles. For examples, Chess is 8x8 and Shogi is 9x9. /// The piece that represents the King for each player or the piece that, when lost, results in losing the game. public Rules CreateNewRules(Vector2 boardSize, TPiece king) { this.boardSize = boardSize; theKing = king; piecePaths = []; return this; } public Rules RegisterPieceWithRules(PieceRulesRegistration pieceToRegister) { if (piecePaths.ContainsKey(pieceToRegister.WhichPiece)) { throw new ArgumentException("This type of piece has already been registered.", nameof(pieceToRegister)); } piecePaths.Add(pieceToRegister.WhichPiece, pieceToRegister.MoveSet); return this; } public int ValidateMove(Vector2 start, Vector2 end, TPiece[][] board) { if (board.GetLength(0) != boardSize.X || board.GetLength(1) != boardSize.Y) { throw new ArgumentException($"2D array dimensions must match boardSize given during {nameof(CreateNewRules)} method.", nameof(board)); } if (start - start != Vector2.Zero) { throw new ArgumentException("Negative values not allowed.", nameof(start)); } if (end - end != Vector2.Zero) { throw new ArgumentException("Negative values not allowed.", nameof(end)); } if (start.X >= boardSize.X || start.Y >= boardSize.Y) { throw new ArgumentException("Start position must be within the given boardSize.", nameof(start)); } if (end.X >= boardSize.X || end.Y >= boardSize.Y) { throw new ArgumentException("End position must be within the given boardSize.", nameof(end)); } } }