public float CalculateEntropy(Vector2Int position, OutputGrid outputGrid) { float sum = 0; foreach (var possibleIndex in outputGrid.GetPossibleValueForPossition(position)) { totalFrequency += patternManager.GetPatternFrequency(possibleIndex); sum += patternManager.GetPatternFrequencyLog2(possibleIndex); } totalFrequencyLog = Mathf.Log(totalFrequency, 2); return(totalFrequencyLog - (sum / totalFrequency)); }
public bool CheckCellSolutionForCollision(Vector2Int cellCoordinates, OutputGrid outputGrid) { foreach (var neighbour in Create4DirectionNeighbours(cellCoordinates)) { if (outputGrid.CheckIfValidPosition(neighbour.CellToPropagatePosition) == false) { continue; } HashSet <int> possibleIndices = new HashSet <int>(); foreach (var patternIndexAtNeighbour in outputGrid.GetPossibleValueForPossition(neighbour.CellToPropagatePosition)) { var possibleNeighboursForBase = patternManager.GetPossibleNeighboursForPatternInDirection(patternIndexAtNeighbour, neighbour.DirectionFromBase.GetOppositeDirectionTo()); possibleIndices.UnionWith(possibleNeighboursForBase); } if (possibleIndices.Contains(outputGrid.GetPossibleValueForPossition(cellCoordinates).First()) == false) { return(true); } } return(false); }