Checkers board structure

Posted by Ockonal on Stack Overflow See other posts from Stack Overflow or by Ockonal
Published on 2010-04-13T16:08:20Z Indexed on 2010/04/13 16:13 UTC
Read the original article Hit count: 385

Filed under:
|

Hello guys, I'm implement checkers (game) board with python. Here is how I switch it to the need structure

[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?

© Stack Overflow or respective owner

Related posts about python

Related posts about checkers