arrays help

Andy Gimblett gimbo at ftech.net
Thu Mar 21 05:34:45 EST 2002


On Tue, Mar 19, 2002 at 06:23:55PM -0800, Umesh Persad wrote:

> background. I am programming a game and I wanted to
> represent a gameboard by a double subscripted array.
> How do I do this in Python? Thanks,

You could use a dictionary, keyed by a tuple:

# empty chessboard:
board = {}
for x in range(8):
    for y in range(8):
        board[(x, y)] = None

# start placing pieces:
board[(0, 0)] = rook(black)
board[(0, 1)] = knight(black)
...
for y in range(8):
    board[(1, 8)] = pawn(black)

etc.

-- 
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.




More information about the Python-list mailing list