The Student Room Group

AQA 2015 COMP1 Preliminary material and skeleton code

Howdy,

The preliminary material and skeleton code got released today by AQA. I am a resit of Year 12 myself, and I think this program is harder than last years, not because of the actual programs but because of the concept behind it - ancient chess. Although I haven't really taken a look at it yet.

I have made a small Wikibooks style site for myself and others in my class, what I've got of the preliminary code and skeleton code is here:

http://computing.konsole.uk/x/L4AL

I'll try and keep it updated.

This thread can be used to discuss COMP1 and in particular the parts relating to the preliminary material and skeleton code.
(edited 9 years ago)

Scroll to see replies

Hey mate retaking as well (Python language) I need an A on this paper as last time I had a panic attack in the exam.

I will look for Python code now and give you my view on it
Reply 2
Believe it or not this is not as hard as it seems.

If you're having troubles with this, and your center is doing this in C# or VB.NET then post your questions in my help desk.
http://www.thestudentroom.co.uk/showthread.php?t=3144857

I'll try my best to answer your questions if I have time.

Note: The programmers who coded this are so old skool lol.
(edited 9 years ago)
Hey do you know what i could do to keep the Code on the Screen for when i try to Run it on VB.Net?



Imports System.Math
Module CaptureTheSarrum
Const BoardDimension As Integer = 8


Sub Main()
Dim Board(BoardDimension, BoardDimension) As String
Dim GameOver As Boolean
Dim StartSquare As Integer
Dim FinishSquare As Integer
Dim StartRank As Integer
Dim StartFile As Integer
Dim FinishRank As Integer
Dim FinishFile As Integer
Dim MoveIsLegal As Boolean
Dim PlayAgain As Char
Dim SampleGame As Char
Dim WhoseTurn As Char
PlayAgain = "Y"
Do
WhoseTurn = "W"
GameOver = False
Console.Write("Do you want to play the sample game (enter Y for Yes)? ")
SampleGame = Console.ReadLine
If Asc(SampleGame) >= 97 And Asc(SampleGame) <= 122 Then
SampleGame = Chr(Asc(SampleGame) - 32)
End If
InitialiseBoard(Board, SampleGame)
Do
DisplayBoard(Board)
DisplayWhoseTurnItIs(WhoseTurn)
MoveIsLegal = False
Do
GetMove(StartSquare, FinishSquare)
StartRank = StartSquare Mod 10
StartFile = StartSquare \ 10
FinishRank = FinishSquare Mod 10
FinishFile = FinishSquare \ 10
MoveIsLegal = CheckMoveIsLegal(Board, StartRank, StartFile, FinishRank, FinishFile, WhoseTurn)
If Not MoveIsLegal Then
Console.WriteLine("That is not a legal move - please try again")
End If
Loop Until MoveIsLegal
GameOver = CheckIfGameWillBeWon(Board, FinishRank, FinishFile)
MakeMove(Board, StartRank, StartFile, FinishRank, FinishFile, WhoseTurn)
If GameOver Then
DisplayWinner(WhoseTurn)
End If
If WhoseTurn = "W" Then
WhoseTurn = "B"
Else
WhoseTurn = "W"
End If
Loop Until GameOver
Console.Write("Do you want to play again (enter Y for Yes)? ")
PlayAgain = Console.ReadLine
If Asc(PlayAgain) >= 97 And Asc(PlayAgain) <= 122 Then
PlayAgain = Chr(Asc(PlayAgain) - 32)
End If
Loop Until PlayAgain <> "Y"
Console.Readline()
End Sub


Sub DisplayWhoseTurnItIs(ByVal WhoseTurn As Char)
If WhoseTurn = "W" Then
Console.WriteLine("It is White's turn")
Else
Console.WriteLine("It is Black's turn")
End If
End Sub


Function GetTypeOfGame() As Char
Dim TypeOfGame As Char
Console.Write("Do you want to play the sample game (enter Y for Yes)? ")
TypeOfGame = Console.ReadLine
Return TypeOfGame
End Function


Sub DisplayWinner(ByVal WhoseTurn As Char)
If WhoseTurn = "W" Then
Console.WriteLine("Black's Sarrum has been captured. White wins!")
Else
Console.WriteLine("White's Sarrum has been captured. Black wins!")
End If
Console.WriteLine()
End Sub


Function CheckIfGameWillBeWon(ByVal Board(,) As String, ByVal FinishRank As Integer, ByVal FinishFile As Integer) As Boolean
If Board(FinishRank, FinishFile)(1) = "S" Then
Return True
Else
Return False
End If
End Function


Sub DisplayBoard(ByVal Board(,) As String)
Dim RankNo As Integer
Dim FileNo As Integer
Console.WriteLine()
For RankNo = 1 To BoardDimension
Console.WriteLine(" _________________________")
Console.Write(RankNo & " ")
For FileNo = 1 To BoardDimension
Console.Write("|" & Board(RankNo, FileNo))
Next
Console.WriteLine("|")
Next
Console.WriteLine(" _________________________")
Console.WriteLine()
Console.WriteLine(" 1 2 3 4 5 6 7 8")
Console.WriteLine()
Console.WriteLine()
End Sub


Function CheckRedumMoveIsLegal(ByVal Board(,) As String, ByVal StartRank As Integer, ByVal StartFile As Integer, ByVal FinishRank As Integer, ByVal FinishFile As Integer, ByVal ColourOfPiece As Char) As Boolean
If ColourOfPiece = "W" Then
If FinishRank = StartRank - 1 Then
If FinishFile = StartFile And Board(FinishRank, FinishFile) = " " Then
Return True
ElseIf Abs(FinishFile - StartFile) = 1 And Board(FinishRank, FinishFile)(0) = "B" Then
Return True
End If
End If
Else
If FinishRank = StartRank + 1 Then
If FinishFile = StartFile And Board(FinishRank, FinishFile) = " " Then
Return True
ElseIf Abs(FinishFile - StartFile) = 1 And Board(FinishRank, FinishFile)(0) = "W" Then
Return True
End If
End If
End If
Return False
End Function


Function CheckSarrumMoveIsLegal(ByVal Board(,) As String, ByVal StartRank As Integer, ByVal StartFile As Integer, ByVal FinishRank As Integer, ByVal FinishFile As Integer) As Boolean
If Abs(FinishFile - StartFile) <= 1 And Abs(FinishRank - StartRank) <= 1 Then
Return True
End If
Return False
End Function


Function CheckGisgigirMoveIsLegal(ByVal Board(,) As String, ByVal StartRank As Integer, ByVal StartFile As Integer, ByVal FinishRank As Integer, ByVal FinishFile As Integer) As Boolean
Dim GisgigirMoveIsLegal As Boolean
Dim Count As Integer
Dim RankDifference As Integer
Dim FileDifference As Integer
GisgigirMoveIsLegal = False
RankDifference = FinishRank - StartRank
FileDifference = FinishFile - StartFile
If RankDifference = 0 Then
If FileDifference >= 1 Then
GisgigirMoveIsLegal = True
For Count = 1 To FileDifference - 1
If Board(StartRank, StartFile + Count) <> " " Then
GisgigirMoveIsLegal = False
End If
Next
ElseIf FileDifference <= -1 Then
GisgigirMoveIsLegal = True
For Count = -1 To FileDifference + 1 Step -1
If Board(StartRank, StartFile + Count) <> " " Then
GisgigirMoveIsLegal = False
End If
Next
End If
ElseIf FileDifference = 0 Then
If RankDifference >= 1 Then
GisgigirMoveIsLegal = True
For Count = 1 To RankDifference - 1
If Board(StartRank + Count, StartFile) <> " " Then
GisgigirMoveIsLegal = False
End If
Next
ElseIf RankDifference <= -1 Then
GisgigirMoveIsLegal = True
For Count = -1 To RankDifference + 1 Step -1
If Board(StartRank + Count, StartFile) <> " " Then
GisgigirMoveIsLegal = False
End If
Next
End If
End If
Return GisgigirMoveIsLegal
End Function


Function CheckNabuMoveIsLegal(ByVal Board(,) As String, ByVal StartRank As Integer, ByVal StartFile As Integer, ByVal FinishRank As Integer, ByVal FinishFile As Integer) As Boolean
If Abs(FinishFile - StartFile) = 1 And Abs(FinishRank - StartRank) = 1 Then
Return True
End If
Return False
End Function


Function CheckMarzazPaniMoveIsLegal(ByVal Board(,) As String, ByVal StartRank As Integer, ByVal StartFile As Integer, ByVal FinishRank As Integer, ByVal FinishFile As Integer) As Boolean
If Abs(FinishFile - StartFile) = 1 And Abs(FinishRank - StartRank) = 0 Or Abs(FinishFile - StartFile) = 0 And Abs(FinishRank - StartRank) = 1 Then
Return True
End If
Return False
End Function


Function CheckEtluMoveIsLegal(ByVal Board(,) As String, ByVal StartRank As Integer, ByVal StartFile As Integer, ByVal FinishRank As Integer, ByVal FinishFile As Integer) As Boolean
If Abs(FinishFile - StartFile) = 2 And Abs(FinishRank - StartRank) = 0 Or Abs(FinishFile - StartFile) = 0 And Abs(FinishRank - StartRank) = 2 Then
Return True
End If
Return False
End Function


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 WhoseTurn = "W" Then
If PieceColour <> "W" Then
Return False
End If
If Board(FinishRank, FinishFile)(0) = "W" Then
Return False
End If
Else
If PieceColour <> "B" Then
Return False
End If
If Board(FinishRank, FinishFile)(0) = "B" Then
Return False
End If
End If
Select Case PieceType
Case "R"
Return CheckRedumMoveIsLegal(Board, StartRank, StartFile, FinishRank, FinishFile, PieceColour)
Case "S"
Return CheckSarrumMoveIsLegal(Board, StartRank, StartFile, FinishRank, FinishFile)
Case "M"
Return CheckMarzazPaniMoveIsLegal(Board, StartRank, StartFile, FinishRank, FinishFile)
Case "G"
Return CheckGisgigirMoveIsLegal(Board, StartRank, StartFile, FinishRank, FinishFile)
Case "N"
Return CheckNabuMoveIsLegal(Board, StartRank, StartFile, FinishRank, FinishFile)
Case "E"
Return CheckEtluMoveIsLegal(Board, StartRank, StartFile, FinishRank, FinishFile)
Case Else
Return False
End Select
End Function


Sub InitialiseBoard(ByRef Board(,) As String, ByVal SampleGame As Char)
Dim RankNo As Integer
Dim FileNo As Integer
If SampleGame = "Y" Then
For RankNo = 1 To BoardDimension
For FileNo = 1 To BoardDimension
Board(RankNo, FileNo) = " "
Next
Next
Board(1, 2) = "BG"
Board(1, 4) = "BS"
Board(1, 8) = "WG"
Board(2, 1) = "WR"
Board(3, 1) = "WS"
Board(3, 2) = "BE"
Board(3, 8) = "BE"
Board(6, 8) = "BR"
Else
For RankNo = 1 To BoardDimension
For FileNo = 1 To BoardDimension
If RankNo = 2 Then
Board(RankNo, FileNo) = "BR"
ElseIf RankNo = 7 Then
Board(RankNo, FileNo) = "WR"
ElseIf RankNo = 1 Or RankNo = 8 Then
If RankNo = 1 Then Board(RankNo, FileNo) = "B"
If RankNo = 8 Then Board(RankNo, FileNo) = "W"
Select Case FileNo
Case 1, 8
Board(RankNo, FileNo) = Board(RankNo, FileNo) & "G"
Case 2, 7
Board(RankNo, FileNo) = Board(RankNo, FileNo) & "E"
Case 3, 6
Board(RankNo, FileNo) = Board(RankNo, FileNo) & "N"
Case 4
Board(RankNo, FileNo) = Board(RankNo, FileNo) & "M"
Case 5
Board(RankNo, FileNo) = Board(RankNo, FileNo) & "S"
End Select
Else
Board(RankNo, FileNo) = " "
End If
Next
Next
End If
End Sub


Sub GetMove(ByRef StartSquare As Integer, ByRef FinishSquare As Integer)
Console.Write("Enter coordinates of square containing piece to move (file first): ")
StartSquare = Console.ReadLine
Console.Write("Enter coordinates of square to move piece to (file first): ")
FinishSquare = Console.ReadLine
End Sub


Sub MakeMove(ByRef Board(,) As String, ByVal StartRank As Integer, ByVal StartFile As Integer, ByVal FinishRank As Integer, ByVal FinishFile As Integer, ByVal WhoseTurn As Char)
If WhoseTurn = "W" And FinishRank = 1 And Board(StartRank, StartFile)(1) = "R" Then
Board(FinishRank, FinishFile) = "WM"
Board(StartRank, StartFile) = " "
ElseIf WhoseTurn = "B" And FinishRank = 8 And Board(StartRank, StartFile)(1) = "R" Then
Board(FinishRank, FinishFile) = "BM"
Board(StartRank, StartFile) = " "
Else
Board(FinishRank, FinishFile) = Board(StartRank, StartFile)
Board(StartRank, StartFile) = " "
End If
End Sub
End Module
I havent seen the preliminary material yet, i am re sitting this. Is it harder than last years?
Reply 5
hey guys,
Im also doing Python as well and was wondering if you guys have made any predictions on what type of questions that could come up ?
Anyone have the Python code? Can't find it anywhere :/
I am doing VB Language, wondering about the level of difficulty
Can't seem to get the program working at all on VB :frown:
Never mind our teacher gave us the wrong source code will post my findings!
(edited 9 years ago)
Original post by ScruffyQuaver
Anyone have the Python code? Can't find it anywhere :/


Here's the Python 3 version. I only have a printed copy at the moment, so this is all typed up by me. It all seems to work okay, but I apologise in advance if there's any slight hiccups with my copying!
For anyone who can't seem to get the VB Source working,

Changing the code on line 7 from
Module CaptureTheSarrum
to
Module Module1
will fix your error. Your new project class file is named Module1 therefore you need to define it as module1.

So far I've gathered the following:

If a invalid number or character entered then it gives a run time
error(from Visual Studio), Therefore adding validation and a catch statement to handle this error is probably a question on the paper.



Console.Write("Do you want to play the sample game (enter Y for Yes)? ")

This doesn't remotely suggest what the input to start a new game(For reference you just press enter to go execute the next part of the code and skip the readline) however this could also be another easy question on the exam asking you to amend this.
(edited 9 years ago)
I've used a try and catch to avoid the run time so far

Original post by jbunce12
I've used a try and catch to avoid the run time so far


Looks good to me, maybe adding some context to what the user has did wrong such as
Console.WriteLine("Please enter a number in the following syntax a two digit number, first number is file(row) and rank(col) e.g 23 ")
Original post by Clarkeson
Looks good to me, maybe adding some context to what the user has did wrong such as
Console.WriteLine("Please enter a number in the following syntax a two digit number, first number is file(row) and rank(col) e.g 23 ")


Yeah, fair enough :smile: Was just doing the basic idea
(edited 9 years ago)
Have you guys noticed that the function

Function GetTypeOfGame() As Char
Dim TypeOfGame As Char
Console.Write("Do you want to play the sample game (enter Y for Yes)? ")
TypeOfGame = Console.ReadLine
Return TypeOfGame
End Function

is never actually referred to in the code??
Original post by KhamZ_98
Have you guys noticed that the function

Function GetTypeOfGame() As Char
Dim TypeOfGame As Char
Console.Write("Do you want to play the sample game (enter Y for Yes)? ")
TypeOfGame = Console.ReadLine
Return TypeOfGame
End Function

is never actually referred to in the code??



Sounds to me like that's probably the basis of one of the questions in the paper then...
Reply 16
Original post by jbunce12
I've used a try and catch to avoid the run time so far



No that's a horrible practice. Why are you catching an error instead of preventing it? How would you like if I waited for a criminal to injure your loved one before I arrested them? You would be much more happy if I prevented them from hurting that love one. Same thing here, prevent the error rather than waiting for it to happen to prevent it.

You should only resort to Try Catch when there is no viable way in which to prevent an error from occurring.


Original post by Clarkeson
Looks good to me, maybe adding some context to what the user has did wrong such as
Console.WriteLine("Please enter a number in the following syntax a two digit number, first number is file(row) and rank(col) e.g 23 ")


Why would the numbers be conjoined together? 23? Makes no sense. What if the board size was changed to 25. What you should do is use a delimiter to split the text. So.

2:7 or 2,7 then you split by the delimiter. To get the two seperate values.
So..

userInput = 2:7
bothHalves() = userInput.Split(":")

Console.WriteLine(bothHavles(0))
'Prints out 2
Console.WriteLine(bothHavles(1))
'Prints out 7
(edited 9 years ago)
Original post by BoxTwentyTwo
Sounds to me like that's probably the basis of one of the questions in the paper then...


They already have a few lines in Sub Main() which ask whether the user wants to play another game. My guess would be that they ask us to replace it with this function instead
Original post by Async
No that's a horrible practice. Why are you catching an error instead of preventing it? How would you like if I waited for a criminal to injure your loved one before I arrested them? You would be much more happy if I prevented them from hurting that love one. Same thing here, prevent the error rather than waiting for it to happen to prevent it.


Haha brilliant...

Well done.


I suggest you lookup LBYL and EAFP.
Reply 19
Original post by Push_More_Button
Haha brilliant...

Well done.


I suggest you lookup LBYL and EAFP.


:colondollar:
There isn't much of it up on the internet.. Isit basically what I explained? It's better to prevent an error than to wait for one to happen then catch it?

Quick Reply

Latest

Trending

Trending