A-level Computing/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.

SampleGame = Ucase(SampleGame)

BoardDimension

SampleGame

GetMove

fileNo

Board

StartRank

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