Example – game map

The last example shown in this chapter involves the application of Dijkstra's algorithm for finding the shortest path in a game map. Let's imagine that you have a board with various obstacles. For this reason, the player can use only part of the board to move. Your task is to find the shortest path between two places located on the board.

To start, let's represent the board as a two-dimensional array where a given position on the board can be available for movement or not. The suitable part of code should be added to the Main method in the Program class, as follows:

string[] lines = new string[] { "0011100000111110000011111", "0011100000111110000011111", "0011100000111110000011111", "0000000000011100000011111", "0000001110000000000011111", ...

Get C# Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.