Assignment #1
Battleships, Version 1 Without Graphics
Due: We. Sept. 15th
Score: 10 points + 2 bonus points
- in time: 100%
- one week delay: 65%
- two weeks delay: 40%
- else: 20%
Write a version of the well known paper/pencil game 'Battleships'. Since you all know the rules of the game
i'll just define some necessary specifications.
The game should be played on a board 20x20 fields, each player may place 5 ships with a fixed size of 3 fields
horizontally or vertically on the field. Overlaps are not allowed, of course, since we don't use submarines.
A players move consists of firing a torpedo to a certain field of the opponent, the fields are given
by coordinates, e.g. 'A,3'. The opponents answer can be: 'water', 'hit' or 'close'. 'Close' seems not to be a
common rule, it means: 'you hit water, but either north, south, east or west there's a ship that is not discovered
yet'. This rule is the only rule that makes the game halfway exciting, that's why we use it.
As discussed in class, here are some helps/constraints how to program the game:
- you may use C, C++ or JAVA. You are free to decide if you want to program the game object oriented.
- the game will possibly be extended, e.g. i'll ask for a 2D graphic version. Prepare your data structures
and program design in a way that takes that into account.
- the field is an array, 20x20, containing indices to the ship the field possibly contains, 0 else.
- a ship should be defined by a structure containing at least size, position, number of hits, sunk/swimming flag
The Output
The most sophisticated part of this game is the output. Though it only consists of characters, showing the state of
each field, the character (in a later version: the graphic-tile) must be determined. The following characters/states
must be used:
- unexplored water: '.' (on both sides, player and computer)
- unexplored ship: '*' on player's terrain, '.' on computer's terrain
- explored water: 'O'
- explored ship, hit: 'x' (both sides)
- explored ship, sunk: 'X' (both sides)
- water, close to at least one unexplored ship: 'O' on player's terrain, '?' on computer's terrain
A typical output would be:
Although it is tempting here, do not mix the actual graphic output with the program logic to determine the character !
The AI
There will be none in here, we simply will cheat (many games do that!). Since the computer is controlling the whole game
and it has the full knowledge to play optimally, we just have to artificially make it more stupid than it actually is.
A move of the computer simply consists of a random shot, the probability of hitting a ship or water is controlled
by the level, from 1: idiot to 5: god.
You can add strategies, e.g. the knowledge about a close shot or a hit, to gain bonus points in this assignment.
The Grading
The following scheme will be used, it also should give you a guideline for the order you should process the different tasks:
- Output: 3 points
- +input: 4 points
- +game logic: 7 points
- + comp AI (=random): 9 points
- +fully working UI, input check etc.: 10 points
- BONUS: a better AI: 1 point
- variable environment, i.e. grid size, number and size of ships: 1 point