Hey there! Sign in to join this conversationNew here? Join for free
x Turn on thread page Beta
    • Thread Starter
    Offline

    2
    ReputationRep:
    Saving The Game

    Assign the text file path location to a variable so it's easier to reference later on like this:

    step1) Gamefile<== C:\Arif\Documents\Comp1AQARevers e\GameFile.txt

    you need to include the name of the text file with the correct format.
    you need to use a text file because you can open it in a text editor and view its contents where as a binary file you won't be able to understand what's in it

    step 2) On the first line in the text File needs to hold the numerical value of the BoardSize variable

    Step 3)

    For loop for going through X axis1 to BoardSize do
    For Loop for going through Y axis c<== 1 to BoardSize do For loop with in a for loop is called a "nested For Loop"
    GameFile<== Board[X,Y]) this will loop through all cells in the game and store the contents of every cell into text file
    End of Y for Loop
    End of X for loop

    Step 4) On a new line in the Text file you need to store a 0 or a 1 which represent whose turn it is when the game was being played
    so add a new variable called Turn and then use an IF statement like so
    IF HumanPlayerTurn = True
    Then Turn <== 1
    Else Turn <== 0
    GameFile<== on New Line Turn

    Step 5) Remember to add a statement to Close the File GameFile.txt or your program will crash when you try to save to the file again.

    End of Procedure.

    Step 6) To use this Save procedure you need to call it in the PlayGame procedure and call the Save procedure after the MakeMove function Has been called
    like this

    Display('Press S to save game';
    Input(Choice);
    if Choice = 'S'
    then Run Save procedure

    make a new local variable called "choice" and make the variable "Board" a global variable because this will help you load the saved data.

    To Load the Game Data all you need to do get the program to open the file for it to be ready to be read from
    Then from the First Line on the Text file needs to be Read into the Variable BoardSize
    Then use a nested For Loop to loop through the text file and read the values from the text file into the Board array
    Finally the last line stores whose turn it is and all you need to use is a if statment to check If there is a 1 sotred when HumanPlayersTurn = False (because the Human has already had there turn)
    else HumanPlayersTurn = True
    Offline

    11
    ReputationRep:
    Guys, I have done it.
    After hours of trying to figure out + youtube + more youtube
    i have done the load game
    time to rest and watch anime
    Offline

    1
    ReputationRep:
    (Original post by Filipo)
    If anyone want's a solution to the percentage score of each of the two players, pm me and I will give you the solution
    could i get the solution to this please?
    Offline

    2
    ReputationRep:
    (Original post by rockingmax)
    Well it has been pseudocode for the past 3 years so they might switch it up and do a flowchart! :bunny:
    dm dm just found flowcharts in my book haha
    Offline

    2
    ReputationRep:
    I can't think of anything else to add in python, anyone got any ideas? like the hardest q's they could ask?
    Offline

    11
    ReputationRep:
    Have you done save and load? And placing a piece if it will flip an opponent's piece?

    Posted from TSR Mobile
    • Thread Starter
    Offline

    2
    ReputationRep:
    (Original post by KnightCode)
    Have you done save and load? And placing a piece if it will flip an opponent's piece?

    Posted from TSR Mobile
    i did the save for you, look at the top of the page
    Offline

    1
    ReputationRep:
    I was just wondering if anyone had the EAD for the AQA WARSHIPS exam. It would be a great help if I could have it

    Thanks
    Offline

    2
    ReputationRep:
    What do you guys think is the hardest part of Section A and any ideas on what may come up this year? Vector images and bitmaps etc that stuff came up last year so hopefully it wont come up again since its the hardest for me.
    • Thread Starter
    Offline

    2
    ReputationRep:
    (Original post by Teee123)
    What do you guys think is the hardest part of Section A and any ideas on what may come up this year? Vector images and bitmaps etc that stuff came up last year so hopefully it wont come up again since its the hardest for me.
    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
    Offline

    11
    ReputationRep:
    always good to know how to add, subtract and multiply binary ofc.

    Should i make a video about saving and loading the game? or does everyone already know

    and don't we have a whatsapp group for comp2 btw? I'm doing comp3 also
    Offline

    11
    ReputationRep:
    (Original post by aelahi23)
    Solution to Allow piece placement only when Capturing

    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 then the Move entered by the user will be valid

    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 normally called after the letter has been assigned to the game board cells so the flip function doesn't see an empty space but sees a letter in the place you entered the coordinates for, since we are now calling it earlier before the letter gets assigned to the board of the player entered co-ordinates the function still reads it as an empty space and will not work that is why in step 3 you have to add and if statement to temporarily assign the selected coordinate to hold a letter instead of an empty space
    for some reason, it's closing Player 2/Computer to have multiple turns in one turn.
    how would you implement the final bit if its Multiplayer? since it would be Player1Turn and Player2Turn instead
    Offline

    2
    ReputationRep:
    That would be super useful man
    Offline

    1
    ReputationRep:
    (Original post by KnightCode)
    the Hardest question that i can think of is

    Implementing that the user/computer can only place a piece if it directly next to the piece.
    So far in this game, we can place a piece anywhere but in the real Reversi game, you can only place next to the opponents piece.
    I'm pretty sure this would be too hard for the exam tbh. You'd have to do an adjacency check, but surely there would be special cases if your piece was placed on any of the sides or a corner to prevent it checking off the board and crashing.
    Offline

    2
    ReputationRep:
    (Original post by willgyel)
    I'm pretty sure this would be too hard for the exam tbh. You'd have to do an adjacency check, but surely there would be special cases if your piece was placed on any of the sides or a corner to prevent it checking off the board and crashing.
    It is definitely something they may ask. If you look at last years paper, and the last question in Section D - have a look on how hard that one was! :P
    Offline

    0
    ReputationRep:
    (Original post by aelahi23)
    Solution to Allow piece placement only when Capturing

    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 then the Move entered by the user will be valid

    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 normally called after the letter has been assigned to the game board cells so the flip function doesn't see an empty space but sees a letter in the place you entered the coordinates for, since we are now calling it earlier before the letter gets assigned to the board of the player entered co-ordinates the function still reads it as an empty space and will not work that is why in step 3 you have to add and if statement to temporarily assign the selected coordinate to hold a letter instead of an empty space
    Has anyone made this work for Python?? It doesn't really work this way; When the computer uses the CheckMoveIsValid routine with random coordinates. Those Coordinates permanently change the keyboard due to the early if statement.
    Offline

    2
    ReputationRep:
    (Original post by ThisGuyThough)
    Has anyone made this work for Python?? It doesn't really work this way; When the computer uses the CheckMoveIsValid routine with random coordinates. Those Coordinates permanently change the keyboard due to the early if statement.
    Yeah I'm struggling as well, for some reason it making me thing that perhaps to implement such thing in python is over our capabilities for the first year course, but idk. If anyone has a solution, I would be very glad to see it!
    Offline

    0
    ReputationRep:
    (Original post by Filipo)
    Yeah I'm struggling as well, for some reason it making me think that perhaps to implement such thing in python is over our capabilities for the first year course, but idk. If anyone has a solution, I would be very glad to see it!
    I've been working on this; I've managed to make it so that the computer doesn't mess up the board but now I have a problem where sometimes the wrong spots on the board are erased so the correctness of the algorithm is... Not great... I feel like I'm close to finishing it though but also definitely think for python this is a very difficult task; I could still see it being asked.. >___<.
    Offline

    10
    ReputationRep:
    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(Boa rd, 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
    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) = "". I hope this works for you guys.
    Offline

    11
    ReputationRep:
    (Original post by Teee123)
    That would be super useful man
    Saving and Loading, hope you can understand my accent xD

    https://www.youtube.com/watch?v=aKs1...ature=youtu.be
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: August 19, 2016
Poll
Do you like carrot cake?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.