Skip to content

Commit af7f552

Browse files
committed
Console output view is improved further.
1 parent 590af77 commit af7f552

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

algorithm-1/C#/Solution-a1-3/solution-3.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
static void Test(string input, int expected)
1212
{
13-
Console.WriteLine("< Test >");
13+
Console.WriteLine("<Test>");
1414
Game game = new(input);
1515
GameState resolvedState = game.GetSolution();
16-
Console.WriteLine(resolvedState.ToString());
17-
Console.WriteLine(resolvedState.Status.ToString());
18-
Console.WriteLine($"resolved in {resolvedState.StepCount} steps");
19-
Console.WriteLine($"Test result {(resolvedState.StepCount == expected ? "passed" : "failed")}.");
20-
Console.WriteLine("</ Test >");
16+
Console.WriteLine(" last state:" + resolvedState.ToString());
17+
Console.WriteLine(" " + resolvedState.Status.ToString());
18+
Console.WriteLine($" resolved in {resolvedState.StepCount} steps");
19+
Console.WriteLine($" Test result {(resolvedState.StepCount == expected ? "passed" : "failed")}.");
20+
Console.WriteLine("</Test>");
2121

2222
}
2323

@@ -136,15 +136,33 @@ public override string ToString()
136136
{
137137
StringBuilder sb = new();
138138
sb.Append("[");
139-
bool reapet = false;
139+
bool isFirstRow = true;
140140
foreach (int[] row in Values)
141141
{
142-
if (reapet)
142+
if (isFirstRow)
143+
{
144+
sb.Append("[");
145+
}
146+
else
147+
{
143148
sb.Append(",");
144-
sb.Append("[");
149+
sb.Append("[");
150+
}
151+
isFirstRow = true;
152+
bool isFirstNum = true;
145153
foreach (int val in row)
146154
{
147-
sb.Append(val);
155+
156+
if (isFirstNum)
157+
{
158+
sb.Append(val);
159+
}
160+
else
161+
{
162+
sb.Append(",");
163+
sb.Append(val);
164+
}
165+
isFirstNum = false;
148166
}
149167
sb.Append("]");
150168
}
@@ -202,7 +220,6 @@ class Game
202220
/// <param name="initState"></param>
203221
public Game(string initState)
204222
{
205-
Console.WriteLine("New Game:" + initState);
206223
int[][] initialState;
207224
initState = initState.Replace("[[", "");
208225
initState = initState.Replace("]]", "");

0 commit comments

Comments
 (0)