# 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.
* Binary number was:
* 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:
Answer:
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:
* Diagonal capture is allowed (along with horizontal and vertical)
* Pieces can only be placed where flips will occur
* 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:
Answer:
Python Code:
Answer:
C# Code:
Answer:

### A loop for invalid co-ordinates

Java:
Answer:
VB.Net:
Answer:
Python:
Answer:
C#:
Answer:
OR
Answer:

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

Python:
Answer:
C#:
Answer:

### Skipping a turn

Answer:

### 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 :
Answer:

### 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.
Answer:
Sub Savegame(ByVal Board(,) As Char, ByVal HumanPlayersTurn As Boolean, ByVal Boardsize As Integer)
Loading the game:
Adapting the program to load the save:
In Sub Main - Case "l"
In Setup Board - Enclose all code with If Gameloaded = False Then ..... End If
In PlayGame -
Python (Method 1):
Answer:
Python (Method 2):
Another Way of Saving (Nested FOR Loops to separate data from board lines)
Answer:
C#:
Answer:

### 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.
Answer:
C#:
Answer:
Vb.net
Answer:

### Ability to change player's initials from H and C

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

### Entering your name before the menu appears

Python:
Answer:
C#:
Answer:

### Flip Diagonally

Python:
Answer:
C#:
Answer:

### 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:
Answer:
C#:
Answer:

## 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
* 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.
Look at Two's compliment
* 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.
Don't forget to know the range of the negative bits too
* 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...
Advantages and disadvantages so mostly talk about the quality of image, the size the file is...
* 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
| Fixed Value | A variable that is given a value that then does not change for a duration of a loop |
| BoardSize | Is set to 6 towards the end of the code, but it could be most recent holder because it can be changed once the program has started |
| Stepper | A variable used to move through an array or other data structure, often heading towards a fixed value and stepping through elements in an array |
| Row | Is used to iterate through the board to give a total amount of rows |
| Column | Is used to iterate through the board to give a total amount of columns |
| Count | It iterates through the board adding the correct number of elements to create sufficient spaces |
| Count2 | Will again iterate through the board which will adding "" to represent a blank space |
| Most Recent Holder | A variable used to record the last thing inserted by a user or a the latest value being read from an array |
| Playername | Will use the latest name entered throughout the program |
| Choice | Will take the latest value inputted and compare against the available options and enter that menu. |
| Move | It is assigned a value and it is used later in the program. |
| Gatherer | A variable that accumulates or tallies up set of data and inputs. It is very useful for calculating totals or totals that will be used to calculate averages. |
| Score | Tallies up total number of pieces of human/computer which gives the total score |
| Most Wanted Holder | A variable that keeps track of the lowest or highest value in a set of inputs |
| Not Sure | Please add if you think there is |
| Follower | Used to keep check of a previous value of a variable, so that a new value can be compared |
| Not Sure | There is None |
| Temporary | A variable used for storing something for a very short period of time |
| Coordinates | The program will only hold the coordinates for one turn, before holding the computer's and back around to the human's coordinates again |
| Transformation | Used to store the result of a calculation involving more than one variable |
| RowCount | stores result of adding the variables StartRow and RowDirection |
| ColumnCount | stores result of adding the variables StartColumn and ColumnDirection |