CSE 271: Programming Assignment 8

Assigned: 3 April
Due: 9 April

Abstract

Practice C and UNIX programming using simple system calls, and build infrastructure and understanding for a follow-on project.

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 6 and lab 8) 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):

Your program should show the board after each placement, and prevent hte user from placing a ship in an impossible place (e.g., diagonal, or hanging off the edge, or on top of an existing ship).

During the game, 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. Ships may be presented in any order, and the points for a ship might not be in sequence. The whitespace between points of a ship is optional (either a single space or no spaces). You may assume that the number of points and their resulting configuration form a valid set of coordinates. If a configuration file you are reading was written incorrectly, your program should recognize that 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.131/p8 subdirectory and have a Makefile. Name your executable p8.
  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: 2 April 2013.