Python

Another question for the Pythonians around here.

I’m doing a simple ASCII checkers game (turns out that a text based UI is pretty lousy for checkers, but I just want to get the logic and maybe even take a stab at AI).

So, I have a Board object and its grid list (defaulting to “.” elements) gets populated with Os and Xs based on the ‘position’ values of Piece objects.

I’m currently emptying the board each turn – blanking it back to all “.” and then feeding in the latest Piece positions to add the Os and X’s. Then I draw the board again.

The wrinkle is in my clearBoard(self) function for the Board object.

When I code it this way (Board.grid is a list object):

self.grid=["." for i in range(64)]

it works fine. (This is identical code to the snippet in Board’s init function setting up the grid initially)

But I was originally trying to code it this way:

for i in self.grid:
i="."

(assume correct indentation)

When I wrote the function like that, it did nothing; the Os and Xs remained.

Any idea what gives? Does it have anything to do with the way lists work?