Skip to content

Instantly share code, notes, and snippets.

@ApprenticeGC
Created March 21, 2020 08:41
Show Gist options
  • Save ApprenticeGC/03259d1e0e30ea525cfba90d7217f38f to your computer and use it in GitHub Desktop.
Save ApprenticeGC/03259d1e0e30ea525cfba90d7217f38f to your computer and use it in GitHub Desktop.
Show rule validation from Debug
void Start()
{
int GetAliveCountOfNeighbors(int[] neighbors) => neighbors.Aggregate(0, (acc, next) => acc + next);
{
// 0 0 0
// 0 1 0
// 0 0 0
var statusOfCurrentCell = 1;
var statusOfCurrentNeighbors = new[] {0, 0, 0, 0, 0, 0, 0, 0};
var statusOfNextGeneration = GetNextGenerationStatus(statusOfCurrentCell, statusOfCurrentNeighbors);
var neighborAliveCount = GetAliveCountOfNeighbors(statusOfCurrentNeighbors);
Debug.Log($"current cell: {statusOfCurrentCell} alive neighbors: {neighborAliveCount} -> next generation status: {statusOfNextGeneration}");
}
{
// 0 0 0
// 0 1 0
// 0 0 1
var statusOfCurrentCell = 1;
var statusOfCurrentNeighbors = new[] {0, 0, 1, 0, 0, 0, 0, 0};
var statusOfNextGeneration = GetNextGenerationStatus(statusOfCurrentCell, statusOfCurrentNeighbors);
var neighborAliveCount = GetAliveCountOfNeighbors(statusOfCurrentNeighbors);
Debug.Log($"current cell: {statusOfCurrentCell} alive neighbors: {neighborAliveCount} -> next generation status: {statusOfNextGeneration}");
}
{
// 0 1 0
// 0 1 0
// 0 0 1
var statusOfCurrentCell = 1;
var statusOfCurrentNeighbors = new[] {0, 0, 1, 0, 0, 0, 1, 0};
var statusOfNextGeneration = GetNextGenerationStatus(statusOfCurrentCell, new[] {0, 0, 1, 0, 0, 0, 1, 0});
var neighborAliveCount = GetAliveCountOfNeighbors(statusOfCurrentNeighbors);
Debug.Log($"current cell: {statusOfCurrentCell} alive neighbors: {neighborAliveCount} -> next generation status: {statusOfNextGeneration}");
}
{
// 0 1 0
// 1 1 0
// 0 0 1
var statusOfCurrentCell = 1;
var statusOfCurrentNeighbors = new[] {0, 0, 1, 1, 0, 0, 1, 0};
var statusOfNextGeneration = GetNextGenerationStatus(statusOfCurrentCell, new[] {0, 0, 1, 1, 0, 0, 1, 0});
var neighborAliveCount = GetAliveCountOfNeighbors(statusOfCurrentNeighbors);
Debug.Log($"current cell: {statusOfCurrentCell} alive neighbors: {neighborAliveCount} -> next generation status: {statusOfNextGeneration}");
}
{
// 0 1 1
// 1 1 0
// 0 0 1
var statusOfCurrentCell = 1;
var statusOfCurrentNeighbors = new[] {0, 0, 1, 1, 0, 0, 1, 1};
var statusOfNextGeneration = GetNextGenerationStatus(statusOfCurrentCell, new[] {0, 0, 1, 1, 0, 0, 1, 1});
var neighborAliveCount = GetAliveCountOfNeighbors(statusOfCurrentNeighbors);
Debug.Log($"current cell: {statusOfCurrentCell} alive neighbors: {neighborAliveCount} -> next generation status: {statusOfNextGeneration}");
}
{
// 0 1 1
// 1 0 0
// 0 0 1
var statusOfCurrentCell = 0;
var statusOfCurrentNeighbors = new[] {0, 0, 1, 1, 0, 0, 1, 1};
var statusOfNextGeneration = GetNextGenerationStatus(statusOfCurrentCell, new[] {0, 0, 1, 1, 0, 0, 1, 1});
var neighborAliveCount = GetAliveCountOfNeighbors(statusOfCurrentNeighbors);
Debug.Log($"current cell: {statusOfCurrentCell} alive neighbors: {neighborAliveCount} -> next generation status: {statusOfNextGeneration}");
}
{
// 0 0 1
// 1 0 0
// 0 0 1
var statusOfCurrentCell = 0;
var statusOfCurrentNeighbors = new[] {0, 0, 1, 1, 0, 0, 0, 1};
var statusOfNextGeneration = GetNextGenerationStatus(statusOfCurrentCell, new[] {0, 0, 1, 1, 0, 0, 0, 1});
var neighborAliveCount = GetAliveCountOfNeighbors(statusOfCurrentNeighbors);
Debug.Log($"current cell: {statusOfCurrentCell} alive neighbors: {neighborAliveCount} -> next generation status: {statusOfNextGeneration}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment