A-level Computing 2009/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Skeleton code/2015 Exam/Section C

Validation
Example Answer

Function CheckMoveIsLegal(ByVal Board As String, ByVal StartRank As Integer, ByVal StartFile As Integer, ByVal FinishRank As Integer, ByVal FinishFile As Integer, ByVal WhoseTurn As Char) As Boolean Dim PieceType As Char Dim PieceColour As Char If FinishFile = StartFile And FinishRank = StartRank Then Return False End If       PieceType = Board(StartRank, StartFile)(1) PieceColour = Board(StartRank, StartFile)(0) If FinishRank = 0 Or FinishFile = 0 Then 'This is the required if statement Return False End If

Variables
If Asc(SampleGame) >= 97 And Asc(SampleGame) <= 122 Then SampleGame = Chr(Asc(SampleGame) - 32) End If

This converts lowercase to uppercase by using ASCII values.

{{CPTQuestion|What simple function can replace this code with? If Asc(SampleGame) >= 97 And Asc(SampleGame) <= 122 Then SampleGame = Chr(Asc(SampleGame) - 32) End If (Answer in Code)

SampleGame = Ucase(SampleGame)

{{CPTQuestion|Give the name of the identifier of a Constant }} {{CPTAnswerTab}} BoardDimension {{CPTAnswerTabEnd}}

{{CPTQuestion|Give the name of the identifier of a Fixed Value Variable}} {{CPTAnswerTab}} SampleGame {{CPTAnswerTabEnd}}

{{CPTQuestion|Give the name of a Most Wanted Holder Variable}} {{CPTAnswerTab}} GetMove {{CPTAnswerTabEnd}}

{{CPTQuestion|Give the name of the identifier of a Stepper Variable}} {{CPTAnswerTab}} fileNo {{CPTAnswerTabEnd}}

{{CPTQuestion|Give the name of the identifier of a Temporary Variable}} {{CPTAnswerTab}} Board {{CPTAnswerTabEnd}}

{{CPTQuestion|Give the name of the identifier of a Transformation Variable}} {{CPTAnswerTab}} StartRank {{CPTAnswerTabEnd}} {{CPTExerciseEnd}}

Loops
The 'for' loop will run a set number of times and finish when the count is complete. A repeat until loop will run until a condition has been met, the condition is checked at the end of the loop so it is possible for the loop to run once

Example Answer

Example Answer

Sub Routines
DisplayWinner, displayWhoseTurnItIs

Extra Stuff
To allow the use of Abs in the process of checking whether moves are legal.

To return the absolute value. This is needed because the result of (FinishFile - StartFile) or (FinishRank - StartRank) may be a negative number, whilst the move is still legal. The Abs function returns the positive alternative, which prevents the program from crashing