-1
        SauvegardePlateau = plateau         
        print(SauvegardePlateau)
        deplacement(VP,X1,Y1,X2,Y2) #changes the value in the first "plateau"
        dessinpieces()
        print(SauvegardePlateau)
        Turn=0

        if SauvegardePlateau != plateau:
            if Joueur==1:
                Joueur=2
            else:
                Joueur=1 

at the first "print(SauvegardePlateau)" it gives me the "plateau" as it should do but on the second print it gives me the one that has been changed when i only changed "plateau" and didn't change "SauvegardePlateau"

the aim is to be able to cancel a move, so I need to save the plateau in a variable (SauvegardePlateau) before my main plateau changes but wiredly they both change which means that my "if SauvegardePlateau != plateau" never works

I don't understand why it's doing that, if you could please help me ? Thanks ! (sorry for english errors i'm french)

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 1
    is `plateau` a list ? – t.m.adam Apr 13 '17 at 11:03
  • Just an advice Thomas, if you are starting in python, please find out best practices regarding the way code is written, Python makes use of snake_case and not CamelCase as @Arnaud Prest clarified. – Ilhicas Apr 13 '17 at 14:10

2 Answers2

0

I can't edit your question to sort things out, hence why I'm making this answer.
First, some translation, so that others have an easier time reading the code:

  • "Plateau" = "Board"
  • "SauvegardePlateau" = "Save Board" (although "Backup Board" is more appropriate)
  • "deplacement" = "move"
  • "dessinpieces" = "draw (chess) pieces"

Now that this is out of the way, let's address your actual problem:

First, you should stick to proper style guidelines, as defined in PEP 8. This will greatly improve the readability of your code.

On the technical part, what you are trying to do is:

  • Backup the board
  • Change the board's state by moving a piece
  • Checking backup you made earlier

In python, if you do the following:

>>> board = ["Begin"]
>>> backup = board
>>> board.append("Change!")
>>> backup
['Begin', 'Change!'] 

You can clearly highlight the issue. backup is not a copy of board, but a link to it.
To obtain a proper "copy" of your list, and judging from the code sample you've provided, it looks like:

sauvegarde_plateau = list(plateau)

Will suit your needs. See this answer for more details.

Community
  • 1
  • 1
user768518
  • 114
  • 6
0

Thank you ! Helped me a lot, thanks for the time you put in to explain me this and yes sorry I should've translated it ! (Though it's for my BAC (A levels equivalent) so I need it all in french). Anyway thank you for your detailed answer.