I'm making a chess program on Python by using dictionaries, and to set up my board I do:
EmptyBoard = {
8:['☐','☒','☐','☒','☐','☒','☐','☒'],
7:['☒','☐','☒','☐','☒','☐','☒','☐'],
6:['☐','☒','☐','☒','☐','☒','☐','☒'],
5:['☒','☐','☒','☐','☒','☐','☒','☐'],
4:['☐','☒','☐','☒','☐','☒','☐','☒'],
3:['☒','☐','☒','☐','☒','☐','☒','☐'],
2:['☐','☒','☐','☒','☐','☒','☐','☒'],
1:['☒','☐','☒','☐','☒','☐','☒','☐'],
' ':['⒜','⒝','⒞','⒟','⒠','⒡','⒢','⒣']
} #regular letters aren't wide enough
Default = {
8:['♜','♞','♝','♛','♚','♝','♞','♜'],
7:['♟','♟','♟','♟','♟','♟','♟','♟'],
2:['♙','♙','♙','♙','♙','♙','♙','♙'],
1:['♖','♘','♗','♕','♔','♗','♘','♖']
}
Board = {}
def NewGame():
Board.update(EmptyBoard)
Board.update(Default)
# some more code
NewGame()
this is fine until I have to edit a block in Board
like so:
Board[3][2] = "X"
print(EmptyBoard[3][2]) # ==> Results in 'X', should stay '☐' or '☒'
this changes both Board[x][y]
and whichever one of EmptyBoard
and Default
that [x][y]
happens to be in.
This clones the pieces for every move after their first.
How do I make it so that only Board
is edited?