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

This is for the new Computer Science specification (2018)

Possible Section C Questions
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'

Allow players to skip and end their turn
Allow players to skip a turn and end their turn by drawing three or more letters

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)

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

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)

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

'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:

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.

High-score table feature
Add a high score table

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.

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 --This is solution elaborates over from the first solution-

Time limit when entering choice
Add a time limit for turns

This unit can be referenced in GetChoice so it now looks like this:

Inappropriate-word filter
Filter out inappropriate words

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.

Prevent duplication of words being entered
Description of question

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.

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

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

Deduct points from score if an invalid word is entered
Remove points from the players score if they do not enter a valid word

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

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.

Luke Price, Havant College

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

Wild card / blank tile added
Description of question

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.

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

Vowel dump scores, words with multiple vowels ie AEON, AERO gain bonus points
Description of question

Regex method

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.

Add the ability to set the player names
Add the ability to set the player names

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

Create a circular queue to improve efficiency.
Create a circular tile queue to improve efficiency of program.

Implement a single-player game against the computer
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.

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. def PlayGame(AllowedWords, TileDictionary, RandomStart, StartHandSize, MaxHandSize, MaxTilesPlayed, NoOfEndOfTurnTiles, Computer): 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.

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 Dim bestWord As String = "no words" Dim TempBestWord As String = "" Dim bestWordScore As Integer = 0 For Each word In AllowedWords Dim tiles As String = PlayerTiles If CheckWordIsInTiles(word, tiles) Then TempBestWord = word End If           If GetScoreForWord(TempBestWord, TileDictionary) > bestWordScore Then bestWord = TempBestWord bestWordScore = GetScoreForWord(bestWord, TileDictionary) End If       Next Return bestWord End Function From MGS' DenDen

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)

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).
You can make the word anything. If the user inputs this word and has the required letters they win instantly :D

Sub HaveTurn(ByVal PlayerName As String, ByRef PlayerTiles As String, ByRef PlayerTilesPlayed As String, ByRef PlayerScore As Integer, ByVal TileDictionary As Dictionary(Of Char, Integer), ByRef TileQueue As QueueOfTiles, ByRef AllowedWords As List(Of String), ByVal MaxHandSize As Integer, ByVal NoOfEndOfTurnTiles As Integer) Dim NewTileChoice As String Dim Choice As String Dim ValidChoice As Boolean Dim ValidWord As Boolean Console.WriteLine Console.WriteLine(PlayerName & " it is your turn.") DisplayTilesInHand(PlayerTiles) NewTileChoice = "2" ValidChoice = False While Not ValidChoice Choice = GetChoice If Choice = "1" Then DisplayTileValues(TileDictionary, AllowedWords) ElseIf Choice = "4" Then TileQueue.Show ElseIf Choice = "7" Then DisplayTilesInHand(PlayerTiles) ElseIf Choice = "0" Then ValidChoice = True FillHandWithTiles(TileQueue, PlayerTiles, MaxHandSize) Else ValidChoice = True If Len(Choice) = 0 Then ValidWord = False Else ValidWord = CheckWordIsInTiles(Choice, PlayerTiles) End If               If Choice = "CAT" Then                     'If their word is CAT Console.WriteLine("You win!")          'says they win Console.ReadLine                     'Requires them to hit enter before it ends the program End                                   'ends the whole program End If               If ValidWord Then ValidWord = CheckWordIsValid(Choice, AllowedWords) If ValidWord Then Console.WriteLine Console.WriteLine("Valid word. " & Choice & " scores: " & GetScoreForWord(Choice, TileDictionary) & " points.") Console.WriteLine UpdateAfterAllowedWord(Choice, PlayerTiles, PlayerScore, PlayerTilesPlayed, TileDictionary, AllowedWords) NewTileChoice = GetNewTileChoice End If       End If        If Not ValidWord Then Console.WriteLine Console.WriteLine("Not a valid attempt, you lose your turn.") Console.WriteLine End If       If NewTileChoice <> "4" Then AddEndOfTurnTiles(TileQueue, PlayerTiles, NewTileChoice, Choice) End If       Console.WriteLine Console.WriteLine("Your word was: " & Choice) Console.WriteLine("Your new score is: " & PlayerScore) Console.WriteLine("You have played " & PlayerTilesPlayed & " tiles so far in this game.") End If       End While End Sub

Add more players
Adds more than 2 players to the game.

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.

By Ellesmere College's Leading Computer Science Student

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.