private void LightGenerate(Room room, int[,] collideGrid) { for (int y = 0; y < room.Height; y++) { for (int x = 0; x < room.Width; x++) { if (collideGrid[y, x] != 3) { continue; } int[,] neighbours = GridMath.GetNeighbours(collideGrid, new Vector2Int(x, y), 0); // if empty below if (neighbours[2, 1] == 0) { if (Roll.Chance(5)) { Vector3 worldLocation = new Vector3(x - Mathf.FloorToInt(room.Width / 2) + 0.5f, y - Mathf.FloorToInt(room.Height / 2) + 0.5f, 0f); GameObject torch = Instantiate(_torchPrefab, worldLocation, Quaternion.identity); torch.transform.parent = room.LightContainer; } } } } }
public void TurnDegrees(int pDegrees) { int degrees = (int)IntPoint.DirectionToIntPoint(direction).Degrees(); degrees -= pDegrees; direction = GridMath.DegreesToDirection((int)degrees); }
public void MoveUp() { if (GridMath.GetRowForIndex(selectedCell) > 0) { SetSelectedIndex(selectedCell - 9); } }
public void MoveLeft() { if (GridMath.GetColumnForIndex(selectedCell) > 0) { SetSelectedIndex(selectedCell - 1); } }
public bool ApplyRule(ref Board board) { bool ruleSucceeded = false; for (int squareNumber = 0; squareNumber < 9; squareNumber++) { CellData cellData = board.GetCellDataForSquare(squareNumber); foreach (int unsolvedValue in cellData.GetUnsolvedValues()) { List <int> cellIndicesWithUnsolvedValue = cellData.GetCellIndicesWithValue(unsolvedValue); if (InSameRow(cellIndicesWithUnsolvedValue)) { CellData allCellsInRow = board.GetCellDataForRow(GridMath.GetRowForIndex(cellIndicesWithUnsolvedValue.First())); bool removalSucceeded = RemoveUnsolvedValueFromCellsNotInSquare(ref board, unsolvedValue, squareNumber, allCellsInRow); ruleSucceeded |= removalSucceeded; } else if (InSameColumn(cellIndicesWithUnsolvedValue)) { CellData allCellsInColumn = board.GetCellDataForColumn(GridMath.GetColumnForIndex(cellIndicesWithUnsolvedValue.First())); bool removalSucceeded = RemoveUnsolvedValueFromCellsNotInSquare(ref board, unsolvedValue, squareNumber, allCellsInColumn); ruleSucceeded |= removalSucceeded; } } } return(ruleSucceeded); }
private void ExpandNodeChance(int expandThreshold = 33) { int[,] _newMapGrid = _mapGrid; for (int y = 0; y < mapSize; y++) { for (int x = 0; x < mapSize; x++) { if (_mapGrid[y, x] != 0) { continue; } int[,] neighbours = GridMath.GetNeighbours(_mapGrid, new Vector2Int(x, y)); if (!GridMath.NeighboursContainsX(neighbours, 1)) { continue; } if (Roll(33)) { _newMapGrid[y, x] = 1; } } } _mapGrid = _newMapGrid; }
public void DegreesToDirection() { Assert.AreEqual(Direction.UP, GridMath.DegreesToDirection(0)); Assert.AreEqual(Direction.RIGHT, GridMath.DegreesToDirection(90)); Assert.AreEqual(Direction.DOWN, GridMath.DegreesToDirection(180)); Assert.AreEqual(Direction.LEFT, GridMath.DegreesToDirection(270)); }
public void MoveDown() { if (GridMath.GetRowForIndex(selectedCell) < 8) { SetSelectedIndex(selectedCell + 9); } }
public void MoveRight() { if (GridMath.GetColumnForIndex(selectedCell) < 8) { SetSelectedIndex(selectedCell + 1); } }
public void ConvertFromFloatToIntRoundsDownWhenLessThanFive() { var expected = 0; var startingFloat = 0.4999f; int actual = GridMath.ConvertFromFloatToInt(startingFloat); Assert.Equal(expected, actual); }
private void TalkToSignetPerson(Person signetNpc) { int dist = GridMath.GetDistancePos(Traveler.Position, signetNpc.Position); if (dist < 3) { HasSignet = true; } }
public void ClampTurnsPositiveNumberToOne() { float number = 1; var want = 1f; float got = GridMath.Clamp(number, 0, 1); Assert.Equal(want, got); }
public void ClampTurnsNegativeNumberToZero() { float number = -1; var want = 0f; float got = GridMath.Clamp(number, 0, 1); Assert.Equal(want, got); }
public void ConvertFromFloatToIntRoundsDownWhenLessThanFiveNegative() { int expected = -0; float startingFloat = -0.4999f; int actual = GridMath.ConvertFromFloatToInt(startingFloat); Assert.Equal(expected, actual); }
public void ConvertFromFloatToIntCanRoundAndConvertNegativeCorrectly() { int expected = -1; float startingFloat = -0.51f; int actual = GridMath.ConvertFromFloatToInt(startingFloat); Assert.Equal(expected, actual); }
public void CalculateIndex() { int column = 4; int row = 4; int index = GridMath.CalculateIndexFromColumnRow(column, 3, 2); Assert.AreEqual(11, index); }
public void ConvertFromFloatToIntCanRoundAndConvertCorrectly() { var expected = 1; var startingFloat = 0.51f; int actual = GridMath.ConvertFromFloatToInt(startingFloat); Assert.Equal(expected, actual); }
void CreateCells(int columnCount, int rowCount) { allCells = new CellCollection(Enumerable.Range(0, columnCount * rowCount).Select(delegate(int index) { int column, row; GridMath.CalculateColumnRow(index, columnCount, out column, out row); return(new Cell.Cell(column, row)); })); }
public bool PathIsFound(Node currentGridNode, Node targetGridNode) { if (currentGridNode == targetGridNode) return true; if (GridMath.GetDistance(currentGridNode, targetGridNode) <= DistanceTolerance) return true; return false; }
public void TestIndicesInSquare(int square, int[] expectedIndices) { List <int> actualIndicesInSquare = GridMath.GetIndicesInSquare(square); actualIndicesInSquare.Should().NotBeEmpty() .And.HaveCount(GridMath.CellsInSquare); foreach (int expectedIndex in expectedIndices) { actualIndicesInSquare.Should().Contain(expectedIndex); } }
public void TestIndicesInColumn(int column, int[] expectedIndices) { List <int> actualIndicesInColumn = GridMath.GetIndicesInColumn(column); actualIndicesInColumn.Should().NotBeEmpty() .And.HaveCount(GridMath.CellsInColumn); foreach (int expectedIndex in expectedIndices) { actualIndicesInColumn.Should().Contain(expectedIndex); } }
public void TestIndicesInRow(int row, int[] expectedIndices) { List <int> actualIndicesInRow = GridMath.GetIndicesInRow(row); actualIndicesInRow.Should().NotBeEmpty() .And.HaveCount(GridMath.CellsInRow); foreach (int expectedIndex in expectedIndices) { actualIndicesInRow.Should().Contain(expectedIndex); } }
public void TestRelatedCellIndices(int index, int[] expectedRelatedIndices) { List <int> actualRelatedIndices = GridMath.GetRelatedCellIndices(index); actualRelatedIndices.Should().NotBeEmpty() .And.HaveCount(EXPECTED_NUMBER_OF_RELATED_INDICES); foreach (int expectedIndex in expectedRelatedIndices) { actualRelatedIndices.Should().Contain(expectedIndex); } }
private Tile SelectPadTile(Vector2Int loc, int[,] padGrid) { int[,] neighbours = GridMath.GetNeighbours(padGrid, loc); string gridType = GridMath.Comparison(neighbours, GridMath.PadComparisonGrids, 1); if (gridType != null) { return(_padTiles[gridType]); } return(_wallTiles["wall"]); }
private Tile SelectWallTile(Vector2Int loc, int[,] collideGrid) { int[,] neighbours = GridMath.GetNeighbours(collideGrid, loc); string gridType = GridMath.Comparison(neighbours, GridMath.WallComparisonGrids); if (gridType != null) { return(_wallTiles[gridType]); } return(_wallTiles["wall"]); }
public IGrid Create() { SquareGrid grid = new SquareGrid(gridConfig); int cellCount = gridConfig.RowCount * gridConfig.ColumnCount; for (int i = 0; i < cellCount; i++) { int row, column; GridMath.CalculateColumnRow(i, gridConfig.ColumnCount, out column, out row); grid.GetCell(column, row).Content = randomContentProvider.Get(); } return(grid); }
private void RemoveSurroundedNodes() { for (int y = 0; y < mapSize; y++) { for (int x = 0; x < mapSize; x++) { int[,] neighbours = GridMath.GetNeighbours(_mapGrid, new Vector2Int(x, y), 1); if (GridMath.CheckSurroundedFully(neighbours, 1)) { _mapGrid[y, x] = 0; } } } }
public void CheckAllPossibleValues() { var actual = GridMath.AllPossibleValues(); actual.Count.Should().Be(9); actual.Should().Contain(1); actual.Should().Contain(2); actual.Should().Contain(3); actual.Should().Contain(4); actual.Should().Contain(5); actual.Should().Contain(6); actual.Should().Contain(7); actual.Should().Contain(8); actual.Should().Contain(9); }
private void RemoveUnreachableNodes() { for (int y = 0; y < mapSize; y++) { for (int x = 0; x < mapSize; x++) { int[,] neighbours = GridMath.GetNeighbours(_mapGrid, new Vector2Int(x, y), 0); if (GridMath.CheckSurroundedCardinal(neighbours, 0)) { _mapGrid[y, x] = 0; } } } }
private bool RemoveUnsolvedValueFromCellsNotInSquare(ref Board board, int unsolvedValue, int squareNumber, CellData cells) { bool success = false; foreach (int cellIndex in cells.Keys) { if (GridMath.GetSquareForIndex(cellIndex) != squareNumber) { bool removalSucceeded = board.RemoveValueFromCell(cellIndex, unsolvedValue); success |= removalSucceeded; } } return(success); }