I am implementing a checkers game board with python. Here is how I generate the board structure as an [8][8] array:
_matrix = []
for i in xrange(8):
_matrix.append( [' '] * 8 )
for row in xrange(0, 8):
for col in xrange(0, 8):
if _darkQuad(row, col) == True:
_matrix[row][col] = '#'
else:
_matrix[row][col] = '-'
def _darkQuad(row, col):
return ((row%2) == (col%2))
def _printDebugBoard():
for row in xrange(0, 8):
for col in xrange(0, 8):
print _matrix[row][col]
print ''
This should do my board like:
# - # - # - # - - # - # - # - # ...
But the result is:
- - - - - - - -
# # # # # # # #
- - - - - - - -
# # # # # # # #
- - - - - - - -
# # # # # # # #
- - - - - - - -
# # # # # # # #
What's wrong?
UPD: Hm, I didn't think this will be important. I made my code easier but here is the exact code I use:
class gameSquare(object):
def __init__(self):
self.validSquare = False
self.symbol = ''
def printSymbol(self):
print self.symbol,
-------
def _validateSquares(self):
for row in xrange(0, 8):
for col in xrange(0, 8):
if self._darkQuad(row, col) == True:
self._matrix[row][col].validSquare = False
self._matrix[row][col].symbol = '#'
else:
self._matrix[row][col].validSquare = True
self._matrix[row][col].symbol = '-'
--------
for i in xrange(8):
self._matrix.append( [gameSquare()] * 8 )
-------
def _printDebugBoard(self):
print ''
for row in xrange(0, 8):
for col in xrange(0, 8):
self._matrix[row][col].printSymbol()
print ''