mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 23:26:40 -08:00
Performance optimization, reducing the amount of writes to the console necessary to output each iteration's matrix.
This commit is contained in:
@@ -134,10 +134,12 @@ void ProcessSimulation()
|
||||
var nextMaxX = 0;
|
||||
var nextMaxY = 0;
|
||||
|
||||
var matrixOutput = new StringBuilder();
|
||||
|
||||
// prints the empty lines before search area
|
||||
for (var x = 0; x < minX; x++)
|
||||
{
|
||||
Console.WriteLine();
|
||||
matrixOutput.AppendLine();
|
||||
}
|
||||
|
||||
// refreshes the matrix and updates search area
|
||||
@@ -168,14 +170,15 @@ void ProcessSimulation()
|
||||
nextMaxY = Math.Max(y + 1, nextMaxY);
|
||||
}
|
||||
|
||||
Console.WriteLine(string.Join(separator: null, values: printedLine));
|
||||
matrixOutput.AppendLine(string.Join(separator: null, values: printedLine));
|
||||
}
|
||||
|
||||
// prints empty lines after search area
|
||||
for (var x = maxX + 1; x < maxHeight; x++)
|
||||
{
|
||||
Console.WriteLine();
|
||||
matrixOutput.AppendLine();
|
||||
}
|
||||
Console.WriteLine(matrixOutput);
|
||||
Console.WriteLine();
|
||||
|
||||
void UpdateSearchArea()
|
||||
|
||||
Reference in New Issue
Block a user