This training program allows you to simulate the movement of a chess piece «Horse» on a field of size 8x8. An additional condition is that the «Horse» must visit each cell only once. Attention! The program was tested only in the environment Borland 3.1!
File name | The contents of the file |
---|---|
HORSEPRT.H | Connecting standard libraries, declaring variables, classes, methods, and functions |
HORSE.CPP | The main project file, contains the function main() |
HORSECTR.CPP | Description of the program management functions |
HORSERND.CPP | Description of methods and functions for finding the best crawl path |
HORSEOUT.CPP | Dialog functions, user interface |
HORSEVIZ.CPP | Visualization of the chess field |
HORSEGPR.CPP | Description of methods and functions for finding the best traversal path with visualization of the chessboard |
Help.txt | File with hints |
To compile and run, it is best to use a simple one, like an Ilyich Light Bulb, and reliable as a Kalashnikov Assault Rifle, Borland 3.1 The choice of this development environment was determined by the principle of «necessary and sufficient». The result of the compilation will be a console application.
After running the compiled exe file, a splash screen will appear in a new window, as shown in the figure below(Pic. 1.):
After the launch, the main menu of the program will be available.
As you can see in the figure above (Pic. 2.), the main menu contains 7 items,which are selected using the function keys(F1-F6, F10). Let’s look at these points in more detail:
When you press the F1 key in the main menu, the program displays the contents of the file: Help.txt
When you press the F2 key, a chessboard with the size of 8x8 cells will appear in the program window(pic. 4.)
The user can independently, by clicking the mouse, select the cells on which the figure “horse”should move. It can also switch to automatic mode by clicking on the field labeled «Руч» in the upper-right corner. After that, the label in this field will change to «АВТ» and after selecting the next cell, the program will start moving around the field on its own(pic.5.).
When press «F3», the user will be prompted to enter the coordinates of the initial position of the chess piece “knight” After that, an automatic crawl of the entire field will start from the specified position. At the same time, the user will be able to track not only the current position, possible paths of movement or the completed trajectory, but also the methods and functions called in the program(pic. 6.).
In the event of deadlocks (when not all the cells have been visited yet, but there is nowhere to step from the current position), the program returns to the previous fork, where the program changes the path of the bypass (pic. 7.).
When you press the «F4» key, the program independently sets the initial position of the “Horse” figure, bypasses the entire chessboard, moves one square and starts the crawl again. And so on until it reaches the last cell.
By pressing the «F5» key, the program will display the trajectory of the last round of the chess field in the form of a sequence of coordinates(pic. 8.):
By pressing the «F6» key, the program will create an array and initialize it with the coordinates of the last crawl path(pic. 9.):
After that, it will ask the user to enter a file name to write the trajectory to the file(pic. 10.):
The result of writing the trajectory to a file(pic. 11):
##5.7. Shutting down the program
By pressing the «F10» key, the program is normally terminated.
Thank you for being able to read this to the end! :)