CS157: Intro to C, Part II

Spring 2018

HW 3

CS157 HW3: Bishops                

Description                

In the game of chess, the bishop can attack other pieces diagonally.                 

For this assignment, you will write a program called bishops.c. It will read a description of a chessboard (not necessarily eight-by-eight) that contains a number of bishops. The program will tell you which bishops are attacking other bishops.                 

Data File                

Here’s an example of a data file:                 

3x4

. . C .
. . . .
A . . B

The first line is an integer indicating the height of the board, an “x”, and an integer indicating the width of the board. After that follows:

Output                

After reading the data file, the program should indicate which bishops are attacking each other, like this: “A attacks B”.                 

To avoid redundancy, don’t display both “B attacks G” and “G attacks B”. Only display “B attacks G”, since 'B'<'G'.                 

The output lines may be in any order. We will sort your output before looking at it.                 

Sample Runs                

Here are several sample runs, where “% ” is my prompt:                 

% c11 -Wall bishops.c 
% cat bishop-data1
3x4

. . C .
. . . .
A . . B
% ./a.out bishop-data1
A attacks C
% cat bishop-data1-ugly 
3x4
.
.
                C..
    . .  .   A..

  B
% ./a.out bishop-data1-ugly
A attacks C
% cat bishop-data2
8x8

. . . . . . . .
. . . . . . . .
. B . C . . . .
. . . . D . . .
. . . . . E . .
. . . A . . . G
. . . . . . F .
. . . . . . . .
% ./a.out bishop-data2
C attacks D
C attacks E
D attacks E
F attacks G
% cat bishop-data3
3x3

Z G .
. . H
. D Q
% ./a.out bishop-data3
G attacks H
D attacks H
Q attacks Z

Debugging                

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements                

How to submit your homework:                

Use web checkin, or:                 

    ~cs157/bin/checkin HW3 bishops.c

How to receive negative points:                

Turn in someone else’s work.                 

User: Guest                 

Check: HTML CSS
Edit History Source

Modified: 2018-04-23T12:55                 

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building