/// <summary> /// RowDelta /// The change in Row (plus or minus) from one letter to the next /// given the direction of the word in the grid /// </summary> /// <param name="direction"></param> /// <returns></returns> public static int RowDelta(this DirectionFlagsEnum direction) { if ((direction & DirectionFlagsEnum.Up) != 0) { return(-1); } else if ((direction & DirectionFlagsEnum.Down) != 0) { return(1); } return(0); }
/// <summary> /// ColumnDelta /// The change in Column (plus or minus) from one letter to the next /// given the direction of the word in the grid /// </summary> /// <param name="direction"></param> /// <returns></returns> public static int ColumnDelta(this DirectionFlagsEnum direction) { if ((direction & DirectionFlagsEnum.Left) != 0) { return(-1); } else if ((direction & DirectionFlagsEnum.Right) != 0) { return(1); } return(0); }
public void IsPlacementValid_WordCrossesAnotherWord_Various(char[,] grid, int row, int column, string word, DirectionFlagsEnum direction, bool expectedResult) { var hiddenWord = new HiddenWord() { Start = new GridLocation(row, column), Word = word, Direction = direction }; var result = PlacementValidator.IsWordPlacementValid(grid, hiddenWord); Assert.Equal(result, expectedResult); }
[InlineData(20, 1, "abcdefghijklmnopqrst", DirectionFlagsEnum.UpRight, true)] // Max size word fits in DownRight public void IsPlacementValid_MaxWordSize_Various(int row, int column, string word, DirectionFlagsEnum direction, bool expectedResult) { var grid = new char[20, 20]; var hiddenWord = new HiddenWord() { Start = new GridLocation(row, column), Word = word, Direction = direction }; var result = PlacementValidator.IsWordPlacementValid(grid, hiddenWord); Assert.Equal(result, expectedResult); }
/// <summary> /// GetNextLetterGridLocation /// Return GridLocation where next character will be placed /// </summary> /// <param name="gridLocation"></param> /// <param name="direction"></param> /// <returns></returns> public static GridLocation GetNextLetterGridLocation(GridLocation gridLocation, DirectionFlagsEnum direction) { var newRow = gridLocation.Row + direction.RowDelta(); var newColumn = gridLocation.Column + direction.ColumnDelta(); return(new GridLocation(newRow, newColumn)); }