I use a panel with checkers with python. This is how I create the board structure as an array [8] [8]:
_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 advice, like:
-
...
But the result:
- - - - - - - -
# # # # # # # #
- - - - - - - -
# # # # # # # #
- - - - - - - -
# # # # # # # #
- - - - - - - -
# # # # # # # #
What's wrong?
UPD : Hmm, I didn’t think it would be important. I simplified the code, but here is the exact code that 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 ''
source
share