Starting from:

$30

Lab06. Unfriendly Knights

EE231002 Introduction to Programming
Lab06. Unfriendly Knights

0Z0Z0Z0Z
Z0Z0Z0Z0
0ZpZpZ0Z
ZpZ0ZpZ0
0Z0M0Z0Z
ZpZ0ZpZ0
0ZpZpZ0Z
Z0Z0Z0Z0
A knight in a chess game can have potentially 8 different moves. If any of the enemy’s piece
is located in the 8 locations, then the knight can capture any one of them. In the figure above,
the white knight can capture any of those 8 pawns in a single move.
In this assignment, you will write a C program to place as many knights as possible on a
N × N chess board and none of knights can be captured by other knights on the board. The
example output of program execution is shown below, where the first line prints the number of
knights placed, followed by the layout of the chess board. The symbol 'o' means a knight is
placed in that location, while '.' means an empty square. (Note that this may not be the best
solution.)
$ ./a.out
Solution with 8 knights on a 6x6 board:
o . . . . o
. . . . . .
. . o o . .
. . o o . .
. . . . . .
o . . . . o
1
Notes.
1. Create a directory lab06 and use it as the working directory.
2. Name your program source file as lab06.c.
3. The first few lines of your program should be comments as the following.
/* EE231002 Lab06. Unfriendly Knights
ID, Name
Date:
*/
4. You should define a macro for the number of rows and columns of the board as following:
#define N 6
5. After finishing editing your source file, you can execute the following command to compile
it,
$ gcc lab06.c
If no compilation errors, the executable file, a.out, should be generated, and you can
execute it by typing
$ ./a.out
6. After you finish verifying your program, you can submit your source code by
$ ∼ee2310/bin/submit lab06 lab06.c
If you see a ”submitted successfully” message, then you are done. In case you want to
check which file and at what time you submitted your labs, you can type in the following
command:
$ ∼ee2310/bin/subrec lab06
It will show all your submission records for lab06.
2

More products