IEnumerable <IntegerVector2> PredictMoveableColumns(IntegerVector2 hypotheticalPosition, IReadOnlyPiece movingPiece) { List <IntegerVector2> result = new List <IntegerVector2>(); if (movingPiece == null || !board.IsOnBoard(hypotheticalPosition)) { return(result); } for (int i = 0; i < board.Width; i++) { for (int j = 0; j < board.Height; j++) { IntegerVector2 currentPosition = new IntegerVector2(i, j); bool isFrontPlayer = movingPiece.Owner != null && movingPiece.Owner.Encampment == Encampment.Front; IntegerVector2 relativePosition = (currentPosition - hypotheticalPosition) * (isFrontPlayer ? -1 : 1); PieceMovement unused; if (board.IsOnBoard(currentPosition) && movingPiece.TryToGetPieceMovementByRelativePosition(relativePosition, out unused)) { result.Add(currentPosition); } } } return(result); }
public IEnumerable <PublicDataType.IntegerVector2> PredictMoveableColumns(PublicDataType.IntegerVector2 hypotheticalPosition, IReadOnlyPiece movingPiece) { if (movingPiece == null || !board.IsOnBoard(hypotheticalPosition)) { return(Enumerable.Empty <PublicDataType.IntegerVector2>()); } bool isFrontPlayer = movingPiece.Owner != null && movingPiece.Owner.Encampment == Terminologies.Encampment.Front; PieceMovement unused; IEnumerable <PublicDataType.IntegerVector2> allColumn = Enumerable.Range(0, board.Width * board.Height) .Select(x => new PublicDataType.IntegerVector2(x / board.Height, x % board.Height)); IEnumerable <PublicDataType.IntegerVector2> moveable = allColumn .Select(absolutePosition => (absolutePosition - hypotheticalPosition) * (isFrontPlayer ? -1 : 1)) .Where(relativePosition => movingPiece.TryToGetPieceMovementByRelativePosition(relativePosition, out unused)) .Select(relativePosition => relativePosition * (isFrontPlayer ? -1 : 1) + hypotheticalPosition); return(moveable); }