A-level Computing/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Skeleton code/2016 Exam Resit

2016 Old Spec Comp 1: AQA REVERSE ANSWERS!
Please put the question number followed by what your answer was, thanks for contributing. I would also like to thank everyone who, along with me, created this page, very good and had most of the solutions on what came up in the exam.


 * 1)  Binary number was:
 * 2)  Hexadecimal number was B4
 * 1)  Hexadecimal number was B4
 * 1)  Hexadecimal number was B4

2016 Old Spec Comp 1: AQA REVERSE
The Skeleton Program accompanying this Preliminary Material is for the board game AQA REVERSE.

AQA REVERSE is a board game in which a human plays against the computer. Each player takes it in turn to make a move by specifying coordinates of where they would like to place one of their pieces – the human player uses pieces labelled "H" and the computer uses pieces labelled "C". A piece can only be put in an empty square on the board.

After a player has put a piece on the board any of the opponent’s pieces that are now trapped, either horizontally or vertically, between the piece just placed and one of the player’s other pieces are flipped – this means that they now change their label (if they were an "H" they become a "C" and vice versa). There must be no empty spaces or other pieces belonging to the player between the two trapping pieces.

The game finishes when every square on the board contains a piece. The winner is the player who has the most pieces on the board at the end of the game. The human player always moves first.

The default board consists of a 6x6 grid of squares.

If you want to communicate I will be able to help: Contacts:

I am one of the contributors to the coding solution, I am a python coder and I can help with any solution.

I can talk about my the solution as pseudo or plain English if it isn't python and a python solution. My contact is: rad-wane@hotmail.co.uk

Please go to the discussion page at the top of the page to talk. Note be-careful and aware of the contact you put here Please contribute to this website as you can see in this link: https://en.wikibooks.org/wiki/A-level_Computing_2009/AQA/Problem_Solving,_Programming,_Data_Representation_and_Practical_Exercise/Skeleton_code/2015_Exam/Section_D

Similar Games:


 * Chinese Go is very similar to this game
 * The real board game version (called Othello) has these other rules:
 * 1) Diagonal capture is allowed (along with horizontal and vertical)
 * 2) Pieces can only be placed where flips will occur
 * 3) If no flips are possible, the player's turn is skipped.

Potential questions could include:

 * A loop for invalid co-ordinates
 * To accept both upper case and lower case inputs for Selection Menu
 * Saving and Loading (Board layout and whose turn)
 * Two player mode
 * A tally of scores after match is over
 * Ability to change player's initials from H and C
 * Starting position of pieces changed
 * Computer move may be asked to be modified
 * Entering your name before the game starts
 * Flip Diagonally
 * Only allowing a player to place a piece if it captures opponent piece
 * Skip Turn
 * (More to follow)

If adding to this list, please provide tangible and measurable changes.

"Changing capture rules" is not a workable idea unless possible changes are also stated.

This is the skeleton program: (Please add to this and make sure it is the full code, mistakes could be costly)
Visual Basic Code:

Python Code:

C# Code:

A loop for invalid co-ordinates
Java:

VB.Net:

Python:

C#:

OR

To accept both upper-case and lower-case inputs for Selection Menu
Python:

C#:

Only letting a player place a piece if it captures the opponent's piece
In the original Reversi game you are only allowed to place a piece if it captures the opponent's piece.

Python :

Saving and Loading (Board layout and whose turn)
I haven't made it load yet, but it does save in a text file called test. If anyone has other ideas on how to do this I'll code other possible solutions. This current one, saves the board every turn and whose turn, true means its human turn, false computer. Vb.Net - Using last year's as an example this is what I came up with, I could definitely be improved but is a starting point.

To save the game i put in a If statement when the human move was fetched so when the input move = 6666 the save sub was run

To make the Load game sub work, I put another case statement into the menu that set a variable Gameload = true and ran the play sub passing it through. Then in the play sub an if statement that when true runs the load game sub, while also making sure to stopped the SetupGameBoard sub overwriting the save.

Saving The Game: Sub Savegame(ByVal Board As Char, ByVal HumanPlayersTurn As Boolean, ByVal Boardsize As Integer)

'Passed into the sub all values that need to be saved. Current board, whose turn it is and the board size. 'To access a .txt file you need to import System.Io       'Declare a variable as a tool to write with Dim SaveFileWriter As StreamWriter Dim TurnFileWriter As StreamWriter

'Declare where the text file is, I have two files one for Turn and board size. One for the actual board layout Dim BoardSave As String = "c:\users\at\documents\visual studio 2010\Projects\Exam code\Save.txt" Dim TurnSizeSave As String = "C:\Users\at\Documents\Visual Studio 2010\Projects\Exam code/TurnSizeSave.txt"

'This variable converts the whose move boolean into a character string you can store Dim whosemove As String

'This declares whos turn it is in string form If HumanPlayersTurn = True Then whosemove = "Human" Else whosemove = "Computer" End If

'Recording all the boord positions cycles through all column/row combinations and written then one line per coordinate SaveFileWriter = New StreamWriter(BoardSave, False) For Rowno = 1 To Boardsize For ColumnNo = 1 To Boardsize SaveFileWriter.WriteLine(Board(Rowno, ColumnNo)) Next Next SaveFileWriter.Close

'This section records whos turn it was on the first line and board size on the second TurnFileWriter = New StreamWriter(TurnSizeSave, False) TurnFileWriter.WriteLine(whosemove) TurnFileWriter.WriteLine(Boardsize) TurnFileWriter.Close Console.WriteLine("The game has been saved") End Sub

Loading the game: Sub loadgame(ByRef BoardSize As Integer, ByRef HumanPlayersTurn As Boolean, ByRef Board As Char) 'Declare one reader for the save file and one for the turn/boardsize file Dim SaveFileReader As StreamReader Dim TurnFileReader As StreamReader Dim whosturn As String

'The two locations of the save files Dim Save As String = "C:\Users\at\Documents\Visual Studio 2010\Projects\Exam code\Save.txt" Dim TurnSize As String = "C:\Users\at\Documents\Visual Studio 2010\Projects\Exam code\TurnSizeSave.txt"

'Reads in the first line of the Turn/Board size save and converts it back to the boolean TurnFileReader = New StreamReader(TurnSize) whosturn = TurnFileReader.ReadLine

'NOTE MUST BE OPOSITE TO WHOS TURN IT WAS AS THE PLAY SUB USES WHATEVER THE BOOLEAN IS NOT If whosturn = "Human" Then HumanPlayersTurn = False ElseIf whosturn = "Computer" Then HumanPlayersTurn = True Else Console.WriteLine("Error loading turn") HumanPlayersTurn = True End If

'Fetchs boardsize BoardSize = TurnFileReader.ReadLine TurnFileReader.Close

'Cycles though all the coordinates for the board size and loads what was saved in the Save.txt file SaveFileReader = New StreamReader(Save) For Row = 1 To BoardSize For Column = 1 To BoardSize Board(Row, Column) = SaveFileReader.ReadLine Next Next End Sub

Adapting the program to load the save:

In Sub Main - Case "l" GameLoaded = True PlayGame(PlayerName, BoardSize, GameLoaded)

In Setup Board - Enclose all code with If Gameloaded = False Then ..... End If

In PlayGame -

If Gameloaded = True Then loadgame(BoardSize, HumanPlayersTurn, Board) End If

Python (Method 1):

Python (Method 2):

Another Way of Saving (Nested FOR Loops to separate data from board lines)

C#:

Two player mode
Python: Firstly I have added another choice on the main menu called (m)ultiplayer game, where user will enter 'm' to play against each other, this will straightly ask them to enter their names, I stored the first player's players name in the variable PlayerName and the second in another variable I made called PlayerTwoName. I then call the play game function passing on three parameters PlayerName, PlayerTwoName, BoardSize. Because I added another parameter that it takes I had to pass another parameter when the computer plays with human so I added none leaving the other two so like (PlayerName,None, BoardSize). In the PlayGame function just before the computer gets it's move, I made a check to see if it's two players against a computer or a human, this was simply done by that variable/parameter I have passed on, if Player2Name does not equal none, then we know it is another human player as we passed his/her name. Under that I did Move = GetHumanPlayerMove(Player2Name), this is calling the function GetHumanPlayerMove but passing a different parameter than the computer. Otherwise/else it is a computer so we keep the existing line Move = GetComputerPlayerMove(BoardSize) but under the if statement as else. I then just added some extra bits so instead of "Press the Enter key and the computer will make its move" I did a check to see if it is against human player and then added anther message saying press enter so 'player2name' will make their move, for example. Also a message saying player 2 won instead of computer won.

C#:

Vb.net

Ability to change player's initials from H and C
Python:

C#:

The solution here changes the default H to the first letter of the player's name when entered through the menu.

Entering your name before the menu appears
Python:

C#:

Flip Diagonally
Python:

C#:

Showing the User's score after a Game is finished.
I have quite simply added ONE line of code in to the original section which calculated when the game was over.

It now just tells you your score against how many spaces were on the board originally.

Python:

C#:

Section A Questions:
Section A usually doesn't relate to the skeleton program. The type of question that will be asked is:Correct any mistakes I make here, please.

''' POINT TO NOTE, AS YOU ARE NOT ALLOWED A CALCULATOR YOU CAN USE THE COMPUTER AND YOUR PROGRAMMING LANGUAGE TO CALCULATE THINGS, worth learning it though. '''


 * Representing denary values to binary, e.g. in last year's paper it was represent 55 using 8 bit unsigned binary.r

The way to go about this is, you will firstly know that 8 bits means there will be 8 numbers. The answer will be: 00110111 Learn how to convert from binary to denary and vice versa

Look at Two's compliment
 * Two's compliment, this is basically a negative binary value, the 1 at the end (to your left) will usually tell you if it is negative, this is when it says it is signed.

Don't forget to know the range of the negative bits too
 * DON'T FORGET denary numbers which have a decimal e.g. 5.625. This is simply 1/2^n, where n is the next column to your right, so it goes 0.5, 0.25, 0.125, 0.0625. It halves each time.
 * You will need to know the range of denary numbers that can be represented by a certain bit value. This is easily worked out, if it is positive 2^n, where n is the amount of bits, meaning if I was using 8 bits, I could represent 2^8 values which is 256 bits.

Advantages and disadvantages so mostly talk about the quality of image, the size the file is...
 * Look at Hexadecimal that is 0-9 A-F, usually represented in 4 bits.
 * Understand why, for example hexadecimal is used instead of binary. This can be so it is faster to write, easier to read, takes less space to display on the screen...
 * The amount of characters 7-bit ASCII and 8-Bit ASCII can represent. 7 bit can do 128 character and 8 bit is 256 characters same as doing 2^n.
 * You need to know what an algorithm is, my definition is a set of instructions to solve a given problem independent of any programming language
 * Know your what parity bits are, odd and even parity. It is validation usually used in communication to check if the message has been received without any errors.
 * Know Hamming code - Hamming code uses multiple parity bits and understand how it works.
 * Find errors given parity bits or hamming code, so by looking at if the value is odd or even depending on type of parity/hamming code.
 * Know how to follow/read and understand an algorithm.
 * FSM - finite state machines, read,follow and understand them.
 * Transition tables
 * Bit Maps, Vector graphics, resolutions, colour depth...


 * Know what floor division is //, know what '%' is know what mod does, mod finds the remainder from dividing one number with another. 12 mod 10 (12% 10 in Python) would be 2.
 * Structured Charts!

''' THESE ARE JUST SOME OF THE THINGS YOU'LL NEED TO KNOW. DON'T JUST RELY ON THIS AS I MAY HAVE MISSED SOME THINGS. '''

Section C - Potential Questions:
State a User Defined Subroutine with only one parameter: 1)GetHumanPlayerMove 2)GetComputerPlayerMove 3)PrintLine 4)GetMenuChoice

State a User-defined subroutine whose only action is to produce output to the screen: 1)DisplayGameBoard 2)PrintLine 3)DisplayMenu

State a Local variable: 1)BoardSize 2)PlayerName 3)Choice

State a Global variable: 1)BoardSize 2)PlayerName 3)Choice

Variable that has a stepper role: 1)Row 2)Column

Variable that has a Gatherer role: 1) Score

Array variable: 1)Board

Describe the circumstances under which this structure in the Skeleton Program will stop repeating: When the int value of the Global Variable of BoardSize has been reached, or when the game has been won by a player.

Why has a For loop been chosen for the repetition structure : The program is fed the specified number of times it has to repeat ( e.g. BoardSize parameters ), therefore a for loop has been used as it allows the user/player to pick a specific range, and execute it the specified amount of times.

#State two reasons why subroutines should, ideally, not use global variables : 1)Easier re-use of routines in other programs; 2)Routine can be included in a library; 3)Helps to make the program code more understandable; 4)Ensures that the routine is self-contained // routine is independent of the rest of the program; 5)(Global variables use memory while a program is running) but local variables use memory for only part of the time a program is running; 6)reduces the possibility of undesirable side effects; 7) Using global variables makes a program harder to debug;

Name a variable used to store whole numbers : 1)Coordinates 2)BoardSize

State a User-defined subroutine that has exactly two parameters : (Arguments are values assigned to the parameter that is passed through) (Paramters are the names passed through the function or subroutine) 1)SetUpGameBoard(Board, Boardsize) 2)GameOver(Board, BoardSize) 3)CheckIfMoveIsValid(Board, Move): 4)DisplayGameBoard(Board, BoardSize) 5)PlayGame(PlayerName, BoardSize)

What does random.seed do? 1) Makes it more random

Why has MOD 10 been used? 1) To get the second digit of a two digit number

State a Built-in function with exactly one parameter that returns an integer value: 1)GetHumanPlayerMove(PlayerName) ====> (gets the integer value of coordinates)

Explain what is meant by a boundary value 1)Boundary values are those just inside, on and just outside the range of allowed values

Built-in function that converts a string into a different data type : 1)int Variable Types