The Student Room Group

Aqa comp1 2016

Scroll to see replies

Python code for only letting a player put a piece down if it takes an opponents piece:
def CheckIfMoveIsValid(Board, Move, BoardSize, HumanPlayersTurn):
Row = Move % 10
Column = Move // 10
MoveIsValid = False
if Board[Row][Column] == " ":
if HumanPlayersTurn == True:
Board[Row][Column] = "H"
else:
Board[Row][Column] = "C"
if ((CheckIfThereArePiecesToFlip(Board, BoardSize, Row, Column, 1, 0) == True) or (CheckIfThereArePiecesToFlip(Board, BoardSize, Row, Column, -1, 0) == True) or (CheckIfThereArePiecesToFlip(Board, BoardSize, Row, Column, 0, 1) == True) or (CheckIfThereArePiecesToFlip(Board, BoardSize, Row, Column, 0, -1) == True)):
MoveIsValid = True
else:
MoveIsValid = False
Board[Row][Column] = " "
return MoveIsValid


This will also work with diagonals if you add 4 more CheckIfThereArePiecesToFlip's.
You'll also need to add BoardSize and HumanPlayersTurn when you in PlayGame when you call upon the function
(edited 7 years ago)
Original post by crazyy
Hi guys, I think I managed to allow only moves where pieces can be flipped. Here it is in VB

Function CheckIfMoveIsValid(ByVal Board(,) As Char, ByVal Move As Integer, ByValBoardsize As Integer,ByVal HumanPlayersTurn AsBoolean) As Boolean

Dim Row As Integer
Dim Column As Integer
Dim MoveIsValid As Boolean
Row = MoveMod 10
Column =Move \ 10
MoveIsValid = False
If Board(Row, Column) = " " Then
If HumanPlayersTurn Then
Board(Row, Column) = "H"
Else
Board(Row, Column) = "C"
End If
If (CheckIfThereArePiecesToFlip(Board, Boardsize,Row, Column, 1, 0) = True Or CheckIfThereArePiecesToFlip(Board, Boardsize, Row,Column, -1, 0) = True Or CheckIfThereArePiecesToFlip(Board, Boardsize, Row, Column, 0, 1) = True Or CheckIfThereArePiecesToFlip(Board, Boardsize, Row, Column, 0, -1) = True) Then
MoveIsValid = True
Else
MoveIsValid = FalseThen
Board(Row, Column) = " "
End If
End If
Return MoveIsValid End Function

TheCheckIfMoveIsValid is responsible for validating moves.I extended the function's parameters by adding 'ByVal Boardsize' and 'Byval HumanPlayersTurn'. I also added two if statements inside the IF statement 'Board(Row, Column)= " " then…'. If the user places a coordinate where there is space, their piece will be placed there. Afterwards I made an IF statement where I check if there are pieces to be flipped, I basically copied this from the MakeMove sub routine and made an if statement out of it. If at least one of them are true, then the move is valid, else the move is invalid and the piece will be removed from the board (Board(Row, Column) = "":wink:. I hope this works for you guys.


Could you give us an algorithm for it?
Function CheckIfMoveIsValid(Board, Move,Boardsize, HumanPlayersTurn) As Boolean
Variable Row As Integer
Variable Column As Integer
Variable MoveIsValid As Boolean
Row=Move Mod 10 (same as % )
Column = Move \ 10 (same as // )
MoveIsValid = False
If Board(The x coordinate you inputted,The y coordinate you inputted) = " " (empty space) then
If HumanPlayersTurn=True then
Board(The x coordinate you inputted, The y coordinate you inputted) = "H"
Else
Board(The x coordinate you inputted, The y coordinate you inputted) = "C"
EndIf
If (CheckIfThereArePiecesToFlip(Board, Boardsize,Row, Column,1, 0) = True Or CheckIfThereArePiecesToFlip(Board, Boardsize, Row,Column, -1,0) = True Or CheckIfThereArePiecesToFlip(Board, Boardsize, Row, Column, 0, 1) =True Or CheckIfThereArePiecesToFlip(Board, Boardsize, Row, Column, 0, -1) =True) Then
MoveIsValid = True
Else
MoveIsValid = False
Board(The x coordinate you inputted, They coordinate you inputted) = "C" (we remove the piece)End If
End If
Returen MoveIsValid
You can do this for diagonal as well,you need to add the other four CheckIfThereArePiecesToFlip combinations:'1 1', '-1-1', '1 -1' and '-1 1'.
Original post by aelahi23
Prepare for logic gate because the Electronic answer document contains a table which I assume will be for a simple logic gate.

Hamming code will most likely come up and using hamming code to correct the wrong bit


Have you got a link to the EAD?? :smile:
Original post by frosts16
Have you got a link to the EAD?? :smile:


It's attached
Reply 165
Original post by frosts16
Have you got a link to the EAD?? :smile:


here is the EAD
Thanks! :smile:
Original post by aelahi23
here is the EAD


Thanks man I never knew we can get EAD before the exam
Reply 168
The EAD indicates that Section D this year should be that hard because there are less marks available for the last 2 questions compared to last years paper.

Last year the last Question was 16 marks now its 13 marks including the screen cap
Original post by aelahi23
Prepare for logic gate because the Electronic answer document contains a table which I assume will be for a simple logic gate.


Logic gates are not on the specification for this exam (they are in COMP2 instead) so don't expect a logic gate question.

In previous papers the table has usually been a transition table for a FSM, or a table for a simple dry-run of an algorithm.
Original post by aelahi23
The EAD indicates that Section D this year should be that hard because there are less marks available for the last 2 questions compared to last years paper.

Last year the last Question was 16 marks now its 13 marks including the screen cap


Are you doing the old spec? :smile:
Original post by VietDao
sorry for the late reply, you don't actually need that i put that in there so i could do amendment later when player want to change their initial but you can just do this:
Function ShowValidMove(ByRef board(,) As Char, ByVal boardSize As Integer) Dim x As Integer = 0 For i As Integer = 1 To boardSize For a As Integer = 1 To boardSize If board(i, a) = "X" Then board(i, a) = " " End If If board(i, a) = " " Then board(i, a) = "H" If FlipOpponentPiecesInOneDirection(board, boardSize, i, a, 1, 0, True) Or FlipOpponentPiecesInOneDirection(board, boardSize, i, a, 1, -1, True) Or FlipOpponentPiecesInOneDirection(board, boardSize, i, a, -1, -1, True) Or FlipOpponentPiecesInOneDirection(board, boardSize, i, a, -1, 0, True) Or FlipOpponentPiecesInOneDirection(board, boardSize, i, a, -1, 1, True) Or FlipOpponentPiecesInOneDirection(board, boardSize, i, a, 0, 1, True) Or FlipOpponentPiecesInOneDirection(board, boardSize, i, a, 1, 1, True) Or FlipOpponentPiecesInOneDirection(board, boardSize, i, a, 0, -1, True) Then board(i, a) = "X" x += 1 Else board(i, a) = " " End If End If Next Next Return x End Function

As for where you would implement it, i have implemented in the PlayGame sub just before second do loop and before "DisplayGameBoard(Board, BoardSize)"


I was wondering what this actually shows on the game display as when i have tried to implement this nothing happens, i must have made a mistake somewhere within my code. I will PM you it if you wouldnt mind helping me out please. Also "x += 1" what does that mean?
Does anyone know which variables would be suitable for fixed value, most wanted holder, gatherer and follower?
Original post by crazyy
Function CheckIfMoveIsValid(Board, Move,Boardsize, HumanPlayersTurn) As Boolean
Variable Row As Integer
Variable Column As Integer
Variable MoveIsValid As Boolean
Row=Move Mod 10 (same as % )
Column = Move \ 10 (same as // )
MoveIsValid = False
If Board(The x coordinate you inputted,The y coordinate you inputted) = " " (empty space) then
If HumanPlayersTurn=True then
Board(The x coordinate you inputted, The y coordinate you inputted) = "H"
Else
Board(The x coordinate you inputted, The y coordinate you inputted) = "C"
EndIf
If (CheckIfThereArePiecesToFlip(Board, Boardsize,Row, Column,1, 0) = True Or CheckIfThereArePiecesToFlip(Board, Boardsize, Row,Column, -1,0) = True Or CheckIfThereArePiecesToFlip(Board, Boardsize, Row, Column, 0, 1) =True Or CheckIfThereArePiecesToFlip(Board, Boardsize, Row, Column, 0, -1) =True) Then
MoveIsValid = True
Else
MoveIsValid = False
Board(The x coordinate you inputted, They coordinate you inputted) = "C" (we remove the piece)End If
End If
Returen MoveIsValid
You can do this for diagonal as well,you need to add the other four CheckIfThereArePiecesToFlip combinations:'1 1', '-1-1', '1 -1' and '-1 1'.


Omg, this is much more elegant than where I went and much easier to remember as well!! Bless your soul! :3 Good luck everyone!!
Original post by crazyy
Does anyone know which variables would be suitable for fixed value, most wanted holder, gatherer and follower?


fixed value: can't find one

most wanted holder: Any variable that stores the user's input so "Coordinates" would be one

gatherer: "Score"

follower: can't find one

and regarding the EAD. Question 3 (13) looks like an answer box for one of those "dry-run this dumb algorithm" type questions. I imagine one of those marks (in the box 14) is for correctly determining the purpose of the algorithm.
(edited 7 years ago)
I've got a simple loop to make things easier when checking for diagonal flips. Just in case it helps anyone

for (int x = -1; x < 2; x++)
{
---- for (int y = -1; y < 2; y++)
---- {
--------- FlipOpponentPiecesInOneDirection(Board, BoardSize, Row, Column, x, y);
---- }
}
Original post by aelahi23
The EAD indicates that Section D this year should be that hard because there are less marks available for the last 2 questions compared to last years paper.

Last year the last Question was 16 marks now its 13 marks including the screen cap


Should not* be right?
Original post by DodaWilliams
I've got a simple loop to make things easier when checking for diagonal flips. Just in case it helps anyone

for (int x = -1; x < 2; x++)
{
---- for (int y = -1; y < 2; y++)
---- {
--------- FlipOpponentPiecesInOneDirection(Board, BoardSize, Row, Column, x, y);
---- }
}


Can you do this as pseudo code please?
Original post by ThisGuyThough
Omg, this is much more elegant than where I went and much easier to remember as well!! Bless your soul! :3 Good luck everyone!!


Glad you found my solution useful thanks for helping me too :biggrin: gl in the exam
Do you guys think chapter 6 - System Life cycle will come up this year, I've never seen a question about it ever.

Quick Reply

Latest

Trending

Trending