Exercise - Create the application
In this exercise, you get started with the project. you'll create the Langton's Ant console application and start working on the Program.cs file code. In the Program.cs file, you create a two-dimensional byte array that is the grid (also referred to as the playing field) and then check your progress.
Create a new console application
Let's begin by creating a new VS Code console application project.
Create a directory for your project.
- Open File Explorer.
- Create a project directory on your Desktop by right-clicking your Desktop folder and selecting 'Show more options'.
- Select New --> Folder
- Name your folder
Langtons Ant Projectand press Enter.
Create a console app in VS Code.
- Right-click the LangtonsAnt folder and select 'Show more options'.
- Right-click the LangtonsAnt folder and select 'Open with Code'.
- Select View --> Terminal to open a console window.
- Verify that you're using the .NET 6.0 or above by entering
dotnet --versionand pressing Enter. - Create your project by entering the type of application you want to create, its directory, and name for your application:
dotnet new console -o LangtonsAntand press Enter. - Enter
cd LangtonsAntto change your current directory to your newly created application folder. - Run your starter 'Hello World' application to make sure you created your console application correctly.
- Run your application, in the terminal window enter
dotnet runand press Enter.
Note
You need to be sure you are in the LangtonsAnt directory when you try and build or run your project. This directory is where your project file (LangtonsAnt.proj) is located, which is needed to run your application.
You should see the words 'Hello, world!' in the console window. You can close the default Welcome file that is created for you by VS Code.
Now that you have created a basic console application that runs in the little window called a console, you're ready to add files to it. Let's begin, however, by modifying the Program.cs file that VS Code created for you.
Create a two-dimensional integer array
You'll create a two dimensional (16x16) byte array that represents the grid for the ants. You then display it by creating a nested looping structure that prints characters to the screen showing the cell locations. The outer loop is creating the horizontal cells (x-axis), while the inner loop is stacking each row as it builds out the vertical axis.
Open your Program.cs file and delete the starter code in the file.
Next, add the following two dimensional byte array for the grid:
int[,] field = new int[16, 16];
Create the loops
Now you'll need to be able to loop through each position in your two-dimensional array to create the grid or field.
First, create the outer
forloop.for(int i = 0; i < field.GetLength(0); i++) { // You will put stuff here }Then create the inner
forloop.for(int i = 0; i < field.GetLength(0); i++) { for(int j = 0; j < field.GetLength(1); j++){ // You will put stuff here } }Now add grid characters and spacing using Console.Write and Console.WriteLine statements to the inner body of the loop so you can see the grid you created.
for(int i = 0; i < field.GetLength(0); i++) { for(int j = 0; j < field.GetLength(1); j++){ Console.Write($"{field[i, j]} "); } Console.WriteLine(); }Save your work by entering Ctrl-S and press enter.
Check your work
Build the project and launch the application.
Build your project by entering 'dotnet build' in your terminal window and pressing Enter.
Run the project by entering
dotnet runand pressing Enter.

You should see a representation of the grid printed to the screen using 0s and spaces, as shown. Make sure it outputs the array you created with each “row” printed on a separate line.