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

From Wikibooks, open books for an open world
Jump to: navigation, search

This is for the new Computer Science Specification.

This is where suggestions can be made about what some of the questions might be and how we can solve them.

Please be respectful and do not vandalise or tamper with the page, as this would affect students' preparation for their exams!

Change the distribution of letters[edit]

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:


Python:

def Add(self):
    if self._Rear < self._MaxSize - 1:
      letters = "aaaaaaaabbcccddddeeeeeeeeeeeefffggghhhhhhiiiiiijkllllmmnnnnnnooooooopqrrrrrsssssstttttttttuuvvwwxyyz"
      self._Rear += 1
      self._Contents[self._Rear] = random.choice(letters.upper())

OR: 

def Add(self): 
    if self._Rear < self._MaxSize - 1:
      vowels = [0,4,8,14,20]
      consonants = [1,2,3,5,6,7,9,10,11,12,13,15,16,17,18,19,21,22,23,24,25]
      vowelChance = random.randint(0,1)
      if(vowelChance == 1):
        RandNo = random.choice(vowels)
      else:
        RandNo = random.choice(consonants)
      self._Rear += 1
      self._Contents[self._Rear] = chr(65 + RandNo)

VB.NET:

  Public Sub Add()
        Dim RandNo As Integer
        Dim letters As String
        Dim NewLet As String
        If Rear < MaxSize - 1 Then
            letters = "aaaaaaaabbcccddddeeeeeeeeeeeefffggghhhhhhiiiiiijkllllmmnnnnnnooooooopqrrrrrsssssstttttttttuuvvwwxyyz"
            RandNo = Int(Rnd() * (letters.Length - 1))
            NewLet = letters.Substring(RandNo, 1)
            Rear += 1
            Contents(Rear) = Char.ToUpper(NewLet)
        End If
    End Sub

Allow players to skip and end their turn[edit]

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

C#:


Delphi/Pascal:


Java:

	int RandomNumber = 3;

    void addEndOfTurnTiles(QueueOfTiles tileQueue, Tiles playerTiles,
            String newTileChoice, String choice)
    {
        int noOfEndOfTurnTiles;
        if(newTileChoice.equals("1"))
        {
            noOfEndOfTurnTiles = choice.length();
        }
        else if(newTileChoice.equals("2"))
        {
            noOfEndOfTurnTiles = 3;
        }
        else if (newTileChoice.equals("99"))
        {
        	int NumberOfTiles = Integer.parseInt(newTileChoice);
        	noOfEndOfTurnTiles = RandomNumber;
        }
        else
        {
            noOfEndOfTurnTiles = choice.length()+3;
        }
        for (int count = 0; count < noOfEndOfTurnTiles; count++) 
        {
            playerTiles.playerTiles += tileQueue.remove();
            tileQueue.add();
        }
    }

    String getChoice()
    {
        Console.println();
        Console.println("Either:");
        Console.println("     enter the word you would like to play OR");
        Console.println("     press 1 to display the letter values OR");
        Console.println("     press 4 to view the tile queue OR");
        Console.println("     press 7 to view your tiles again OR");
        Console.println("     press 8 to skip a turn OR");
        Console.println("     press 0 to fill hand and stop the game.");
        Console.print("> ");
        String choice = Console.readLine();
        Console.println();
        choice = choice.toUpperCase(); 
        return choice;
    }
    
    void haveTurn(String playerName, Tiles playerTiles, 
            TileCount playerTilesPlayed, Score playerScore, Map tileDictionary, 
            QueueOfTiles tileQueue, String[] allowedWords, int maxHandSize, 
            int noOfEndOfTurnTiles)
    {
      Console.println();
      Console.println(playerName + " it is your turn.");
      displayTilesInHand(playerTiles.playerTiles);
      String newTileChoice = "2";
      boolean validChoice = false;
      boolean validWord;
      while (!validChoice)
      {
        String choice = getChoice();
        if (choice.equals("1"))
        {
          displayTileValues(tileDictionary, allowedWords);
        }
        else if (choice.equals("4"))
        {
          tileQueue.show();
        }
        else if (choice.equals("7"))
        {
          displayTilesInHand(playerTiles.playerTiles);
        }
        else if (choice.equals("0"))
        {
          validChoice = true;
          fillHandWithTiles(tileQueue, playerTiles, maxHandSize);
        }
        else if (choice.equals("8")) {
        	validChoice = true;
        	Random rand = new Random();
        	int RN = rand.nextInt(5) + 3;
        	RandomNumber = RN;
            Console.println("Skip Turn - You will get " + RandomNumber + " Extra Letters ");
            addEndOfTurnTiles(tileQueue, playerTiles, "99", choice);
        }
        else
        {
          validChoice = true;
          if (choice.length() == 0)
          {
            validWord = false;
          }
          else
          {
            validWord = checkWordIsInTiles(choice, playerTiles.playerTiles);
          }
          if (validWord)
          {
            validWord = checkWordIsValid(choice, allowedWords);
            if (validWord)
            {
              Console.println();
              Console.println("Valid word");
              Console.println();
              updateAfterAllowedWord(choice, playerTiles, playerScore, 
                      playerTilesPlayed, tileDictionary, allowedWords);
              newTileChoice = getNewTileChoice();
            }
          }
          if (!validWord)
          {
            Console.println();
            Console.println("Not a valid attempt, you lose your turn.");
            Console.println();
          }
          if (!newTileChoice.equals("4"))
          {
            addEndOfTurnTiles(tileQueue, playerTiles, newTileChoice, choice);
          }
          Console.println();
          Console.println("Your word was:" + choice);
          Console.println("Your new score is:" + playerScore.score);
          Console.println("You have played " + playerTilesPlayed.numberOfTiles + " tiles so far in this game.");
        }
      }
    }

Python:


VB.NET:

Sub AddEndOfTurnTiles(ByRef TileQueue As QueueOfTiles, ByRef PlayerTiles As String, ByVal NewTileChoice As String, ByVal Choice As String)

        Dim NoOfEndOfTurnTiles As Integer
        If NewTileChoice = "1" Then
            NoOfEndOfTurnTiles = Len(Choice)
        ElseIf NewTileChoice = "2" Then
            NoOfEndOfTurnTiles = 3

            ' new else if created. deals three penalty card.
        ElseIf NewTileChoice = "9" Then

            NoOfEndOfTurnTiles = 3

        Else
            NoOfEndOfTurnTiles = Len(Choice) + 3
        End If
        For Count = 0 To NoOfEndOfTurnTiles - 1
            PlayerTiles += TileQueue.Remove()
            TileQueue.Add()
        Next
    End Sub

    Function GetChoice()
        Dim Choice As String
        Console.WriteLine()
        Console.WriteLine("Either:")
        Console.WriteLine("     enter the word you would like to play OR")
        Console.WriteLine("     press 1 to display the letter values OR")
        Console.WriteLine("     press 4 to view the tile queue OR")
        Console.WriteLine("     press 7 to view your tiles again OR")

        ' this is new command line created.
        Console.WriteLine("     press 8 to skip your turn and draw penalty cards OR")

        Console.WriteLine("     press 0 to fill hand and stop the game.")
        Console.Write("> ")
        Choice = Console.ReadLine()
        Console.WriteLine()
        Choice = Choice.ToUpper()
        Return Choice
    End Function

    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)

                ' new statement for the skip.
            ElseIf Choice = "8" Then

                ' Allows the code to continue running
                ValidChoice = True

                ' called function which draws three penalty card 
                AddEndOfTurnTiles(TileQueue, PlayerTiles, "9", Choice)

                ' text output to alart the player of the penalty
                Console.WriteLine("You have skipped your turn. Penalty tiles have been added")
                Console.WriteLine("Number of new tiles added is 3")

            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 ValidWord Then
                    ValidWord = CheckWordIsValid(Choice, AllowedWords)
                    If ValidWord Then
                        Console.WriteLine()
                        Console.WriteLine("Valid word")
                        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

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

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

C#:

        private static string GetChoice()
        {
            string Choice = "";
            string[] ValidChoice = { "1", "4", "7", "0" };
            bool bLoop = true;
            while (bLoop)
            {
                Console.WriteLine();
                Console.WriteLine("Either:");
                Console.WriteLine("     enter the word you would like to play OR");
                Console.WriteLine("     press 1 to display the letter values OR");
                Console.WriteLine("     press 4 to view the tile queue OR");
                Console.WriteLine("     press 7 to view your tiles again OR");
                Console.WriteLine("     press 0 to fill hand and stop the game.");
                Console.Write("> ");
                Choice = Console.ReadLine();
                Console.WriteLine();
                Choice = Choice.ToUpper();

                if (Array.IndexOf(ValidChoice, Choice) == -1)
                    Console.WriteLine("Noooooooo! Invalid choice");
                else
                    bLoop = false;
            }
            return Choice;
        }

Delphi/Pascal:


Java:

    void haveTurn(String playerName, Tiles playerTiles, 
            TileCount playerTilesPlayed, Score playerScore, Map tileDictionary, 
            QueueOfTiles tileQueue, String[] allowedWords, int maxHandSize, 
            int noOfEndOfTurnTiles)
    {
      Console.println();
      Console.println(playerName + " it is your turn.");
      displayTilesInHand(playerTiles.playerTiles);
      String newTileChoice = "2";
      boolean validChoice = false;
      boolean validWord;
      while (!validChoice)
      {
        String choice = getChoice();
        boolean choicecorrect = false;
        while (choicecorrect) {
        	if (choice.equals("1"))
        	{
        		choicecorrect = true;
        		displayTileValues(tileDictionary, allowedWords);
        	}
        	else if (choice.equals("4"))
        	{
        		choicecorrect = true;
        		tileQueue.show();
        	}
        	else if (choice.equals("7"))
        	{
        		choicecorrect = true;
        		displayTilesInHand(playerTiles.playerTiles);
        	}
        	else if (choice.equals("0"))
        	{
        		choicecorrect = true;
        		validChoice = true;
        		fillHandWithTiles(tileQueue, playerTiles, maxHandSize);
        	}
        	else if (choice.equals("2") || choice.equals("3") || choice.equals("5") || choice.equals("6") || choice.equals("8") || choice.equals("9") || choice.equals("1")) {
        		choicecorrect = false;
        	}
        	else
        	{
        		choicecorrect = true;
        		validChoice = true;
        		if (choice.length() == 0)
        		{
        			validWord = false;
        		}
        		else
        		{
        			validWord = checkWordIsInTiles(choice, playerTiles.playerTiles);
        		}
        		if (validWord)
        		{
        			validWord = checkWordIsValid(choice, allowedWords);
        			if (validWord)
        			{
        				Console.println();
        				Console.println("Valid word");
        				Console.println();
        				updateAfterAllowedWord(choice, playerTiles, playerScore, 
        						playerTilesPlayed, tileDictionary, allowedWords);
        				newTileChoice = getNewTileChoice();
        			}
        		}
          if (!validWord)
          {
            Console.println();
            Console.println("Not a valid attempt, you lose your turn.");
            Console.println();
          }
          if (!newTileChoice.equals("4"))
          {
            addEndOfTurnTiles(tileQueue, playerTiles, newTileChoice, choice);
          }
          Console.println();
          Console.println("Your word was:" + choice);
          Console.println("Your new score is:" + playerScore.score);
          Console.println("You have played " + playerTilesPlayed.numberOfTiles + " tiles so far in this game.");
        }
      }
      }
    }

Python:

#Insert into the 'GetChoice' function

if Choice.lstrip('-').isdigit():  
    ValidNum = False  
    while ValidNum == False:  
      if Choice in ["1","4","7","0"]:  
        ValidNum = True  
      else:  
        print "Please enter a valid number"  
        Choice = raw_input(">")

VB.NET:

Function GetChoice()
        Dim Choice As String

        ' Set as False so whenever this function is called, the value is 
        ' reset.
        Dim Check As Boolean = False

        ' Added do loop which will continue this section of the code until  
        ' a specific condition is met. In this case we created boolean variable
        ' which shows if the check function has passed or failed.
        Do

            Console.WriteLine()
            Console.WriteLine("Either:")
            Console.WriteLine("     enter the word you would like to play OR")
            Console.WriteLine("     press 1 to display the letter values OR")
            Console.WriteLine("     press 4 to view the tile queue OR")
            Console.WriteLine("     press 7 to view your tiles again OR")
            Console.WriteLine("     press 0 to fill hand and stop the game.")
            Console.Write("> ")
            Choice = Console.ReadLine()
            Console.WriteLine()

            ' ChoiceCheck is new function created for this purpose.
            Check = ChoiceCheck(Choice)

            ' If statement which output a message when function returns false.
            If Check = False Then
                Console.WriteLine("Invalid Input. Please enter correct option")

            End If

            ' Loops until the check clears.
        Loop Until Check = True
        Choice = Choice.ToUpper()
        Return Choice
    End Function

    ' New function written for the check.
    Function ChoiceCheck(ByVal Choice As String) As Boolean

        ' To be fair, this could be more steramlined. This is only way i could
        ' immediatly think of.
        If Choice = "1" Or Choice = "4" Or Choice = "7" Or Choice = "0" Then
            Return True

            ' not in the spec but this will prevent return key being registered as valid attemp.
        ElseIf Choice = "" Then
            Return False

        Else
            Return False

        End If

    End Function



Alternative Solution By Big Heny Jnes

Choice = GetChoice()
            Checker = RemoveInvalidCharacters(Choice)
            If Checker = False Then
                Console.WriteLine("Invalid Entry. Please Try Again")
            Else
                Try
                    Number = CInt(Choice)
                Catch
                    Checker = True
                End Try
                If Number < 0 Or Number = 2 Or Number = 3 Or Number = 5 Or Number = 6 Or Number > 7 Then
                    Checker = False
                End If
                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)
                ElseIf Checker = False Then
                    Console.WriteLine("Invalid Entry. Please Try Again")
                Else
                    ValidChoice = True
                    If Len(Choice) = 0 Then
                        ValidWord = False
                    Else
                        ValidWord = CheckWordIsInTiles(Choice, PlayerTiles)
                    End If
                    If ValidWord Then
                        ValidWord = CheckWordIsValid(Choice, AllowedWords)
                        If ValidWord Then
                            Console.WriteLine()
                            Console.WriteLine("Valid word")
                            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 If
        End While
    End Sub

    Function RemoveInvalidCharacters(ByVal Choice As String) As Boolean
        Dim FinalOutput As String = ""
        Dim Check As Boolean
        Dim Value As Integer
        Dim x As Integer = -1
        Do
            x += 1
            Value = Asc(Choice.Substring(x, 1))
            If Value > 96 And Value < 123 Then
                Value -= 32
            End If
            If (Value >= 65 And Value <= 90) Or (Value >= 48 And Value <= 57) Then
                Check = True
            Else
                Check = False
            End If
        Loop Until Check = False Or x = Choice.Length - 1
        Return Check
    End Function

Save Game Feature[edit]

A feature that allows the user to save the game

C#:


Delphi/Pascal:


Java:


Python:

def LoadGame():
  SaveFile = open("save.txt",'r')
  lines = SaveFile.readlines()
  PlayerOneData = lines[0].replace("\n","").split("|")
  PlayerTwoData = lines[1].replace("\n","").split("|")
  TileQueueRaw = list(lines[2].replace("\n",""))
  TileQueue = QueueOfTiles(len(TileQueueRaw))
  TileQueue._Contents = TileQueueRaw
  SaveFile.close()
  return PlayerOneData,PlayerTwoData,TileQueue
  
def SaveGame(PlayerData,TileQueue):
  if os.path.exists("save.txt"):
    os.remove("save.txt")
  SaveFile = open("save.txt",'a')
  for data in PlayerData:
    for item in data:
      SaveFile.write(str(item))
      if not item == data[-1]: SaveFile.write("|")
    SaveFile.write("\n")
  TileQueueLetters = "".join(TileQueue._Contents) 
  SaveFile.write(TileQueueLetters+"\n")
  SaveFile.close()
  
def PlayGame(AllowedWords, TileDictionary, RandomStart, StartHandSize, MaxHandSize, MaxTilesPlayed, NoOfEndOfTurnTiles, Load=False):
  if not Load:
    PlayerOneScore = 50
    PlayerTwoScore = 50
    PlayerOneTilesPlayed = 0
    PlayerTwoTilesPlayed = 0
    TileQueue = QueueOfTiles(20)
    if RandomStart:
      PlayerOneTiles = GetStartingHand(TileQueue, StartHandSize)
      PlayerTwoTiles = GetStartingHand(TileQueue, StartHandSize)
    else:
      PlayerOneTiles = "BTAHANDENONSARJ"
      PlayerTwoTiles = "CELZXIOTNESMUAA"
  else:
    try:
      (PlayerOneScore,PlayerOneTilesPlayed,PlayerOneTiles),(PlayerTwoScore,PlayerTwoTilesPlayed,PlayerTwoTiles),TileQueue = LoadGame()
      PlayerOneScore = int(PlayerOneScore)
      PlayerTwoScore = int(PlayerTwoScore)
      PlayerOneTilesPlayed = int(PlayerOneTilesPlayed)
      PlayerTwoTilesPlayed = int(PlayerTwoTilesPlayed)
    except:
      print()
      print("Save file not found")
      print()
      return False

  while PlayerOneTilesPlayed <= MaxTilesPlayed and PlayerTwoTilesPlayed <= MaxTilesPlayed and len(PlayerOneTiles) < MaxHandSize and len(PlayerTwoTiles) < MaxHandSize:
    PlayerOneTiles, PlayerOneTilesPlayed, PlayerOneScore, TileQueue = HaveTurn("Player One", PlayerOneTiles, PlayerOneTilesPlayed, PlayerOneScore, TileDictionary, TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles)
    print()
    input("Press Enter to continue")
    print()
    PlayerTwoTiles, PlayerTwoTilesPlayed, PlayerTwoScore, TileQueue = HaveTurn("Player Two", PlayerTwoTiles, PlayerTwoTilesPlayed, PlayerTwoScore, TileDictionary, TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles)
    print()
    if input("Would you like to save the game? (Y/N)").lower() == "y":
      PlayerOneData = (PlayerOneScore,PlayerOneTilesPlayed,PlayerOneTiles)
      PlayerTwoData = (PlayerTwoScore,PlayerTwoTilesPlayed,PlayerTwoTiles)
      SaveGame((PlayerOneData,PlayerTwoData),TileQueue)

  PlayerOneScore = UpdateScoreWithPenalty(PlayerOneScore, PlayerOneTiles, TileDictionary)
  PlayerTwoScore = UpdateScoreWithPenalty(PlayerTwoScore, PlayerTwoTiles, TileDictionary)
  DisplayWinner(PlayerOneScore, PlayerTwoScore)

def DisplayMenu():
  print()
  print("=========")
  print("MAIN MENU")
  print("=========")
  print()
  print("1. Play game with random start hand")
  print("2. Play game with training start hand")
  print("3. Load saved game")
  print("9. Quit")
  print()
  
def Main():
  print("++++++++++++++++++++++++++++++++++++++")
  print("+ Welcome to the WORDS WITH AQA game +")
  print("++++++++++++++++++++++++++++++++++++++")
  print()
  print()
  AllowedWords = LoadAllowedWords()
  TileDictionary = CreateTileDictionary()
  MaxHandSize = 20
  MaxTilesPlayed = 50
  NoOfEndOfTurnTiles = 3
  StartHandSize = 15
  Choice = ""
  while Choice != "9":
    DisplayMenu()
    Choice = input("Enter your choice: ")
    if Choice == "1":
      PlayGame(AllowedWords, TileDictionary, True, StartHandSize, MaxHandSize, MaxTilesPlayed, NoOfEndOfTurnTiles)
    elif Choice == "2":
      PlayGame(AllowedWords, TileDictionary, False, 15, MaxHandSize, MaxTilesPlayed, NoOfEndOfTurnTiles)
    elif Choice == "3":
      if PlayGame(AllowedWords, TileDictionary, True, StartHandSize, MaxHandSize, MaxTilesPlayed, NoOfEndOfTurnTiles,Load=True) is False: Main()

VB.NET:


Alert the User if aqawords.txt File is Missing[edit]

Tell the player(s) if the required text file is missing

C#:


Delphi/Pascal:


Java:


Python:

def LoadAllowedWords():
  AllowedWords = []
  try:
    WordsFile = open("aqawords.txt", "r")
    for Word in WordsFile:
      AllowedWords.append(Word.strip().upper()) 
    WordsFile.close()
  except FileNotFoundError:
    print("The aqawords.txt file is missing, please download it")
    exit()

VB.NET:


Allow players to add new words to the game[edit]

Ask the players to add new word(s) to be added to the valid word list.

C#:


Delphi/Pascal:


Java:


Python:

def LoadAllowedWords():                         
  AllowedWords = []
  try:
    WordsFile = open("aqawords.txt", "r")
    for Word in WordsFile:
      AllowedWords.append(Word.strip().upper())
    WordsFile.close()
    choice = "yes"
    while(choice == "yes" or choice == "Yes"):
      choice = input("Do you want to add any custom words? ")
      if(choice == "yes" or choice == "Yes"):
        newWord = input("Enter the new word to add : ")
        AllowedWords.append(newWord)
  except:
    pass
  return AllowedWords

VB.NET:

Sub Main()
        Dim Word As String
        Dim MaxHandSize As Integer
        Dim MaxTilesPlayed As Integer
        Dim NoOfEndOfTurnTiles As Integer
        Dim StartHandSize As Integer
        Dim Choice As String
        Dim AllowedWords As New List(Of String)
        Dim TileDictionary As New Dictionary(Of Char, Integer)()
        Console.WriteLine("++++++++++++++++++++++++++++++++++++++")
        Console.WriteLine("+ Welcome to the WORDS WITH AQA game +")
        Console.WriteLine("++++++++++++++++++++++++++++++++++++++")
        Console.WriteLine()
        Console.WriteLine()
        LoadAllowedWords(AllowedWords)
        TileDictionary = CreateTileDictionary()
        MaxHandSize = 20
        MaxTilesPlayed = 50
        NoOfEndOfTurnTiles = 3
        StartHandSize = 15
        Choice = ""
        While Choice <> "9"
            DisplayMenu()
            Console.Write("Enter your choice: ")
            Choice = Console.ReadLine()
            If Choice = "1" Then
                PlayGame(AllowedWords, TileDictionary, True, StartHandSize, MaxHandSize, MaxTilesPlayed, NoOfEndOfTurnTiles)
            ElseIf Choice = "2" Then
                PlayGame(AllowedWords, TileDictionary, False, 15, MaxHandSize, MaxTilesPlayed, NoOfEndOfTurnTiles)
------------------------------------------------------------------------------------------------------------------------------------
            ElseIf Choice = "3" Then
                Console.Write("Word:")
                Word = Console.ReadLine().ToUpper
                AddWordToList(Word)
            End If
-----------------------------------------------------------------------------------------------------------------------------------
        End While
    End Sub
-----------------------------------------------------------------------------------------------------------------------------------
Sub AddWordToList(ByVal Word As String)
        Dim FileWriter As New System.IO.StreamWriter("(Insert your file path)\aqawords.txt", True)
        FileWriter.Write("")
        FileWriter.WriteLine(Word)
        FileWriter.Close()
        Console.WriteLine()
        Console.WriteLine("Word Successfully added")
        Console.WriteLine()
    End Sub
--------------------------------------------------------------------------------------------------------------------------------------
Sub DisplayMenu()
        Console.WriteLine()
        Console.WriteLine("=========")
        Console.WriteLine("MAIN MENU")
        Console.WriteLine("=========")
        Console.WriteLine()
        Console.WriteLine("1. Play game with random start hand")
        Console.WriteLine("2. Play game with training start hand")
----------------------------------------------------------------------------------------------------------------------------------------
        Console.WriteLine("3. Add a word")
----------------------------------------------------------------------------------------------------------------------------------------
        Console.WriteLine("9. Quit")
        Console.WriteLine()
    End Sub

Michael Slater - Jumeirah College

High score table feature[edit]

Add a high score table

C#:


Delphi/Pascal:


Java:


Python:


VB.NET:


Time limit when entering choice[edit]

Add a time limit for turns

C#:


Delphi/Pascal:


Java:


Python:


VB.NET:


Inappropriate word filter[edit]

Filter out inappropriate words

C#:


Delphi/Pascal:


Java:


Python:


VB.NET:


Ask user to confirm their word choice[edit]

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:

def HaveTurn(PlayerName, PlayerTiles, PlayerTilesPlayed, PlayerScore, TileDictionary, TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles): 
  print()
  print(PlayerName, "it is your turn.") 
  DisplayTilesInHand(PlayerTiles)
  NewTileChoice = "2"
  ValidChoice = False
  while not ValidChoice:
    confirmed = False
    while not confirmed:
      Choice = GetChoice()
      if Choice == "1":
        DisplayTileValues(TileDictionary, AllowedWords)
      elif Choice == "4":
        TileQueue.Show()
      elif Choice == "7":
        DisplayTilesInHand(PlayerTiles)      
      elif Choice == "0":
        ValidChoice = True
        TileQueue, PlayerTiles = FillHandWithTiles(TileQueue, PlayerTiles, MaxHandSize)
      else:
        confirmation = input("Press enter to confirm your choice, press x to enter again\n>")
        if confirmation.lower() == "x":
          confirmed = False
        else: confirmed = True
    ValidChoice = True
    if len(Choice) == 0:
      ValidWord = False 
    else:
      ValidWord = CheckWordIsInTiles(Choice, PlayerTiles)
    if ValidWord:
      ValidWord = CheckWordIsValid(Choice, AllowedWords)
      if ValidWord:
        print()
        print("Valid word")
        print()
        PlayerTiles, PlayerScore, PlayerTilesPlayed = UpdateAfterAllowedWord(Choice, PlayerTiles, PlayerScore, PlayerTilesPlayed, TileDictionary, AllowedWords)
        NewTileChoice = GetNewTileChoice()
    if not ValidWord:
      print()
      print("Not a valid attempt, you lose your turn.")
      print()
    if NewTileChoice != "4":
      TileQueue, PlayerTiles = AddEndOfTurnTiles(TileQueue, PlayerTiles, NewTileChoice, Choice)
    print()
    print("Your word was:", Choice)
    print("Your new score is:", PlayerScore)
    print("You have played", PlayerTilesPlayed, "tiles so far in this game.")
  return PlayerTiles, PlayerTilesPlayed, PlayerScore, TileQueue

VB.NET:

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
----------------------------------------------------------------------------------------------------------------------------
        Dim Confirm As String
----------------------------------------------------------------------------------------------------------------------------
        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)
            ElseIf Choice = "9" Then
                ValidChoice = True
                SaveGame(PlayerTiles, PlayerScore, PlayerTiles, PlayerScore, TileQueue)
            Else
                ValidChoice = True
                If Len(Choice) = 0 Then
                    ValidWord = False
                Else
---------------------------------------------------------------------------------------------------------------------------------------
                    While Confirm <> "YES"
                        Console.WriteLine("Are you sure you want to use " & Choice & "? (Yes or No)")
                        Confirm = Console.ReadLine().ToUpper
                        If Confirm = "NO" Then
                            Console.WriteLine("Re-Input Word")
                            Choice = Console.ReadLine()
                        End If
                    End While
---------------------------------------------------------------------------------------------------------------------------------------
                    ValidWord = CheckWordIsInTiles(Choice, PlayerTiles)
                End If
                If ValidWord Then
                    ValidWord = CheckWordIsValid(Choice, AllowedWords)
                    If ValidWord Then
                        Console.WriteLine()
                        Console.WriteLine("Valid word")
                        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
'Theres probably a better way to do this, but this is one solution
Michael Slater - Jumeirah College

Prevent duplication of words being entered[edit]

Description of question

C#:


Delphi/Pascal:


Java:


Python:


VB.NET:



Bonus points if two or more high scoring tiles are played ie JAZ (J=5, A=1 ,Z=5)[edit]

Description of question

C#:


Delphi/Pascal:


Java:


Python:


VB.NET:



Bonus points at end of game for longest and highest scored words[edit]

Description of question

C#:


Delphi/Pascal:


Java:


Python:


VB.NET:


Deduct points from score if invalid word entered[edit]

Description of question

C#:


Delphi/Pascal:


Java:


Python:


VB.NET:



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

Description of question

C#:


Delphi/Pascal:


Java:


Python:


VB.NET:


Display the highest scored word by each player at the end of the game[edit]

Description of question

C#:


Delphi/Pascal:


Java:


Python:


VB.NET: