# A-level Computing/AQA/Paper 1/Skeleton program/2018

This is for the new Computer Science specification (2018)

## Possible Section C Questions

Section C:
State the name of a user defined subroutine - CreateTileDictionary
State the name of an identifier for an array variable - Tiles, Contents, TStringArray, TIntegerArray
Give an example of instantiation - TileDictionary As New Dictionary(Of Char, Integer)
Give an example of a subroutine that returns - (1) - An integer - TTileDictionary (2) - A boolean value - QueueOfTiles.IsEmpty (3) - A string - QueueOfTiles.Remove, GetStarttingHand
Give the name of a built in function - print, open
Give an example of an assignment statement - MaxHandSize = 20
Give a name of a subclass that uses iteration and give an example - AddEndOfTurnTiles (For Count := 1 to NoOfEndOfTurnTiles) DO CheckWordIsValid(While...Do)
Give the name of a subclass that uses selection - GetScoreForWord(If Length(word)>7 then Score := Score+20 etc..)
Give the name of a subclass that uses exception handling - LoadALlowedWords (Try...Finally) Why has Try...Finally been used -
State the steps you would have to take in order to add 4 players to the game
Name the subroutine that uses a linear search algorithm - CheckWordIsValid (Follow up) Give the time complexity of a linear search- O(n),
Disadvantage of Linear search - Has to look through each word step by step to find if the word is valid therefore inefficient
Recursion - N/A
Draw a class diagram for QueueOfTiles / a hierarchy chart for the program
Give the name of a method and describe its purpose-
Give an example of an abstract data structure used- a linear queue, dictionary
State the name of an identifier for:
A user-defined data type
A global variable used to store a whole number
A function that returns a string.
A user-defined subroutine that has only one parameter
Explain what happens to the other items in the tile queue when one item is removed.
Why is this inefficient?
Outline how the workings of the tile queue could be improved to avoid this.
The CheckWordIsValid function uses a linear search to check whether Word is in AllowedWords.
What is the big(O) of a linear search?
What more efficient search could be used instead?
Outline how this more efficient search works.
What is its big(O)?
Explain what is meant by exception handling and how exception handling could be used in the GetChoice subroutine.
Explain what is meant by a structured programming approach.
There is a variable called Item in the method QueueOfTiles.Remove. There is also a different variable called Item in the method QueueOfTiles.Show. Explain why these two different variables can have the same identifier.
In the game, the list of allowed words is loaded from a text file. A binary file could have been used instead. Describe a difference between the way in which data are stored in a binary file and the way data are stored in a text file.
What is the difference between a value parameter and a reference parameter? Use examples from the skeleton program to explain your answer.
What is the difference between a procedure and a function?
The subroutines in the Skeleton Program avoid the use of global variables – they use local variables and parameter passing instead. State two reasons why subroutines should, ideally, not use global variables.
Describe the use of the TileDictionary and why a dictionary is appropriate
-Feel free to answer and add questions-

## Change the distribution of letters

Change the distribution of letters so that more common letters like 'E' are more likely to be put into a hand than 'Z'
C#:
Delphi/Pascal:
Java:
Java: Alternative solution:
Python:
VB.NET:
VB.NET (Alternate):

## Allow players to skip and end their turn

Allow players to skip a turn and end their turn by drawing three or more letters
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## When a number other than 1, 4, 7 or 0 is entered, the program shouldn't use that as a word attempt

When a number other than 1, 4, 7 or 0 is entered the program shouldn't use that as a word attempt (adding validation to GetChoice)
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:
A solution that actually works by Joe - KES Bath
Alternative Solution By Big Heny Jnes
Alternative Solution by FatMatt
Alternative Solution By Hamza Shahid
Alternative Solution by Anon tiger (using RegEx)

## Save Game Feature

A feature that allows the user to save the game
C#:
Delphi/Pascal:
Java:
Python:
Python (Json):
VB.NET:

## Improve the searching algorithm

To check if the word is valid the program uses linear search O(n), improve it using a more efficient algorithm, e.g. binary search O(logn)
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:
Binary Search by Joe - KES Bath
Alternative Solution by Anon tiger:
alternative fast solution

## Alert the User if aqawords.txt File is Missing

Tell the player(s) if the required text file is missing
C#:
Delphi/Pascal:
The below unit can be applied to any file name and therefore is very versatile. For example, if the inappropriate words .txt file is needed then this can also be searched for.
The above unit's main procedure 'checkForFileStartup', which runs the subroutines within the unit, can be referenced in the LoadAllowedWords function so it now looks like this:
Java:
Python:
VB.NET:

## Allow players to add new words to the game

Ask the players to add new word(s) to be added to the valid word list.
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## High-score table feature

Add a high score table
C#:
Create a function to read from a high score CSV file, containing the players score and then the players name. The file is read and the sorted using a bubble sort, the top 5 scores and names are then output.
Saves the high score into this new file.
The winner of the game is asked if they would like to save their high score.
The "Main" function is updated to allow a choice 3 to display the current high scores.
The "DisplayMenu" method is also updated to show the user can press 3 to display the high score.
Delphi/Pascal:
Java:
Python2:
The original solution stored the player score as a string type, it then went on to use a lambda function to compare these string values, which ultimately did not work (for me it did not), apologies for the crude code, but it worked for me anyway. Please do edit this if you have a better solution than to this
Python:
VB.NET:

## Time limit when entering choice

Add a time limit for turns
C#:
Delphi/Pascal:
This unit can be referenced in GetChoice so it now looks like this:
Java:
Python:
VB.NET:

## Inappropriate-word filter

Filter out inappropriate words
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## Ask user to confirm their word choice

Ask the user to confirm their word choice or go back and change it if they made a typo etc.
C#:
Delphi/Pascal:
Java:
Python:
Python 2:
VB.NET:

## Prevent duplication of words being entered

Description of question
C#:
The have turn method was edited, such that it adds a valid word to a used word list and then checks each time the user inputs a word if it is inside of this list, if not it has not been used before and is a valid word.
The PlayGame method is also amended to contain the UsedWords string list, this stores all of the valid words which have been played and is passed to the HaveTurn function by ref.
Delphi/Pascal:
Java:
Python:
VB.NET:

## Bonus points if two or more high-scoring tiles are played ie JAZZ (J=5, A=1 ,Z=5, Z=5)

Description of question...
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## Bonus points at end of game for longest and highest-scored words

Description of question
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## Deduct points from score if an invalid word is entered

Remove points from the players score if they do not enter a valid word
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## Display list of words (valid and invalid) used by each player at the end of the game

Description of question
C#:
Firstly a list of strings variable called "PlayedWords" is created inside of the PlayGame Subroutine, this is used to store each of the words that our played by the player. This variable is then passed to the HaveTurn method and too the Display Winners Method.
The HaveTurn method is then edited such it accepts the PlayedWords parameter as ref, if the user plays a word and the word is not 0 in length (blank), then it will be added to the list.
The DisplayWinner method is also eddied such that it cycles through all the word plays and prints them to the console, using a foreach loop.
Delphi/Pascal:
Java:
Python:
VB.NET:
Luke Price, Havant College

## Display the highest-scored word by each player at the end of the game

Description of question
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## Wild card / blank tile added

Description of question
C#:
C#: Another Idea:
This method is also a 'blank tile' however this works as in Scrabble, where it allows user to choose which letter the blank may represent.
Delphi/Pascal:
Java:
Python:
VB.NET:

## The player that has the letter that is closest to “A” will begin the game. A blank tile will win the start of the game

Description of question
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## Vowel dump scores, words with multiple vowels ie AEON, AERO gain bonus points

Description of question
C#:
Delphi/Pascal:
Java:
Python:
Regex method
VB.NET:

## In queue-class definition, make use of the IsEmpty method in Show method

In queue-class definition, make use of the IsEmpty method in Show method.
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## Add the ability to set the player names

Add the ability to set the player names
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## Identification of Acronyms and abbreviations, user given option to enter word/acronym/abbreviation - different points awarded for each

Description of question
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## Create a circular queue to improve efficiency.

Create a circular tile queue to improve efficiency of program.
C#:
Delphi/Pascal:
Java:
Python:
VB.NET:

## Implement a single-player game against the computer

C#:
This involves using an anagram-finding algorithm to make the game unnecessarily difficult to win. I can't imagine this will come up in the exam but I want to avoid doing my actual homework and you're in for the ride.
Python:
Okay so the first thing we're going to do is the function for finding anagrams. The function will be called when the computer needs to enter a word and it will return a valid word.
Next, we're going to modify PlayGame to take an additional boolean parameter. This parameter will be called Computer. When Computer is True, a single-player game will be played against the computer, which is a very useful feature if like me, you don't have any real friends to play against.
There is another step to modifying PlayGame. The way the game will work is that Player One will always be human and Player Two will either be human or the computer according to the boolean value of Computer. So when PlayGame calls the HaveTurn function in its while loop, the value of computer can always be False for Player One. For Player Two, we can simply pass the value of Computer.
Now this won't work unless we update HaveTurn to accept Computer and behave differently when it's the computer's turn. Make sure you change NewTileChoice to NewTileChoice = GetNewTileChoice(Computer).
Okay now we are almost done. We will modify GetNewTileChoice to take Computer as a parameter. It is necessary to use GetNewTileChoice because when the computer chooses either "1", "2", "3", "4", the player needs to be reminded of the options so that they can see which one the computer chose. The number will simply be chosen randomly. No anagrams to find here :(
The last thing to do is change DisplayMenu and Main to allow players to choose single-player. Here is DisplayMenu:
And here is Main:
Yay! It works! Or maybe it doesn't for you because my instructions and code are hot garbage. Anyway, I hope this momentarily distracted you from the pain of A-Levels.
VB.NET:
kinda like the one above but in an inferior language
bang this function in the haveTurn sub as another choice and win ez
lots of love, Luke Price. Havant College
Here is a different version to the one above, and seems to find better words than it. Eg... for the first training go, this code finds "Jonathan" (34) but the above finds "Another" (14).
By Ryan
An alternate solution that uses the CheckWordIsInTile sub routine.
Function FindBestWord(ByVal PlayerTiles As String, ByRef TileDictionary As Dictionary(Of Char, Integer), ByRef AllowedWords As List(Of String)) 'finds the best-scoring word
Or, instead of using an anagram finder, do it the easy way: go through every single word in the text file. (A LOT easier to code)
JAVA:

## Make a secret word that allows the user to instantly win the game if they type it (as long as they have the letters to make it).

Python:
You can make the word anything. If the user inputs this word and has the required letters they win instantly :D
Vb.net:

## Add more players

Adds more than 2 players to the game.
Java:
Python:
By Ellesmere College's Leading Computer Science Student

## Do a frequency analysis on all the words in the dictionary, then assign scores based on those frequencies

In createTileDictionary it assigns 1 point to 8 letters, 2 points to 8 letters, 3 points to 6 letters and then 5 points to the rest. Instead of this, make createTileDictionary received allowedWords as an argument, do a frequency analysis on all the words in the dictionary and then assign 1 point to the 8 highest frequency letters, 2 points to the next 8, 3 points to the next 6 and 5 points to the rest.
Python:
By Ellesmere College's Leading Computer Science Student
Java:

## Implement Bubble Sort when displaying the player's tiles

In DisplayTilesInHand, instead of just outputting the contents of PlayerTiles, use bubble sort to rearrange tiles in alphabetic order.
VB.NET:
Python 3:
Java: