public static Direction GetNextDirection(this int[,] matrix, Direction direction, int row, int col) { for (int i = 0; i < NUMBERS_DIRECTIONS; i++) { Direction currentDirection = (Direction)(((int)direction + i) % NUMBERS_DIRECTIONS); int currentRow = row + GetRowChange(currentDirection); int currentCol = col + GetColChange(currentDirection); if (matrix.CanContinueInDirection(currentRow, currentCol)) { return currentDirection; } } throw new InvalidOperationException("The matrix is filled."); }
public static Direction FindNewPosition(this int[,] matrix, Direction direction, Position position) { for (int i = 0; i < DirectionCount; i++) { Direction currDirection = (Direction)(((int)direction + i) % DirectionCount); int currRow = position.Row + ChangeByRow[(int)currDirection]; int currCol = position.Col + ChangeByColumn[(int)currDirection]; Position newPosition = new Position(currRow, currCol); if (CanGoToPosition(matrix, newPosition)) { return currDirection; } } throw new InvalidOperationException("Matrix is already filled."); }
public static int GetRowChange(Direction direction) { return VerticalDirection[(int)direction]; }
public static int GetColChange(Direction direction) { return HorizontalDirection[(int)direction]; }
public static int GetRowChange(Direction direction) { return RowChange[(int)direction]; }
public static int GetColChange(Direction direction) { return ColChange[(int)direction]; }