Skip to content

Commit

Permalink
Added arrow key path navigation.
Browse files Browse the repository at this point in the history
  • Loading branch information
osalinasv committed Oct 20, 2017
1 parent 30fedba commit 2abb0f2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
33 changes: 27 additions & 6 deletions atomixcs/atomixcs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ static void Main(string[] args) {
/** General initializations **/
Console.OutputEncoding = System.Text.Encoding.UTF8;

string root = AppContext.BaseDirectory;
string data_dir = root + "data/";
string data_dir = AppContext.BaseDirectory + "data/";

/** Read and deserialize level XML data **/
List<XMLLevel> levels = read_level_data(data_dir + "data.xml");

if (levels == null || levels.Count <= 0) {
Console.WriteLine("No levels were found or there is a problem with data.xml");
Console.ReadLine();
return;
}

Expand Down Expand Up @@ -214,16 +214,37 @@ static void display_path(ref Grid grid, ref List<State> path) {

console_line_start = Console.CursorTop;

for (int i = 0; i < path.Count; i++) {
int i = 0;
ConsoleKey key_pressed;

Console.CursorVisible = false;

while (i >= 0 && i < path.Count) {
Console.CursorTop = console_line_start;

grid.draw_grid(path[i]);
Console.WriteLine(path[i]);
Console.WriteLine("{0}. {1} ", (i <= 0) ? "start" : i.ToString(), path[i]);
Console.WriteLine();

Console.WriteLine("Press enter to " + ((i >= path.Count - 1) ? "end".PadRight(Console.WindowWidth) : "continue..."));
Console.ReadLine();
Console.WriteLine("Press \u2190 or \u2192 arrows to navigate...");
if (i >= path.Count) {
break;
}

if (Console.KeyAvailable) {
key_pressed = Console.ReadKey(false).Key;

if (key_pressed == ConsoleKey.LeftArrow) {
i--;
} else if(key_pressed == ConsoleKey.RightArrow) {
i++;
}

i = Math.Min(Math.Max(0, i), path.Count);
}
}

Console.CursorVisible = true;
} else {
Console.WriteLine("No solution found");
}
Expand Down
16 changes: 15 additions & 1 deletion atomixcs/atomixcs/a_star/AStar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,21 @@ public static List<State> a_star(ref Grid grid, State start_state, State target_
}

watch.Stop();
Console.Write("\relapsed: {0} | iterations: {1} | heuristic: {2} | f-cost: {3} ", watch.ElapsedMilliseconds, iteration_count, current_state.heuristic, current_state.f_cost);

string time_tag = "ms";
float time = watch.ElapsedMilliseconds;

if (time >= 1000) {
time /= 1000;
time_tag = "s";

if (time >= 60) {
time /= 60;
time_tag = "m";
}
}

Console.Write("\relapsed: {0} {1} | iterations: {2} | heuristic: {3} | f-cost: {4} ", watch.ElapsedMilliseconds, time_tag, iteration_count, current_state.heuristic, current_state.f_cost);
watch.Start();
}

Expand Down

0 comments on commit 2abb0f2

Please sign in to comment.