CSE 271: Programming Assignment 6

Assigned: 4 April 2007
Due: 11 April 2007

Grading

Grading will likely match this grading sheet.

Abstract

Practice C and UNIX programming using simple system calls, and build infrastructure and understanding for later projects.

Details

Battleship is a popular two-player game for kids, and has a history going back to the 1930s.

Typically, each player places five "ships" of known size and distribution on a 10x10 grid. Those ships occupy grid positions that can be blindly bombed by your opponent. The goal is to sink all of your opponent's ships to win the game.

You can play a modern version written in flash, or a more complex javascript version online.

Your goal is to re-implement a simple version of Battleship as a UNIX game. Your program (perhaps utilizing the screen writing code from lab 4) should allow a single player game against a 'dumb' computer opponent. You need to ask the human player where to place five ships of varying length (one ship of each type):

During the program, your program should ask the user for coordinates to attack Y,X where Y is a letter from A-J and X is a number from 1 to 10. After each round of attacks (one user, one computer), the system should provide a status update (e.g., you just sank the frigate! or hit! or miss! and "the computer won" or "you won") and generate a new version of the player's screen showing all hits and misses on the grid.

Your program should also read in a configuration file for the automated player. This file will specify every move that the computer player makes -- the original positioning of its ships as well as every bombing coordinate that will be attempted (a long list!). Thus, for this assignment, the computer player is not intelligent or even adaptive -- it just follows the list as specified in the configuration file, which would be of the form:

#a comment!
A (A,1) (B,1) (C,1) (D,1) (E,1)
B (B,2) (C,2) (D,2) (E,2) 
F (C,3) (D,3) (E,3)
S (D,4) (E,4) (F,4)
M (E,5) (F,5)
#comments could be anywhere, but always start with a # symbol
(J,10)
(J,9)
(J,8)
(J,7)
(J,6)
(J,5)
(J,4)
(J,3)
(J,2)
(J,1)
(I,10)
(I,9)
...

Note that in all cases, coordinates here are Y (row) by X (column) from A-J and 1-10, respectively. If a configuration file is written incorrectly, your program should recognize that (if possible) and generate an appropriate error message.

Please contact me with any questions (the earlier the better!).

Submission Requirements

  1. As usual, the program must reside in the cse271.071/p6 subdirectory and have a Makefile. Name your executable p6.
  2. Your name must be in the comment section (along with appropriate description, etc.).
  3. Do a touch DONE when the program is ready to be collected.

Last revised: 3 April 2007.