The Student Room Group

Aqa comp1 2016

Scroll to see replies

Reply 40
Original post by ChuckyTownXL
Title is comp 2 2016 but thanks anyway 👍🏼


Can you not read it says comp1 2016
[QUOTE="aelahi23;64673289"]Can you not read it says comp1 2016[/QUOTE
ooo so you did bother reading the title , because before you said it says resit in the title when it clearly doesn't
(edited 7 years ago)
anyone doing this in Java or just me :frown:
Reply 43
Can anyone create the code for Visual basic for Two player mode and the Loop for wrong coordinate values please.
I've done a check for the co-ordinates in VB. Working on 2 player mode later...

I changed GetHumanPlayerMove to fix the crash that occurred if the player typed a string instead of co-ordinates:
'Get the player's move by asking and reading their response as co-ordinates
Function GetHumanPlayerMove(ByVal PlayerName As String) As Integer
'MY FIX: Crash if non-integer was entered
'Dim Coordinates As Integer
Dim Coordinates As String 'Changed from Integer
Console.Write(PlayerName & " enter the coordinates of the square where you want to place your piece: ")
Coordinates = Console.ReadLine

Try
Return Int(Coordinates)
Catch ex As Exception
Return 0
End Try
End Function
I also changed CheckIfMoveIsValid to return False if the co-ordinates are out of range:'Check if a move is valid - cell is empty
'MY FIX: Add BoardSize attribute
Function CheckIfMoveIsValid(ByVal Board(,) As Char, ByVal BoardSize As Integer, ByVal Move As Integer) As Boolean
Dim Row As Integer
Dim Column As Integer
Dim MoveIsValid As Boolean

'Get row and col from move co-ordinates
Row = Move Mod 10
Column = Move \ 10
MoveIsValid = False

'BEGIN MY FIX
'Return false if Row or Col < 0
'OutOfRangeException occurs if Row or Column is greater than the board size, or < 0
If Row < 0 Or Column < 0 Or Row > BoardSize Or Column > BoardSize Then
Return False
End If
'END MY FIX

'If the cell at the given co-ordinates is empty, the move is valid
If Board(Row, Column) = " " Then
MoveIsValid = True
End If

Return MoveIsValid
End Function

anyone got any code for saving the game?
Reply 46
I did this as a solution to the multiplayer feature in python.
I started off just using the play game function and adapting it as I went. You'll notice I didn't even change computer player to player 2 as it will still function the same. Also, if they asked for your name and you wanted to convert that into a player piece instead of just H I used this and called if the user selects enter name from menu, otherwise by default is is set to H.

Player1Piece = str(PlayerName[0].upper())

def MultiPlayerGame(PlayerName, Player2Name, BoardSize):
Player1Piece = str(PlayerName[0].upper())
print(Player1Piece)
Board = CreateBoard()
SetUpGameBoard(Board, BoardSize)
HumanPlayersTurn = False
while not GameOver(Board, BoardSize):
HumanPlayersTurn = not HumanPlayersTurn
DisplayGameBoard(Board, BoardSize)
MoveIsValid = False
while not MoveIsValid:
if HumanPlayersTurn:
Move = GetHumanPlayerMove(PlayerName)
else:
Move = GetHumanPlayerMove(Player2Name)
MoveIsValid = CheckIfMoveIsValid(Board, Move)
MakeMove(Board, BoardSize, Move, HumanPlayersTurn)
DisplayGameBoard(Board, BoardSize)
HumanPlayerScore = GetPlayerScore(Board, BoardSize, Player1Piece)
ComputerPlayerScore = GetPlayerScore(Board, BoardSize, Player2Piece)
if HumanPlayerScore > ComputerPlayerScore:
print("Well done", PlayerName, ", you have won the game!")
elif HumanPlayerScore == ComputerPlayerScore:
print("That was a draw!")
else:
print("Well done", Player2Name, ", you have won the game!")
print()
Reply 47
FOR PYTHON: For validating user input, there are two things you can do, firstly this that uses a try/except to see that when you convert the input to an integer if it is valid, if it's not the function requests the coordinates again.

def GetHumanPlayerMove(PlayerName): Coordinates = int() print(PlayerName, "enter the coodinates of the square where you want to place your piece: ", end="") try: Coordinates = int(input()) except ValueError: print(PlayerName, "please enter 2 numbers as coordinates! ", end="") return Coordinates

Also, if you alter the check move is valid function so that it looks like this, you can see wether the coordinates that the user has entered are within the range of the board size.

def CheckIfMoveIsValid(Board, Move): Row = Move % 10 Column = Move // 10 MoveIsValid = False if Row > BoardSize or Row < 1: MoveIsValid = False elif Column > BoardSize or Column < 1: MoveIsValid = False elif Board[Row][Column] == " ": MoveIsValid = True return MoveIsValid


Hope it helps someone. Has anyone got any ideas of what else they might ask, as apart from diagonal flips which has already been mentioned the only thing I haven't done yet is save??
For VB:

Coordinate error checking:
To check its an integer they've inputted, tryparse it as an integer to another variable.
To check its within the board size and not blank just use an if statement.

Percentage of human to board size:
Use this:
PercentageScore = (HumanPlayerScore * 100)/(BoardSize * BoardSize)

To allow lower and higher case for menu just use ucase or lcase function.

For skipping a turn or quitting mid-game I've been just allowing x or s as coordinates and letting them bypass the MoveIsValid and GameOver subs/functions. Any better way?

...

Anyone got code for saving highscores and load/saving game?
(edited 7 years ago)
Original post by ollycostello
anyone got any code for saving the game?


I believe Read and Write Text Files would be used to save the game but I do not know exactly how.
Worked out how to save the game on VB.NET.
I don't think the solution is very efficient as had to change where variables are called and a lot of messing about with variables passed.
But yes, involved the read and write to text file.
PM me for code if anyone wants it.
Original post by aelahi23
due to so many requests I'll post the solution here

Step 1) there should be a a function called CheckIfMoveIsValid, what you need to do is modify the if statement to this

If Board[Row, Column] = '"empty space" and(CheckIfThereArePiecesToFlip(Boar d, BoardSize, Row, Column, 1,0 = true
or CheckIfThereArePiecesToFlip(Boar d, BoardSize, Row, Column, -1, 0) = true
or CheckIfThereArePiecesToFlip(Boar d, BoardSize, Row, Column, 0, 1) = true
or CheckIfThereArePiecesToFlip(Boar d, BoardSize, Row, Column, 0, -1) = true)
Then MoveIsValid <== True
what this does is call the function to check if there are pieces to flip and the function will return true or false and if it returns true

Step 2) Make HumanPlayerTurn a global variable instead of a local variable in the PlayGame Function

Step 3)Then paste the following if statement in the function called CheckIfThereArePiecesToFlip right at the start of the function
If HumanPlayersTurn = true
Then Board[StartRow, StartColumn] := 'H'
Else Board[StartRow, StartColumn] := 'C'

when the function to check for flips is called it's called after the letter has been assigned to the game board cells so the flip function doesn't see an empty space but a letter in the place you entered the coordinates for, since we are calling it earlier before the letter gets assigned to the board the function still reads it as an empty space and will not work thats why in step 3 you have to add and if statement to temporarily assign the selected coordinate to hold a letter

if you still don't get it let me know

I have done every other possible problems we discussed on the first page of this thread and have solved them so if anyone is stuck just leave a message here. If I don't do the same language as you I can still provide a working algorithm to solve a problem


Hi, by making HumanPlayersTurn global, does that mean it will need to be passed through CheckIfMoveIsValid, CheckIfThereArePiecesToFlip, FlipOppenentsPiecesInOneDirection and PlayGame?
Reply 52
Original post by aelahi23
due to so many requests I'll post the solution here

Step 1) there should be a a function called CheckIfMoveIsValid, what you need to do is modify the if statement to this

If Board[Row, Column] = '"empty space" and(CheckIfThereArePiecesToFlip(Boar d, BoardSize, Row, Column, 1,0 = true
or CheckIfThereArePiecesToFlip(Boar d, BoardSize, Row, Column, -1, 0) = true
or CheckIfThereArePiecesToFlip(Boar d, BoardSize, Row, Column, 0, 1) = true
or CheckIfThereArePiecesToFlip(Boar d, BoardSize, Row, Column, 0, -1) = true)
Then MoveIsValid <== True
what this does is call the function to check if there are pieces to flip and the function will return true or false and if it returns true

Step 2) Make HumanPlayerTurn a global variable instead of a local variable in the PlayGame Function

Step 3)Then paste the following if statement in the function called CheckIfThereArePiecesToFlip right at the start of the function
If HumanPlayersTurn = true
Then Board[StartRow, StartColumn] := 'H'
Else Board[StartRow, StartColumn] := 'C'

when the function to check for flips is called it's called after the letter has been assigned to the game board cells so the flip function doesn't see an empty space but a letter in the place you entered the coordinates for, since we are calling it earlier before the letter gets assigned to the board the function still reads it as an empty space and will not work thats why in step 3 you have to add and if statement to temporarily assign the selected coordinate to hold a letter

if you still don't get it let me know

I have done every other possible problems we discussed on the first page of this thread and have solved them so if anyone is stuck just leave a message here. If I don't do the same language as you I can still provide a working algorithm to solve a problem


Thank you very much for this, have you also done the multiplayer feature and validating co-ordinate input? I don't do the same language as you but a working algorithm would be very useful as my code seems abit messed :/ thanks
Guys, does anyone have a link to the c# version of the skeleton? Our teacher lost it...
Original post by DodaWilliams
Guys, does anyone have a link to the c# version of the skeleton? Our teacher lost it...


Teachers have access to direct AQA filestores where they can take material from. Tell him/her to call up AQA and ask waddup.

(My teacher called up AQA to get the Python code for me because I was the only one in the year retaking)
Does anyone have VB code or psuedocode to skip a turn or quit (to menu) mid game?
Reply 56
Can anyone help me, i'm using VB and whenever I try to copy in the code some people have given on this thread I keep getting this error and I don't know what to do.
Picture.png
Original post by TSR2k16
Can anyone help me, i'm using VB and whenever I try to copy in the code some people have given on this thread I keep getting this error and I don't know what to do.
Picture.png


Boardsize needs to be inbetween board and move in that line of code I think
Reply 58
Original post by bakersman110
how would you fix it in python??


In CheckIfMoveIsValid you have state that `MoveIsValid = False` and add an if statement to specify the boundaries of the coordinates for row and column separately, and then just print an error message if the coordinates don't satisfy :smile:
hey guys,
Just stating I'm doing C#
and that i'm going to convert most of the solutions here into C#
I have already done the Multiplayer in c# and other features.
If you are also doing c# and want the solutions do tell :smile:

Quick Reply

Latest

Trending

Trending