Hey,
I try of saving my board to a text file and then trying to load my board from the text file but actually does not works.

If anyone knows how this can be solve let me know !

Thanks

just write it to a text file so that the text file looks something like this:

sssssssss
sssssssss
rryrssyry
yyyryryyr
yryrryryr

where s is an unoccupied slot and r represents a red and y represents a yellow..

this way you can reconstruct the board giving each slot of the board a specific state or occupier.

It is quite easy to parse the string(s) using basic string manipulation.

Hi eleonora,

It's also easy to use the pickle module. Pickle dumps objects into a data file and reloads them without you having to worry about parsing text. So, if you have a variable named "board" and you want to dump it to a file called "board.dat" you can just do:

import pickle
board = dict()
f = open("board.dat", "w")
pickle.dump(board, f)
f.close()

And if you want to retrieve it, you can do:

import pickle
f = open("board.dat", "r")
board = pickle.load(f)
f.close()

Hope this helps!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.