# A-level Computing/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Skeleton code/2016 Exam/Skeleton code 2016 Problems(section D in comp1 and most likely section c in paper1 this year)

This is Comp1 for the new Computer Science Specification even though it is under the Computing Wiki. Keep in mind that there is another Comp1 exam for Computing (for retakes?) and this is the place for this older exam. There should be a new wiki for Computer Science with links from both wikis to each other.
Welcome to the paper 1 section C (what used to be section D in past COMP1 papers) for the new 2016 AQA Computer Science Exam.
This is where suggestions can be made about what some of the questions might be and how can we solve them.
Please be respectful and do not vandalise or tamper with the page, as this would affect students' preparation for their exams!
I wish you all good luck with the exam, hopefully we can make it a little easier on ourselves by working together.

## Checking to see if you're off the board - If the player enters over 9 or under 0 it will crash the game.

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution:
Answer :
Answer:
This is a simple way to check the validity of row and column's entered values to ensure they do not exceed the size of the board. The maximum size of the board being 9 and minimum size being 0.
Another way could be to use the 'Try and Except' function in Python, this would help to cover multiple input errors and include the method above in a slightly more efficient way.
This is some more top-notch code from your friendly neighborhood Oliver James Cooke.
Java Solution
Answer :
Answer:
Alternative, checking column and then row separately:
Alternative, with no checking, instead invalid values are truncated.
C# Solution
Answer :
Answer:
p.s. (if you can't do this, you will fail)

## Add a feature which tells the player the type of warship they hit.

This feature may defeat the point of the game. But we shall give it a go anyway.
Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer - Better :
Answer:
Answer :
Answer:
Python Solution
Answer - Better :
Answer:
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## No error checking for erroneous inputs - if a string is entered the program crashes!

This is highly unlikely to come up as it is already implemented in Java but it is good practice nonetheless.
Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Save Game File - The player is able to save an unfinished game.

This would involve adding another menu item between 2 and 9 perhaps to load a saved game?
Saving a game part way through would mean just saving a .txt file and having the option to open it much in the same way a training file works.
We would also need to make sure that when a game is saved it deletes the previous save file, or maybe allow for there to be multiple save slots.
Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer (works) :
Answer:
VB.NET Solution
Answer:
Answer:
Answer :
Answer:
Python Solution
Answer :
Answer:
You will need to add a call to this subroutine into the main PlayGame(Board) subroutine to get it to save the Progress after each turn.
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## How would the game be extended to use a bigger board?

Unlikely as all the ship data would need to be changed. It would take too long in the exam.
Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## How could the game be changed to add another ship?

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Game crashes at the main menu if a string is entered or if the menu option does not exist.

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## On menu you can enter any number. But it crashes when you enter a letter.

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Limit the number of moves for the player to use.

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## No score is given (tell user how many moves they took to win).

-Give % accuracy?(user moves/least possible moves) -Could also add a high score list written to a file (Which would mean adding -another option in the menu).
Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Crashes if no input on column or row: (possibly use a try catch statement).

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
One to use the 'Try and Except' function in Python is shown below, this would help to cover a simple ValueError (string typed in place of an integer input); it also works for the input of a NULL value.
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Add multiple ships of the same type in one game.

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution bad
Answer :
Answer:
Python Solution
Answer :
Answer:
When I modify the code to show the position of the ships when the game is played, I get this result:
I now have two patrol boats on the board.
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Validate Position of Shot

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Add a multiplayer option (another person or the computer).

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
This code overhaul allows two players to compete. Player 1 is represented on the game board by pieces labelled 'A'. Player 2 is represented on the game board by pieces labelled 'B'. This retains the neat structure of the game board.
An alternative method to multiplayer. Although Neil's code suffices, this code might be more efficient.
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Add a message for destroying warships (can be coded in a similar way to CheckWin (Board)).

This adds a message to the user as soon as a Ship has been destroyed. It may quite easily crop up in the exam, as a simple way to get it to work is to copy and modify the existing CheckWin (Board) subroutine. This works by scanning the entire board to check for the existence of ships. You can then check which exist.
Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
This subroutine works similarly to the existing CheckWin(Board). It is called in the same position, too.
Probably not the best example that could be coded in, but it works, and in a way that has already been demonstrated in the skeleton code.
The PlayGame(Board, Ships) subroutine has had a simple line added to call the CheckShipsSunk(Board) subroutine when the game is running.
Answer - Alternative :
Answer:
This solution is simple and uses the lengths of the ships stored in the ships' 2D array.
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Bonus special missile when you sink a ship (such as one with a larger range). (unnecessary)

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Could ask for leaderboard. (very unlikely)

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Clear the environment after every turn has taken place. (pointless)

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Randomize ship positions

VB.NET Solution
Answer :
Answer:

## Allow the player to fire a salvo (i.e. simultaneously enter coordinates for three shots and then make the move)

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Don't subtract a move when a coordinate has been re-entered.

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
This shows how I subtract 1 from the current score every time the same coordinate is entered:
Python Solution
Answer :
Answer:
How to add a set number of turns and how to not miss a turn when the same coordinate is re-entered:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:

## Allow user to enter their own ships on the board

Delphi/Pascal Solution
Answer :
Answer:
VB.NET Solution
Answer :
Answer:
Java Solution
Answer :
Answer:
C# Solution
Answer :
Answer:
Python Solution
Answer :
Answer:

## Load Text File

VB.NET Solution
Answer :
Answer:
Delphi/Pascal Solution
Answer :
Answer:
Python Solution
Answer :
Answer:

## Allow diagonal placement of ships

Java Solution j
Answer :
Answer:
Python
Answer :
Answer:
Changes have to be made to 3 of the functions; ValidateBoatPoisition, PlaceShip and PlaceRandomShips:

## Allow user to enter two-digit co-ordinates, so 35 instead of 3 then 5

VB.NET Solution
Answer 1 :
Answer:
Answer 2 :
Answer:
Python Solution
Answer:
Answer:
Java Solution
Answer:
Answer:

## If a miss, scan one element near the miss to see if a ship is present

VB.NET Solution
Answer :
Answer:
Python Solution
Answer :
Answer:
Java Solution:
Answer :
Answer:

## Performing Run-length Encoding on the 'Board', possibly useful when saving the game.

Performing some Run-length Encoding on the 'Board', possibly useful when saving the game. This would work in a similar way to the 'Generate FEN' question from last year's COMP1 paper.
Python Solution:
Answer :
Answer:
C# Solution
Answer :
Answer:

## Torpedo Function: fires vertically until a ship is hit or a column has been torpedoed.

Java Solution
Answer :
Answer:
Python
Answer :
Answer:
Changes have to be made to the subroutine 'PlayGame' as well as creating a new subroutine 'MakeTorpedoMove'.